Convert StructuredText to html.
npm install cnc-structured-textConvert StructuredText to html.
npm install cnc-structured-text --save
``javascript
const tohtml = require('cnc-structured-text');
const structuredtext = [{
type: 'paragraph',
text: 'Hi everyone, I am an awesome text!',
spans: [
{ start: 0, end: 11, type: 'strong' },
{ start: 3, end: 11, type: 'em' },
{ start: 13, end: 17, type: 'strong' },
{ start: 17, end: 28, type: 'em' }
]
}];
tohtml(structuredtext, / [options] /);
// ->
Hi everyone, I am an awesome text!
`
javascripttohtml(structuredtext, {
// [optional] how to resolve internal links
linkResolver: function(doc, isBroken) {
// default resolver:
if (isBroken) return '#broken';
// if target document has a url field -> use it
if (doc.document && doc.document.url) return doc.document.url;
// otherwise fallback to id
return '/' + doc.id;
}
// [optional] how to render fragments (Links, Images....)
serializer: function() {
// default serializer:
// add target='_blank' on external links
if (element.type === 'hyperlink' && element.url && element.url.substring(0, 4) === 'http') {
return '' + content + '';
}
return null;
}
})
;
``