UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

40 lines 1.29 kB
import * as marked from 'marked'; import { MarkUp, MarkupType, TokenType } from './markup'; /** * marked's intex.ts does not include these types (though they work): del, strong, em */ export class Markdown extends MarkUp { constructor(flavour) { super(flavour); switch (flavour) { case MarkupType.MARKDOWN: this.options = {}; break; case MarkupType.GITHUB: case MarkupType.CONTENTFUL: this.options = { gfm: true }; break; default: throw Error(`Invalid markdown flavour: ${flavour}`); } } parse(txt) { // cannot cache Lexer because it would accumulate the tokens return marked.lexer(txt); } renderToken(_token) { throw new Error('Not implemented'); } wrapWithInline(input, inlineType) { // emphasis & strong cannot have internal spaces input = input.trim(); if (inlineType === TokenType.EMPHASIS) { return `_${input}_`; } if (inlineType === TokenType.STRONG) { return `**${input}**`; } throw new Error(`wrapWithInline does not support inline ${inlineType}`); } } //# sourceMappingURL=markdown.js.map