Skip to content

Commit

Permalink
🎨 Improve HTML clipping siyuan-note/siyuan#12725
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 8, 2024
1 parent ad5b8f2 commit 3db6018
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
if lute.ParseOptions.ProtyleWYSIWYG {
node.Tokens = lex.EscapeProtyleMarkers(node.Tokens)
} else {
node.Tokens = lex.EscapeCommonMarkers(node.Tokens)
if nil != n.Parent && atom.Span == n.Parent.DataAtom && 0 == len(n.Parent.Attr) {
// 按原文解析,不处理转义
} else {
node.Tokens = lex.EscapeCommonMarkers(node.Tokens)
}
if lute.parentIs(n, atom.Table) {
node.Tokens = bytes.ReplaceAll(node.Tokens, []byte("\\|"), []byte("|"))
node.Tokens = bytes.ReplaceAll(node.Tokens, []byte("|"), []byte("\\|"))
Expand Down
2 changes: 1 addition & 1 deletion javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/h2m_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

var html2MdTests = []parseTest{

{"187", "$foo$", "\\$foo\\$\n"},
{"186", "<span>$foo$</span>", "$foo$\n"},
{"185", "<p data-pid=\"Ir_Zz_Dw\"><span class=\"ztext-math\" data-eeimg=\"1\" data-tex=\"\\ \\\\ h_0p_0=s'_0(x) \\\\ (h_0+h_1)(\\frac{p_0}{2}+\\frac{p_1}{2}+\\frac{p_2}{2})=s'_1(x)\\\\ (h_0-h_1)(\\frac{p_0}{2}-\\frac{p_1}{2}+\\frac{p_2}{2} )=s'_2(x) \\\\ h_1p_2\"><span></span><span><span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax_SVG\" id=\"MathJax-Element-58-Frame\" tabindex=\"0\" style=\"font-size: 100%; display: inline-block; position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mtext>&amp;#xA0;</mtext><mspace linebreak=&quot;newline&quot; /><msub><mi>h</mi><mn>0</mn></msub><msub><mi>p</mi><mn>0</mn></msub><mo>=</mo><msubsup><mi>s</mi><mn>0</mn><mo>&amp;#x2032;</mo></msubsup><mo stretchy=&quot;false&quot;>(</mo><mi>x</mi><mo stretchy=&quot;false&quot;>)</mo><mspace linebreak=&quot;newline&quot; /><mo stretchy=&quot;false&quot;>(</mo><msub><mi>h</mi><mn>0</mn></msub><mo>+</mo><msub><mi>h</mi><mn>1</mn></msub><mo stretchy=&quot;false&quot;>)</mo><mo stretchy=&quot;false&quot;>(</mo><mfrac><msub><mi>p</mi><mn>0</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>1</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>2</mn></msub><mn>2</mn></mfrac><mo stretchy=&quot;false&quot;>)</mo><mo>=</mo><msubsup><mi>s</mi><mn>1</mn><mo>&amp;#x2032;</mo></msubsup><mo stretchy=&quot;false&quot;>(</mo><mi>x</mi><mo stretchy=&quot;false&quot;>)</mo><mspace linebreak=&quot;newline&quot; /><mo stretchy=&quot;false&quot;>(</mo><msub><mi>h</mi><mn>0</mn></msub><mo>&amp;#x2212;</mo><msub><mi>h</mi><mn>1</mn></msub><mo stretchy=&quot;false&quot;>)</mo><mo stretchy=&quot;false&quot;>(</mo><mfrac><msub><mi>p</mi><mn>0</mn></msub><mn>2</mn></mfrac><mo>&amp;#x2212;</mo><mfrac><msub><mi>p</mi><mn>1</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>2</mn></msub><mn>2</mn></mfrac><mo stretchy=&quot;false&quot;>)</mo><mo>=</mo><msubsup><mi>s</mi><mn>2</mn><mo>&amp;#x2032;</mo></msubsup><mo stretchy=&quot;false&quot;>(</mo><mi>x</mi><mo stretchy=&quot;false&quot;>)</mo><mspace linebreak=&quot;newline&quot; /><msub><mi>h</mi><mn>1</mn></msub><msub><mi>p</mi><mn>2</mn></msub></math>\" role=\"presentation\"><svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"79.691ex\" height=\"14.836ex\" viewBox=\"0 -51.9 34311.3 6387.5\" role=\"img\" focusable=\"false\" aria-hidden=\"true\" style=\"vertical-align: -14.715ex; max-width: 68800px;\"><g stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" transform=\"matrix(1 0 0 -1 0 0)\"><g transform=\"translate(0,-1200)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-30\" x=\"815\" y=\"-213\"></use><g transform=\"translate(1030,0)\"><use xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-30\" x=\"712\" y=\"-213\"></use></g><use xlink:href=\"#MJMAIN-3D\" x=\"2265\" y=\"0\"></use><g transform=\"translate(3321,0)\"><use xlink:href=\"#MJMATHI-73\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-2032\" x=\"663\" y=\"445\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-30\" x=\"663\" y=\"-435\"></use></g><use xlink:href=\"#MJMAIN-28\" x=\"4245\" y=\"0\"></use><use xlink:href=\"#MJMATHI-78\" x=\"4634\" y=\"0\"></use><use xlink:href=\"#MJMAIN-29\" x=\"5207\" y=\"0\"></use></g><g transform=\"translate(0,-2846)\"><use xlink:href=\"#MJMAIN-28\" x=\"0\" y=\"0\"></use><g transform=\"translate(389,0)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-30\" x=\"815\" y=\"-213\"></use></g><use xlink:href=\"#MJMAIN-2B\" x=\"1642\" y=\"0\"></use><g transform=\"translate(2642,0)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-31\" x=\"815\" y=\"-213\"></use></g><use xlink:href=\"#MJMAIN-29\" x=\"3673\" y=\"0\"></use><use xlink:href=\"#MJMAIN-28\" x=\"4062\" y=\"0\"></use><g transform=\"translate(4452,0)\"><g transform=\"translate(120,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,577)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-30\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-2B\" x=\"5711\" y=\"0\"></use><g transform=\"translate(6489,0)\"><g transform=\"translate(342,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,566)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-31\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-2B\" x=\"7971\" y=\"0\"></use><g transform=\"translate(8749,0)\"><g transform=\"translate(342,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,566)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-32\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-29\" x=\"10009\" y=\"0\"></use><use xlink:href=\"#MJMAIN-3D\" x=\"10676\" y=\"0\"></use><g transform=\"translate(11732,0)\"><use xlink:href=\"#MJMATHI-73\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-2032\" x=\"663\" y=\"445\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-31\" x=\"663\" y=\"-435\"></use></g><use xlink:href=\"#MJMAIN-28\" x=\"12656\" y=\"0\"></use><use xlink:href=\"#MJMATHI-78\" x=\"13045\" y=\"0\"></use><use xlink:href=\"#MJMAIN-29\" x=\"13618\" y=\"0\"></use></g><g transform=\"translate(0,-4545)\"><use xlink:href=\"#MJMAIN-28\" x=\"0\" y=\"0\"></use><g transform=\"translate(389,0)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-30\" x=\"815\" y=\"-213\"></use></g><use xlink:href=\"#MJMAIN-2212\" x=\"1642\" y=\"0\"></use><g transform=\"translate(2642,0)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-31\" x=\"815\" y=\"-213\"></use></g><use xlink:href=\"#MJMAIN-29\" x=\"3673\" y=\"0\"></use><use xlink:href=\"#MJMAIN-28\" x=\"4062\" y=\"0\"></use><g transform=\"translate(4452,0)\"><g transform=\"translate(120,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,577)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-30\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-2212\" x=\"5711\" y=\"0\"></use><g transform=\"translate(6489,0)\"><g transform=\"translate(342,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,566)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-31\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-2B\" x=\"7971\" y=\"0\"></use><g transform=\"translate(8749,0)\"><g transform=\"translate(342,0)\"><rect stroke=\"none\" width=\"796\" height=\"60\" x=\"0\" y=\"220\"></rect><g transform=\"translate(60,566)\"><use transform=\"scale(0.707)\" xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.5)\" xlink:href=\"#MJMAIN-32\" x=\"712\" y=\"-326\"></use></g><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"313\" y=\"-531\"></use></g></g><use xlink:href=\"#MJMAIN-29\" x=\"10009\" y=\"0\"></use><use xlink:href=\"#MJMAIN-3D\" x=\"10676\" y=\"0\"></use><g transform=\"translate(11732,0)\"><use xlink:href=\"#MJMATHI-73\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-2032\" x=\"663\" y=\"445\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"663\" y=\"-435\"></use></g><use xlink:href=\"#MJMAIN-28\" x=\"12656\" y=\"0\"></use><use xlink:href=\"#MJMATHI-78\" x=\"13045\" y=\"0\"></use><use xlink:href=\"#MJMAIN-29\" x=\"13618\" y=\"0\"></use></g><g transform=\"translate(0,-6046)\"><use xlink:href=\"#MJMATHI-68\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-31\" x=\"815\" y=\"-213\"></use><g transform=\"translate(1030,0)\"><use xlink:href=\"#MJMATHI-70\" x=\"0\" y=\"0\"></use><use transform=\"scale(0.707)\" xlink:href=\"#MJMAIN-32\" x=\"712\" y=\"-213\"></use></g></g></g></svg><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mtext>&nbsp;</mtext><mspace linebreak=\"newline\"></mspace><msub><mi>h</mi><mn>0</mn></msub><msub><mi>p</mi><mn>0</mn></msub><mo>=</mo><msubsup><mi>s</mi><mn>0</mn><mo>′</mo></msubsup><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo><mspace linebreak=\"newline\"></mspace><mo stretchy=\"false\">(</mo><msub><mi>h</mi><mn>0</mn></msub><mo>+</mo><msub><mi>h</mi><mn>1</mn></msub><mo stretchy=\"false\">)</mo><mo stretchy=\"false\">(</mo><mfrac><msub><mi>p</mi><mn>0</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>1</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>2</mn></msub><mn>2</mn></mfrac><mo stretchy=\"false\">)</mo><mo>=</mo><msubsup><mi>s</mi><mn>1</mn><mo>′</mo></msubsup><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo><mspace linebreak=\"newline\"></mspace><mo stretchy=\"false\">(</mo><msub><mi>h</mi><mn>0</mn></msub><mo>−</mo><msub><mi>h</mi><mn>1</mn></msub><mo stretchy=\"false\">)</mo><mo stretchy=\"false\">(</mo><mfrac><msub><mi>p</mi><mn>0</mn></msub><mn>2</mn></mfrac><mo>−</mo><mfrac><msub><mi>p</mi><mn>1</mn></msub><mn>2</mn></mfrac><mo>+</mo><mfrac><msub><mi>p</mi><mn>2</mn></msub><mn>2</mn></mfrac><mo stretchy=\"false\">)</mo><mo>=</mo><msubsup><mi>s</mi><mn>2</mn><mo>′</mo></msubsup><mo stretchy=\"false\">(</mo><mi>x</mi><mo stretchy=\"false\">)</mo><mspace linebreak=\"newline\"></mspace><msub><mi>h</mi><mn>1</mn></msub><msub><mi>p</mi><mn>2</mn></msub></math></span></span><script type=\"math/tex;mode=inline\" id=\"MathJax-Element-58\">\\ \\\\ h_0p_0=s'_0(x) \\\\ (h_0+h_1)(\\frac{p_0}{2}+\\frac{p_1}{2}+\\frac{p_2}{2})=s'_1(x)\\\\ (h_0-h_1)(\\frac{p_0}{2}-\\frac{p_1}{2}+\\frac{p_2}{2} )=s'_2(x) \\\\ h_1p_2</script><span class=\"tex2jax_ignore math-holder\">\\ \\\\ h_0p_0=s'_0(x) \\\\ (h_0+h_1)(\\frac{p_0}{2}+\\frac{p_1}{2}+\\frac{p_2}{2})=s'_1(x)\\\\ (h_0-h_1)(\\frac{p_0}{2}-\\frac{p_1}{2}+\\frac{p_2}{2} )=s'_2(x) \\\\ h_1p_2</span></span></span> </p>", "$$\n\\ \\\\ h_0p_0=s'_0(x) \\\\ (h_0+h_1)(\\frac{p_0}{2}+\\frac{p_1}{2}+\\frac{p_2}{2})=s'_1(x)\\\\ (h_0-h_1)(\\frac{p_0}{2}-\\frac{p_1}{2}+\\frac{p_2}{2} )=s'_2(x) \\\\ h_1p_2\n$$\n"},
{"184", "<div class=\"highlight-container\" data-rel=\"C\"><div class=\"highlight-container\"><figure class=\"iseeu highlight c\"><table><tbody><tr><td class=\"gutter\"><pre><span class=\"line\">1</span><br><span class=\"line\">2</span><br><span class=\"line\">3</span><br><span class=\"line\">4</span><br><span class=\"line\">5</span><br><span class=\"line\">6</span><br><span class=\"line\">7</span><br><span class=\"line\">8</span><br></pre></td><td class=\"code\"><pre><span class=\"line\"><span class=\"comment\">// 如果alpha的值域是[0,1],这里相当于将其拉伸为[0,255]</span></span><br><span class=\"line\"><span class=\"comment\">// 所以相当于是 Alpha = 1 - (1 - Alpha1) * ( 1 - Alpha2)乘以了两次255</span></span><br><span class=\"line\"><span class=\"comment\">// 当a1和a2都接近于0的时候,会导致计算得到的A值不为0,导致叠加不正常</span></span><br><span class=\"line\"><span class=\"type\">uint32_t</span> A = (<span class=\"number\">0xffff</span> - (<span class=\"number\">0xff</span> - a1) * (<span class=\"number\">0xff</span> - a2));</span><br><span class=\"line\"><span class=\"comment\">// 下面左边部分少左移8位,相当于乘以了255</span></span><br><span class=\"line\"><span class=\"type\">uint32_t</span> R = (((rgba1 &lt;&lt; <span class=\"number\">8</span> &amp; <span class=\"number\">0xff00</span>U) * a1 + (rgba2 &gt;&gt; <span class=\"number\">0</span> &amp; <span class=\"number\">0xff</span>U) * a2 *(<span class=\"number\">0xff</span> - a1)) / A) &amp; <span class=\"number\">0xff</span>U;</span><br><span class=\"line\"><span class=\"type\">uint32_t</span> G = (((rgba1 &gt;&gt; <span class=\"number\">0</span> &amp; <span class=\"number\">0xff00</span>U) * a1 + (rgba2 &gt;&gt; <span class=\"number\">8</span> &amp; <span class=\"number\">0xff</span>U) * a2 *(<span class=\"number\">0xff</span> - a1)) / A) &amp; <span class=\"number\">0xff</span>U;</span><br><span class=\"line\"><span class=\"type\">uint32_t</span> B = (((rgba1 &gt;&gt; <span class=\"number\">8</span> &amp; <span class=\"number\">0xff00</span>U) * a1 + (rgba2 &gt;&gt; <span class=\"number\">16</span> &amp; <span class=\"number\">0xff</span>U) * a2 *(<span class=\"number\">0xff</span> - a1)) / A) &amp; <span class=\"number\">0xff</span>U;</span><br></pre></td></tr></tbody></table></figure><div class=\"copy-button\"><i class=\"fa-regular fa-copy\"></i></div><div class=\"fold-button\"><i class=\"fa-solid fa-chevron-down\"></i></div></div></div>", "```c\n// 如果alpha的值域是[0,1],这里相当于将其拉伸为[0,255]\n// 所以相当于是 Alpha = 1 - (1 - Alpha1) * ( 1 - Alpha2)乘以了两次255\n// 当a1和a2都接近于0的时候,会导致计算得到的A值不为0,导致叠加不正常\nuint32_t A = (0xffff - (0xff - a1) * (0xff - a2));\n// 下面左边部分少左移8位,相当于乘以了255\nuint32_t R = (((rgba1 << 8 & 0xff00U) * a1 + (rgba2 >> 0 & 0xffU) * a2 *(0xff - a1)) / A) & 0xffU;\nuint32_t G = (((rgba1 >> 0 & 0xff00U) * a1 + (rgba2 >> 8 & 0xffU) * a2 *(0xff - a1)) / A) & 0xffU;\nuint32_t B = (((rgba1 >> 8 & 0xff00U) * a1 + (rgba2 >> 16 & 0xffU) * a2 *(0xff - a1)) / A) & 0xffU;\n```\n"},
{"183", "<pre data-index=\"0\" class=\"set-code-show\" name=\"code\"><code class=\"language-css hljs\"><ol class=\"hljs-ln\" style=\"width:100%\"><li><div class=\"hljs-ln-numbers\"><div class=\"hljs-ln-line hljs-ln-n\" data-line-number=\"1\"></div></div><div class=\"hljs-ln-code\"><div class=\"hljs-ln-line\"><span class=\"hljs-selector-tag\">html</span> {</div></div></li><li><div class=\"hljs-ln-numbers\"><div class=\"hljs-ln-line hljs-ln-n\" data-line-number=\"2\"></div></div><div class=\"hljs-ln-code\"><div class=\"hljs-ln-line\"> <span class=\"hljs-attribute\">overflow-y</span>: overlay;</div></div></li><li><div class=\"hljs-ln-numbers\"><div class=\"hljs-ln-line hljs-ln-n\" data-line-number=\"3\"></div></div><div class=\"hljs-ln-code\"><div class=\"hljs-ln-line\">}</div></div></li></ol></code><div class=\"hljs-button signin active\" data-title=\"登录复制\" data-report-click=\"{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}\" onclick=\"hljs.signin(event)\"></div></pre>", "```css\nhtml {\n overflow-y: overlay;\n}\n```\n"},
Expand Down

0 comments on commit 3db6018

Please sign in to comment.