diff --git a/src/lib/turndown-plugin-mathjax.js b/src/lib/turndown-plugin-mathjax.js index 988bfe2..4b450f4 100644 --- a/src/lib/turndown-plugin-mathjax.js +++ b/src/lib/turndown-plugin-mathjax.js @@ -9,7 +9,7 @@ rules.removeDisplayFormula = { }; // remove inline formula -rules.removeInlineFormulat = { +rules.removeInlineFormula = { filter: node => { return ( node.nodeName === "SPAN" && @@ -20,6 +20,37 @@ rules.removeInlineFormulat = { replacement: () => "" }; +rules.removeBlankListItem = { + filter: ["li"], + replacement: function(content, node, options) { + node.childNodes.forEach(child => { + if (child.className && child.className.startsWith("MathJax")) { + node.removeChild(child); + } + }); + //console.log(content); + content = content + .replace(/^\n+/, "") // remove leading newlines + .replace(/\n+$/, "\n") // replace trailing newlines with just a single one + .replace(/\n/gm, "\n "); // indent + let prefix = options.bulletListMarker + " "; + const parent = node.parentNode; + if (parent.nodeName === "OL") { + const start = parent.getAttribute("start"); + const index = Array.prototype.indexOf.call(parent.children, node); + prefix = (start ? Number(start) + index : index + 1) + ". "; + } + if (content !== "") { + return ( + prefix + + content + + (node.nextSibling && !/\n$/.test(content) ? "\n" : "") + ); + } + return ""; + } +}; + // remove new lines surrounding blank paragraph before script node rules.paragraphBeforeScriptNode = { filter: "p", diff --git a/test/fixtures/issue-8-2.md b/test/fixtures/issue-8-2.md index 8511289..5c04b23 100644 --- a/test/fixtures/issue-8-2.md +++ b/test/fixtures/issue-8-2.md @@ -9,4 +9,4 @@ LDA出来说话了:**主题和词汇的分布就是多项式分布**!因为 - $\vec{\theta_m}$代表第$m$篇文章的多项式分布参数,长度为$K$,因此$\Theta$是一个- $M*K$的矩阵,没一行代表一篇文章的多项式分布参数 - $N_m$代表第- $m$篇文章的长度 - $z_{m,n}$代表第$m$篇文章第- $n$个词由哪个主题产生的 -- $w_{m,n}$代表第$m$篇文章第$n$个词 copy.js:95:7 +- $w_{m,n}$代表第$m$篇文章第$n$个词