All files / src/pipeline/rfcxml create-rfcxml-parser.js

85.71% Statements 18/21
0% Branches 0/4
60% Functions 3/5
85.71% Lines 18/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64          5x 5x 5x 5x   5x                   7x           7x   15x     7x       7x 7x 7x 7x 7x 7x           7x                   7x     5x        
/**
 * Lightweight markdown-it parser for RFCXML export.
 * Intentionally omits HTML-only plugins (TOC, Prism, KaTeX, charts).
 */
 
const MarkdownIt = require('markdown-it');
const containers = require('markdown-it-container');
const applyTemplateTagSyntax = require('../../markdown-it/template-tag-syntax');
const { templateTags } = require('../../utils/regex-patterns');
 
const NOTICE_TYPES = {
    note: 1,
    issue: 1,
    example: 1,
    warning: 1,
    todo: 1,
    informative: 1
};
 
function createRfcxmlParser() {
    const md = new MarkdownIt({
        html: true,
        linkify: true,
        typographer: true
    });
 
    applyTemplateTagSyntax(md, [
        {
            filter: type => templateTags.terminology.test(type)
        },
        {
            filter: type => templateTags.specName.test(type)
        }
    ]);
 
    md.use(require('markdown-it-deflist'));
    md.use(require('markdown-it-sub'));
    md.use(require('markdown-it-sup'));
    md.use(require('markdown-it-ins'));
    md.use(require('markdown-it-mark'));
    md.use(require('markdown-it-multimd-table'), {
        multiline: true,
        rowspan: true,
        headerless: true
    });
 
    md.use(containers, 'notice', {
        validate(params) {
            const matches = params.match(/(\w+)\s?(.*)?/);
            return matches && NOTICE_TYPES[matches[1]];
        },
        render(tokens, idx) {
            return tokens[idx].nesting === 1 ? '' : '';
        }
    });
 
    return md;
}
 
module.exports = {
    createRfcxmlParser,
    NOTICE_TYPES
};