Skip to content

Commit

Permalink
🎨 Improve HTML clipping siyuan-note/siyuan#13185
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 25, 2024
1 parent 0e199ab commit fc6e727
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
defer tree.Context.ParentTip()
return
case atom.Br:
if ast.NodeLink == tree.Context.Tip.Type {
if ast.NodeLink == tree.Context.Tip.Type || ast.NodeHeading == tree.Context.Tip.Type {
break
}

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.

1 change: 1 addition & 0 deletions test/h2m_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var html2MdTests = []parseTest{

{"206", "<p class=\"el-h4\"><h4 data-heading=\"foo\" dir=\"auto\" class=\"publish-article-heading\"><span class=\"heading-collapse-indicator collapse-indicator collapse-icon\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"svg-icon right-triangle\"><path d=\"M3 8L12 17L21 8\"></path></svg></span><br data-added-by-siyuan=\"true\">foo <span class=\"clickable-icon\" aria-label=\"Copy link\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"svg-icon lucide-link\"><path d=\"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\"></path><path d=\"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\"></path></svg></span><br data-added-by-siyuan=\"true\"></h4></p>", "#### foo\n"},
{"205", "<div style=\"margin-top: 20px; text-indent: 0px; color: black;\">如果换到<img class=\"ma-tex-img\" alt=\"\\rho-\\theta\" src=\"\" style=\"max-width: 100%; margin: 0px 2px; vertical-align: middle; display: inline-block;\">坐标系下:</div>", "如果换到 $\\rho-\\theta$ 坐标系下:\n"},
{"204", "<p>在物理学中,牛顿的第二定律可以用如下公式表示:</p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>F</mi><mo>=</mo><mi>m</mi><mi>a</mi></mrow><annotation encoding=\"application/x-tex\">F = ma</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em;\"></span><span class=\"mord mathnormal\" style=\"margin-right: 0.13889em;\">F</span><span class=\"mspace\" style=\"margin-right: 0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right: 0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height: 0.4306em;\"></span><span class=\"mord mathnormal\">ma</span></span></span></span></span><p>其中 <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>F</mi></mrow><annotation encoding=\"application/x-tex\">F</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.6833em;\"></span><span class=\"mord mathnormal\" style=\"margin-right: 0.13889em;\">F</span></span></span></span> 表示力,<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>m</mi></mrow><annotation encoding=\"application/x-tex\">m</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.4306em;\"></span><span class=\"mord mathnormal\">m</span></span></span></span> 是物体的质量,<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>a</mi></mrow><annotation encoding=\"application/x-tex\">a</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.4306em;\"></span><span class=\"mord mathnormal\">a</span></span></span></span> 是物体的加速度。这个公式描述了物体所受外力与其加速度之间的关系。</p>", "在物理学中,牛顿的第二定律可以用如下公式表示:\n\n$$\nF = ma\n$$\n\n其中 $F$ 表示力,$m$ 是物体的质量,$a$ 是物体的加速度。这个公式描述了物体所受外力与其加速度之间的关系。\n"},
{"203", "<div class=\"highlight\"><div class=\"chroma open\"><div class=\"code-header language-fallback\"><span class=\"code-title\"><i class=\"arrow fas fa-chevron-right fa-fw\" aria-hidden=\"true\"></i></span><span class=\"ellipses\"><i class=\"fas fa-ellipsis-h fa-fw\" aria-hidden=\"true\"></i></span><span class=\"copy\" data-clipboard-text=\"2020-08-29 支出 100 CNY ; 购买日用品\n\" title=\"Copy to clipboard\"><i class=\"far fa-copy fa-fw\" aria-hidden=\"true\"></i></span></div><div class=\"table-wrapper\"><table class=\"lntable\"><tbody><tr><td class=\"lntd\"><pre tabindex=\"0\" class=\"chroma\"><code><span class=\"lnt\">1\n</span></code></pre></td><td class=\"lntd\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\">2020-08-29 支出 100 CNY ; 购买日用品\n</span></span></code></pre></td></tr></tbody></table></div></div></div>", "```\n2020-08-29 支出 100 CNY ; 购买日用品\n```\n"},
Expand Down

0 comments on commit fc6e727

Please sign in to comment.