Skip to content

emagining/sveltekit-pote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

253463b · Sep 16, 2021

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portable Text for Svelte & SvelteKit

Provides a way to render Portable Text in Svelte / SvelteKit applications.

Based on @arzidava/svelte-portable-text but removes the wrapping <div> around blocks (paragraphs) => "p" blocks will be wrapped in <p> {paragraph} </p> instead of <div><p><span> {paragraph} </span></p></div>

NOTE: it doens't support <span> as a custom mark because that is used by portable text to mark a child node in the block.

Install

npm add --save-dev @emagining/sveltekit-pote

Usage

<script>
  import BlockContent from '@emagining/sveltekit-pote'

  import Image from '$lib/Image.svelte'
  import Link from '$lib/Link.svelte'

  export let content;
  export const customSerializers = {
    types: {
      image: props => {
        return {
          component: Image,
          props: {
            url: props.node.url,
          },
        };
      },
    },
    marks: {
      link: props => {
        return {
          component: Link,
          props: props.mark,
        };
      },
    },
  };
</script>

<BlockContent blocks="{content}" serializers="{customSerializers}" />

Work in Progress

This package was created to serve my own needs. Have a look at these libs to see if they better serve your need:

Contribute

Open an issue or make a pull req. :)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published