UNPKG

mathpix-markdown-it

Version:

Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)

99 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tableMarkdownJoin = exports.getMdForChild = exports.getMdLink = void 0; var getMdLink = function (child, token, j) { if (child.type !== 'link_open') { return ''; } var link = ''; link += '['; var linkRef = "(".concat(child.attrGet('href'), ")"); var nextChild = j + 1 < token.children.length ? token.children[j + 1] : null; if (!nextChild) { return ''; } link += nextChild.content; link += ']'; link += linkRef; return link; }; exports.getMdLink = getMdLink; var getMdForChild = function (child) { var res = ''; if (!child.tag) { switch (child.type) { case 'textbf_open': case 'textbf_close': res = '**'; break; case 'textit_open': case 'textit_close': res = '*'; break; case 'texttt_open': case 'texttt_close': res = '`'; break; case 'smiles_inline': res = '<smiles>'; break; case 'link_open': res = '<a>'; break; case 'link_close': res = '</a>'; break; } return res; } switch (child.tag) { case 'em': case 's': case 'strong': case 'mark': case 'code': res = child.markup; break; } return res; }; exports.getMdForChild = getMdForChild; var tableMarkdownJoin = function (tableMd, align) { if (align === void 0) { align = ''; } if (!tableMd || tableMd.length === 0) { return ''; } var table = []; var alignArr = align.split('|'); for (var i = 0; i < tableMd.length; i++) { var row = tableMd[i]; var rowStr = '| ' + row.join(' | ') + ' |'; table.push(rowStr); if (i === 0) { var header = '|'; for (var j = 0; j < alignArr.length; j++) { var itemAlign = alignArr[j]; switch (itemAlign) { case 'left': header += ' :--- |'; break; case 'right': header += ' ---: |'; break; case 'center': header += ' :---: |'; break; default: header += ' --- |'; break; } } table.push(header); } } return table.join("\n"); }; exports.tableMarkdownJoin = tableMarkdownJoin; //# sourceMappingURL=table-markdown.js.map