A live-sanitizing parsing and rendering module for a subset of Markdown representing simple prose
This parses and renders constrained prose passages of Markdown to a constrained DOM tree. It renders a subset of Markdown that is strict, except that it can detect and run blocks through an external renderer, if any are passed. It is called simple-prose because it only handles simple prose elements like paragraphs, headings, bold, italics, and underlines. When it runs into something unsupported it errors.
This module intentionally has its scope constrained. Plans exist to provide a companion module for more complex prose (links, superscript, subscript, inline code, inline widgets). Where both apply, they may be composed over the same content — e.g., allowing links only in specific sections.
This has default limits and restrictions, such as how many blocks and how many characters per block, which can be extended, as well as a default supported character set, which make it ideal for sandboxing prose coming from an untrusted source. This also makes review, whether automated or manual, faster, because only the content needs to be reviewed – the structure is already constrained.
Having the structure limited also makes it easy to know what styles are needed to control the appearance of prose, and what needs to be supported in an editor for the prose.
import { Model, View } from '@macchiato-dev/simple-prose'
const textArea = document.querySelector('#input')
const main = document.querySelector('main')
const model = new Model(textArea.value)
const view = new View({el: main, model})
textArea.addEventListener('input', e => {
model.update(textArea.value)
})MIT. See LICENSE.