@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
40 lines • 1.29 kB
JavaScript
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