Skip to content

Commit

Permalink
fix(mathjax): remove blank line item and update test case
Browse files Browse the repository at this point in the history
partial fix for issue2 of #8.
  • Loading branch information
0x6b committed Aug 4, 2018
1 parent 787175d commit 638bbf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/lib/turndown-plugin-mathjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rules.removeDisplayFormula = {
};

// remove inline formula
rules.removeInlineFormulat = {
rules.removeInlineFormula = {
filter: node => {
return (
node.nodeName === "SPAN" &&
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/issue-8-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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$个词

0 comments on commit 638bbf4

Please sign in to comment.