A Markdown serializer for the Slate editor framework
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2018-05-26 00:36:32 +01:00
lib only escape MD outside code blocks 2018-05-26 00:36:32 +01:00
src only escape MD outside code blocks 2018-05-26 00:36:32 +01:00
.babelrc Fix parsing errors with marks within blocks 2017-05-03 22:29:14 -07:00
.eslintrc Fix parsing errors with marks within blocks 2017-05-03 22:29:14 -07:00
.gitignore try checking in lib for pinned dep 2018-05-23 03:19:05 +01:00
.npmignore Test for bug reported by Ada Support 2018-03-24 14:09:46 -07:00
circle.yml Update test env 2017-11-21 21:36:27 -08:00
LICENSE.txt Project skeleton 2016-07-29 18:35:38 -03:00
package.json oops, remove inline-code thinko 2018-05-23 20:01:03 +01:00
README.md Update version in README 2018-02-13 21:01:02 -08:00
yarn.lock Tweak dependencies 2018-02-13 20:55:04 -08:00

CircleCI

Slate Markdown Serializer

A Markdown serializer for the Slate Editor. Requires Slate 0.32+.

renderMark

This serializer supports the following Slate marks:

function renderMark(props) {
  switch (props.mark.type) {
    case 'bold':
      return <strong>{props.children}</strong>;
    case 'code':
      return <Code>{props.children}</Code>;
    case 'italic':
      return <em>{props.children}</em>;
    case 'underlined':
      return <u>{props.children}</u>;
    case 'deleted':
      return <del>{props.children}</del>;
    case 'added':
      return <mark>{props.children}</mark>;
    default:
  }
}

renderNode

This serializer supports the following Slate node keys:

function renderNode(props) {
  const { attributes } = props;

  switch (props.node.type) {
    case 'paragraph':
      return <Paragraph {...props} />;
    case 'block-quote':
      return <blockquote {...attributes}>{props.children}</blockquote>;
    case 'bulleted-list':
      return <ul {...attributes}>{props.children}</ul>;
    case 'ordered-list':
      return <ol {...attributes}>{props.children}</ol>;
    case 'todo-list':
      return <ul {...attributes}>{props.children}</ul>;
    case 'table':
      return <table {...attributes}>{props.children}</table>;
    case 'table-row':
      return <tr {...attributes}>{props.children}</tr>;
    case 'table-head':
      return <th {...attributes}>{props.children}</th>;
    case 'table-cell':
      return <td {...attributes}>{props.children}</td>;
    case 'list-item':
      return <li {...attributes}>{props.children}</li>;
    case 'horizontal-rule':
      return <hr />;
    case 'code':
      return <code {...attributes}>{props.children}</code>;
    case 'image':
      return <img src={props.src} title={props.title} />;
    case 'link':
      return <a href={props.href}>{props.children}</a>;
    case 'heading1':
      return <h1 {...attributes}>{props.children}</h1>;
    case 'heading2':
      return <h2 {...attributes}>{props.children}</h2>;
    case 'heading3':
      return <h3 {...attributes}>{props.children}</h3>;
    case 'heading4':
      return <h4 {...attributes}>{props.children}</h4>;
    case 'heading5':
      return <h5 {...attributes}>{props.children}</h5>;
    case 'heading6':
      return <h6 {...attributes}>{props.children}</h6>;
    default:
  }
};