2.1.6 • Published 5 months ago

@slate-serializers/template v2.1.6

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

@slate-serializers/template

Render Slate JSON as a combination of HTML and custom serializers that you pass to the configuration.

Returns an array. By default, each array element is the output of @slate-serializers/html. If you pass a custom serializers, your serialized output will be included in this array. These serializers match on top-level Slate nodes only using the type attribute.

Usage

slateToTemplate

import { slateToTemplate } from '@slate-serializers/template'

const slate = [
  {
    children: [
      {
        text: 'Heading 1',
      },
    ],
    type: 'h1',
  },
  {
    children: [
      {
        text: 'Paragraph 1',
      },
    ],
    type: 'p',
  },
]

const serializedToArray = slateToTemplate(slate)
// output
// ["<h1>Heading 1</h1>", "<p>Paragraph 1</p>"]

Configuration

Define a custom serializer to include any output for top-level Slate nodes of a given type.

const slate = [
  {
    children: [
      {
        text: 'Paragraph',
      },
    ],
    type: 'p',
  },
  {
    children: [
      {
        buttonType: 'primary',
        text: 'Button',
      },
    ],
    type: 'button',
  },
];

const config: SlateToTemplateConfig = {
  ...defaultTemplateConfig,
  customElementSerializers: {
    button: ({ node }) => {
      return () =>
        `<button class="${node.buttonType}">Button HTML string generated by function</button>`;
    },
  },
};

const serializedToArray = slateToTemplate(slate)
// output
// ["<p>Paragraph</p>", [Function]]
2.1.4

5 months ago

2.1.6

5 months ago

2.1.5

5 months ago

2.1.3

5 months ago

2.1.2

5 months ago

2.1.1

5 months ago

2.1.0

7 months ago

2.0.1

8 months ago

2.0.0

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.6.7

10 months ago

0.6.6

10 months ago

0.6.5

10 months ago

0.6.4

10 months ago

0.6.3

10 months ago