Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
/ mdast Public archive

Mdast utils developed at Project R. Tools for rendering, serializing and specifying markdown documents.

Notifications You must be signed in to change notification settings

orbiting/mdast

Repository files navigation

[DEPRECATED] Mdast Utils

⚠️ This repository together with others has been merged into the republik/plattform monorepo. Let's continue the journey there. ⚠️

This repository contains utilities we've used to combine mdast and Slate in our CMS—Publikator.

Packages in this repo, all available on NPM:

Serializer

The first challange was to convert a Slate tree to an mdast tree.

slate-mdast-serializer takes care of that with customizable rules.

The API is inspired by slate-html-serializerdeserialize and serialize are available to convert between Slate Value and a mdast tree. Additionally fromMdast and toMdast is available to convert any Slate json to mdast nodes.

import MarkdownSerializer from 'slate-mdast-serializer'

new MarkdownSerializer({
  rules: [
    paragraph,
    bold
  ]
})

Remark Preset

Preconfigured remark with plugins for zone, sub, sup and span types and yaml meta data.

Use this on your server if you want to persist mdast tree as strings—markdown files. In your editor to import and export markdown. Or as a helper in your tests to skip writing mdast trees by hand.

import { parse, stringify } from '@orbiting/remark-preset'

const md = 'Hello **World**\n'
const mdast = parse(md)

md === stringify(mdast)

Renderer

Your front ends shouldn't load Slate or remark (the mdast processor) for just displaying content. Send you front end an mdast tree (as json) and let it be rendered with react and this under hundred-lines-of-code-long util.

mdast-react-render renders your mdast tree according to a schema.

import { renderMdast } from 'mdast-react-render'

const schema = {
  rules: [{
    matchMdast: matchType('root'),
    component: Container,
    rules: [paragraph, bold]
  }]
}

renderMdast(mdast, schema)

Example Template

This isn't meant for direct usage but for understanding how you might use above utils, Publikator and a starting point for your own templates.

In packages/template-newsletter you'll find the newsletter template schema of Project R that can render to web and email. It also contains editor information and can be initiated with our CMS to author newsletters according to the schema.

About

Mdast utils developed at Project R. Tools for rendering, serializing and specifying markdown documents.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •