lexical_markdown 1.4.0 copy "lexical_markdown: ^1.4.0" to clipboard
lexical_markdown: ^1.4.0 copied to clipboard

Markdown import and export for lexical_core, built from composable transformers: headings, quotes, lists, code fences, links and inline formatting. Pure Dart.

lexical_markdown

lexical_markdown #

Markdown import and export for lexical_core. Pure Dart.

dependencies:
  lexical_markdown: ^1.0.0
editor.update(() {
  $convertFromMarkdown(source, transformers: defaultMarkdownTransformers);
}, discrete: true);

final back = editor.read(
  () => $convertToMarkdown(transformers: defaultMarkdownTransformers),
);

One declaration, both directions #

Conversion is built from transformers: each describes one construct going in and coming out.

final ElementTransformer headingTransformer = ElementTransformer(
  regExp: RegExp(r'^(#{1,6})\s+(.*)$'),
  replace: (block, children, match) => block.replace(
    $createHeadingNode(HeadingTag.values[match.group(1)!.length - 1])
      ..appendAll(children),
  ),
  export: (node, exportChildren) => node is! HeadingNode
      ? null
      : '${'#' * node.tag.level} ${exportChildren(node)}',
);

Splitting import and export into separate tables makes it easy to write a heading that reads ## but writes something else, and hard to notice. Keeping them in one place makes that particular bug unwriteable.

What survives, and what does not #

Markdown is lossier than the document model, and this package is honest about it rather than pretending otherwise.

Round-trips: headings, quotes, paragraphs, bullet, ordered and check lists including nesting, fenced code with its language, links with titles, and bold / italic / strikethrough / inline code.

Does not: block alignment, indentation, text colour and other CSS, marks, hashtags, mentions, tables. None of these have a markdown spelling.

Use the JSON wire format to move documents between editors. Use markdown to move them between people.

Licence #

MIT. Portions derived from Lexical, © Meta Platforms, Inc. See the repository.

0
likes
0
points
541
downloads

Publisher

verified publisherahmadre.com

Weekly Downloads

Markdown import and export for lexical_core, built from composable transformers: headings, quotes, lists, code fences, links and inline formatting. Pure Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

lexical_code, lexical_core, lexical_link, lexical_list, lexical_rich_text, meta

More

Packages that depend on lexical_markdown