From e5c904d1d5202aac943bda00c102f607d118eb29 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 20 May 2024 20:39:22 +0800 Subject: [PATCH] :art: The browser extension supports CSDN formula https://github.com/siyuan-note/siyuan/issues/5624 --- h2m.go | 15 ++++++++++++--- test/h2m_test.go | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/h2m.go b/h2m.go index 654415021b..4e0f160541 100644 --- a/h2m.go +++ b/h2m.go @@ -782,10 +782,19 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) { // The browser extension supports CSDN formula https://github.com/siyuan-note/siyuan/issues/5624 if strings.Contains(strings.ToLower(strings.TrimSpace(util.DomAttrValue(n, "class"))), "katex") { - if span := util.DomChildByTypeAndClass(n, atom.Span, "mord", "mathdefault"); nil != span { + if span := util.DomChildByTypeAndClass(n, atom.Span, "katex-mathml"); nil != span { if tex := util.DomText(span.FirstChild); "" != tex { - appendInlineMath(tree, tex) - return + tex = strings.TrimSpace(tex) + for strings.Contains(tex, "\n ") { + tex = strings.ReplaceAll(tex, "\n ", "\n") + } + // 根据最后 4 个换行符分隔公式内容 + if idx := strings.LastIndex(tex, "\n\n\n\n"); 0 < idx { + tex = tex[idx+4:] + tex = strings.TrimSpace(tex) + appendInlineMath(tree, tex) + return + } } } } diff --git a/test/h2m_test.go b/test/h2m_test.go index 019960c86e..0c313a5334 100644 --- a/test/h2m_test.go +++ b/test/h2m_test.go @@ -18,8 +18,9 @@ import ( var html2MdTests = []parseTest{ + {"112", "

对于第 \n \n \n \n \n i \n \n \n \n i \n \n \n i 个数( \n \n \n \n \n i \n \n \n ≤ \n \n \n k \n \n \n \n i≤k \n \n \n ik)。在 \n \n \n \n \n k \n \n \n \n k \n \n \n k 步之前,被选中的概率为 1。当走到第 \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n k+1 \n \n \n k+1 步时, \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n k+1 \n \n \n k+1 个元素替换的概率 = 第 \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n k+1 \n \n \n k+1 个元素被选中的概率 * \n \n \n \n \n i \n \n \n \n i \n \n \n i 被选中替换的概率,即为 \n \n \n \n \n \n k \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n × \n \n \n \n 1 \n \n \n k \n \n \n \n = \n \n \n \n 1 \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n \n \\frac{k}{k + 1} \\times \\frac{1}{k} = \\frac{1}{k + 1} \n \n \n k+1k×k1=k+11。则不被第 \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n k+1 \n \n \n k+1个元素替换的概率为 \n \n \n \n \n 1 \n \n \n − \n \n \n \n 1 \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n = \n \n \n \n k \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n \n 1 - \\frac{1}{k + 1} = \\frac{k}{k + 1} \n \n \n 1k+11=k+1k。依次类推,不被 \n \n \n \n \n k \n \n \n + \n \n \n 2 \n \n \n \n k+2 \n \n \n k+2 个元素替换的概率为 \n \n \n \n \n 1 \n \n \n − \n \n \n \n k \n \n \n \n k \n \n \n + \n \n \n 2 \n \n \n \n \n × \n \n \n \n 1 \n \n \n k \n \n \n \n = \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n k \n \n \n + \n \n \n 2 \n \n \n \n \n \n 1 - \\frac{k}{k + 2} \\times \\frac{1}{k} = \\frac{k + 1}{k + 2} \n \n \n 1k+2k×k1=k+2k+1。则运行到第 \n \n \n \n \n n \n \n \n \n n \n \n \n n 步时,第 \n \n \n \n \n i \n \n \n \n i \n \n \n i 个数仍保留的概率 = 被选中的概率 * 不被替换的概率,即:
\n \n \n \n \n 1 \n \n \n × \n \n \n \n k \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n × \n \n \n \n \n k \n \n \n + \n \n \n 1 \n \n \n \n \n k \n \n \n + \n \n \n 2 \n \n \n \n \n × \n \n \n \n \n k \n \n \n + \n \n \n 2 \n \n \n \n \n k \n \n \n + \n \n \n 3 \n \n \n \n \n × \n \n \n … \n \n \n × \n \n \n \n \n n \n \n \n − \n \n \n 1 \n \n \n \n n \n \n \n \n = \n \n \n \n k \n \n \n n \n \n \n \n \n 1 \\times \\frac{k}{k + 1} \\times \\frac{k + 1}{k + 2} \\times \\frac{k + 2}{k + 3} \\times … \\times \\frac{n - 1}{n} = \\frac{k}{n} \n \n \n 1×k+1k×k+2k+1×k+3k+2××nn1=nk

", "对于第 $i$ 个数($i≤k$)。在 $k$ 步之前,被选中的概率为 1。当走到第 $k+1$ 步时,\u200b**被 $k+1$ 个元素替换的概率 = 第 $k+1$ 个元素被选中的概率 \\* $i$ 被选中替换的概率**\u200b,即为 $\\frac{k}{k + 1} \\times \\frac{1}{k} = \\frac{1}{k + 1}$。则不被第 $k+1$ 个元素替换的概率为 $1 - \\frac{1}{k + 1} = \\frac{k}{k + 1}$。依次类推,不被 $k+2$ 个元素替换的概率为 $1 - \\frac{k}{k + 2} \\times \\frac{1}{k} = \\frac{k + 1}{k + 2}$。则运行到第 $n$ 步时,第 $i$ 个数\u200b**仍保留的概率 = 被选中的概率 \\* 不被替换的概率**\u200b,即:\n$1 \\times \\frac{k}{k + 1} \\times \\frac{k + 1}{k + 2} \\times \\frac{k + 2}{k + 3} \\times … \\times \\frac{n - 1}{n} = \\frac{k}{n}$\n"}, {"111", "
\n

\n
\n \n
(2)&#x0393;(x)=&#x222B;&#x03B1;&#x03B2;g(t)(x&#x2212;t)2&#xA0;dt&#x03D5;(x)&#x2211;i=0N&#x2212;1&#x03C9;i\" role=\"presentation\">Γ(x)=βαg(t)(xt)2 dtϕ(x)N1i=0ωi(2)(2)Γ(x)=αβg(t)(xt)2 dtϕ(x)i=0N1ωi
\n

\n
", "> $$\n> \\varGamma(x) = \\frac{\\int_{\\alpha}^{\\beta} g(t)(x-t)^2\\text{ d}t }{\\phi(x)\\sum_{i=0}^{N-1} \\omega_i} \\tag{2}\n> $$\n"}, - {"110", "

假设一个随机变量 \n \n \n \n \n X \n \n \n \n X \n \n \n X,其一个表示定义为 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n ( \n \n \n X \n \n \n ) \n \n \n \n \\hat{X}(X) \n \n \n X^(X),若我们使用 \n \n \n \n \n R \n \n \n \n R \n \n \n R个比特(bit)来表示 \n \n \n \n \n X \n \n \n \n X \n \n \n X,每个比特的数值为 \n \n \n \n \n 0 \n \n \n \n 0 \n \n \n 0 \n \n \n \n \n 1 \n \n \n \n 1 \n \n \n 1,那么函数 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n \n \\hat{X} \n \n \n X^可以有 \n \n \n \n \n \n 2 \n \n \n R \n \n \n \n \n 2^R \n \n \n 2R中不同取值,那么我们现在的问题是找到一个 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n \n \\hat{X} \n \n \n X^的最优值集(称为再生点(reproduction points)或码点(code points)),而目的是通过最小化定义的一个失真度量得到。

", "假设一个随机变量 $X$,其一个表示定义为 $X^$,若我们使用 $R$ 个比特(bit)来表示 $X$,每个比特的数值为 $0$ 或 $1$,那么函数 $X^$ 可以有 $2$ 中不同取值,那么我们现在的问题是找到一个 $X^$ 的最优值集(称为再生点(reproduction points)或码点(code points)),而目的是通过最小化定义的一个失真度量得到。\n"}, + {"110", "

假设一个随机变量 \n \n \n \n \n X \n \n \n \n X \n \n \n X,其一个表示定义为 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n ( \n \n \n X \n \n \n ) \n \n \n \n \\hat{X}(X) \n \n \n X^(X),若我们使用 \n \n \n \n \n R \n \n \n \n R \n \n \n R个比特(bit)来表示 \n \n \n \n \n X \n \n \n \n X \n \n \n X,每个比特的数值为 \n \n \n \n \n 0 \n \n \n \n 0 \n \n \n 0 \n \n \n \n \n 1 \n \n \n \n 1 \n \n \n 1,那么函数 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n \n \\hat{X} \n \n \n X^可以有 \n \n \n \n \n \n 2 \n \n \n R \n \n \n \n \n 2^R \n \n \n 2R中不同取值,那么我们现在的问题是找到一个 \n \n \n \n \n \n X \n \n \n ^ \n \n \n \n \n \\hat{X} \n \n \n X^的最优值集(称为再生点(reproduction points)或码点(code points)),而目的是通过最小化定义的一个失真度量得到。

", "假设一个随机变量 $X$,其一个表示定义为 $\\hat{X}(X)$,若我们使用 $R$ 个比特(bit)来表示 $X$,每个比特的数值为 $0$ 或 $1$,那么函数 $\\hat{X}$ 可以有 $2^R$ 中不同取值,那么我们现在的问题是找到一个 $\\hat{X}$ 的最优值集(称为再生点(reproduction points)或码点(code points)),而目的是通过最小化定义的一个失真度量得到。\n"}, {"109", "

&#x03C9;\" role=\"presentation\">ω\\omega 表示 n\" role=\"presentation\">nn 次单位根 exp&#x2061;(2&#x03C0;i/n)\" role=\"presentation\">exp(2πi/n)\\exp(2\\pi i/n) , n\" role=\"presentation\">nn 取决于上下文.

", "$\\omega$ 表示 $n$ 次单位根 $\\exp(2\\pi i/n)$ , $n$ 取决于上下文.\n"}, {"108", "

定义有效的笔记

", "### 定义有效的笔记\n"}, {"107", "

bar

", "\u200b`bar`\n"},