You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@slate-serializers/template

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slate-serializers/template

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

2.2.3
latest
npmnpm
Version published
Weekly downloads
62
121.43%
Maintainers
0
Weekly downloads
 
Created
Source

@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]]

FAQs

Package last updated on 19 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts