Skip to content

Commit

Permalink
🎨 Improve HTML clipping siyuan-note/siyuan#10987
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Aug 12, 2024
1 parent 198dd12 commit c927554
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
node := &ast.Node{Type: ast.NodeText, Tokens: util.StrToBytes(n.Data)}
switch n.DataAtom {
case 0:
class := util.DomAttrValue(n.PrevSibling, "class")
if "fn__space5" == class {
// 链滴剪藏图片时多了长宽显示 https://github.com/siyuan-note/siyuan/issues/10987
return
}

if nil != n.Parent && atom.A == n.Parent.DataAtom {
node.Type = ast.NodeLinkText
}
Expand Down Expand Up @@ -914,6 +920,11 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
case atom.Colgroup, atom.Col:
return
case atom.Span:
class := util.DomAttrValue(n, "class")
if "fn__space5" == class {
return
}

// Improve inline elements pasting https://github.com/siyuan-note/siyuan/issues/11740
dataType := util.DomAttrValue(n, "data-type")
dataType = strings.Split(dataType, " ")[0] // 简化为只处理第一个类型
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{

{"181", "<p><span class=\"vditor-reset__preview\"><img src=\"https://b3logfile.com/file/2024/08/image-tU91NvB.png?imageView2/2/interlace/1/format/webp\" alt=\"image.png\" style=\"background-image: none; background-color: transparent;\"><div class=\"fn__flex-inline\">\n<svg><use xlink:href=\"#iconPhotoActual\"></use></svg>\n<span class=\"fn__space5\"></span>496 x 344</div></span></p>", "![image.png](https://b3logfile.com/file/2024/08/image-tU91NvB.png?imageView2/2/interlace/1/format/webp)\n"},
{"180", "<ul class=\"fa-ul\">\n <li data-marker=\"*\"><span class=\"fa-li\"><i class=\"fas fa-square\"></i></span>\n <p>foo</p>\n\n <div class=\"language-c highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"cp\">#include</span> <span class=\"cpf\">&lt;stdio.h&gt;</span><span class=\"cp\">\n</span>\n<span class=\"kt\">int</span> <span class=\"nf\">main</span><span class=\"p\">(</span><span class=\"kt\">void</span><span class=\"p\">)</span>\n<span class=\"p\">{</span>\n <span class=\"n\">string</span> <span class=\"n\">answer</span> <span class=\"o\">=</span> <span class=\"n\">get_string</span><span class=\"p\">(</span><span class=\"s\">\"What's your name? \"</span><span class=\"p\">);</span>\n <span class=\"n\">printf</span><span class=\"p\">(</span><span class=\"s\">\"hello, %s</span><span class=\"se\">\\n</span><span class=\"s\">\"</span><span class=\"p\">,</span> <span class=\"n\">answer</span><span class=\"p\">);</span>\n<span class=\"p\">}</span>\n</code></pre></div> </div>\n <p>bar</p>\n </li>\n</ul>", "* foo\n\n ```c\n #include <stdio.h>\n\n int main(void)\n {\n string answer = get_string(\"What's your name? \");\n printf(\"hello, %s\\n\", answer);\n }\n ```\n\n bar\n"},
{"179", "<ul>\n<li>foo\n<pre><div class=\"vditor-copy\"><textarea></textarea><span aria-label=\"复制\" onmouseover=\"this.setAttribute('aria-label', '复制')\" class=\"vditor-tooltipped vditor-tooltipped__w\" onclick=\"this.previousElementSibling.select();document.execCommand('copy');this.setAttribute('aria-label', '已复制')\"><svg><use xlink:href=\"#vditor-icon-copy\"></use></svg></span></div><code class=\"highlight-chroma hljs nginx\" style=\"max-height: 992px;\"><span class=\"highlight-line\"><span class=\"highlight-cl\"><span class=\"hljs-attribute\">bar</span>\n</span></span></code><span style=\"position: absolute\">&ZeroWidthSpace;</span></pre>\n</li>\n</ul>", "* foo\n ```\n bar\n ```\n"},
{"178", "<details open=\"\">\n\t\t\t\t<summary>Example Feature Code Implementation</summary>\n\t\t\t\t<pre><code class=\"language-fea\">feature aalt {\n feature salt;\n feature smcp;\n feature swsh;\n sub quoteleft by quoteleft.fr;\n sub quoteright by quoteright.fr;\n} aalt;\n</code></pre>\n\t\t\t</details>", "* Example Feature Code Implementation\n ```fea\n feature aalt {\n feature salt;\n feature smcp;\n feature swsh;\n sub quoteleft by quoteleft.fr;\n sub quoteright by quoteright.fr;\n } aalt;\n ```\n"},
Expand Down

0 comments on commit c927554

Please sign in to comment.