npf2html
Version:
Converts Tumblr's Neue Post Format to plain HTML
59 lines • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderTextNoIndent = renderTextNoIndent;
exports.renderTextIndented = renderTextIndented;
/**
* Converts {@link block} to HTML.
*
* @category Content
*/
function renderTextNoIndent(renderer, block) {
const text = renderer.formatText(block.text, block.formatting);
switch (block.subtype) {
case 'heading1':
return `<h1>${text}</h1>`;
case 'heading2':
return `<h2>${text}</h2>`;
case 'quirky':
return `<p class="${renderer.prefix}-block-text-quirky">${text}</p>`;
case 'quote':
return `<p class="${renderer.prefix}-block-text-quote">${text}</p>`;
case 'chat':
return `<p class="${renderer.prefix}-block-text-chat">${text}</p>`;
default:
return `<p>${text}</p>`;
}
}
/**
* Converts {@link blocksAndNested} to HTML.
*
* The first element of {@link blocksAndNested} determines the subtype of the
* entire thing; any other blocks are guaranteed to have the same subtype. The
* string elements of {@link blocksAndNested} ar {@link TextBlockIndented}
* objects which are more deeply nested and have already been converted to HTML.
*
* @category Content
*/
function renderTextIndented(renderer, blocksAndNested) {
const { subtype } = blocksAndNested[0];
let contents = {
indented: '<blockquote>',
'ordered-list-item': '<ol>',
'unordered-list-item': '<ul>',
}[subtype];
for (const element of blocksAndNested) {
const string = typeof element === 'string';
contents += subtype === 'indented' ? (string ? '' : '<p>') : '<li>';
contents += string
? element
: renderer.formatText(element.text, element.formatting);
contents += subtype === 'indented' ? (string ? '' : '</p>') : '</li>';
}
contents += {
indented: '</blockquote>',
'ordered-list-item': '</ol>',
'unordered-list-item': '</ul>',
}[subtype];
return contents;
}
//# sourceMappingURL=text-block.js.map