Skip to content

Commit

Permalink
🎨 Improve HTML clipping siyuan-note/siyuan#13342
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 4, 2024
1 parent 54b4e66 commit 8a0f920
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,16 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
imgClass := util.DomAttrValue(n, "class")
imgAlt := util.DomAttrValue(n, "alt")
if "emoji" == imgClass {
node.Type = ast.NodeEmoji
emojiImg := &ast.Node{Type: ast.NodeEmojiImg, Tokens: tree.EmojiImgTokens(imgAlt, util.DomAttrValue(n, "src"))}
emojiImg.AppendChild(&ast.Node{Type: ast.NodeEmojiAlias, Tokens: util.StrToBytes(":" + imgAlt + ":")})
node.AppendChild(emojiImg)
if e := parse.EmojiUnicodeAlias[imgAlt]; "" != e {
// 直接使用 alt 值(即 emoji 字符)https://github.com/siyuan-note/siyuan/issues/13342
node.Type = ast.NodeText
node.Tokens = []byte(imgAlt)
} else {
node.Type = ast.NodeEmoji
emojiImg := &ast.Node{Type: ast.NodeEmojiImg, Tokens: tree.EmojiImgTokens(imgAlt, util.DomAttrValue(n, "src"))}
emojiImg.AppendChild(&ast.Node{Type: ast.NodeEmojiAlias, Tokens: util.StrToBytes(":" + imgAlt + ":")})
node.AppendChild(emojiImg)
}
} else {
node.Type = ast.NodeImage
node.AppendChild(&ast.Node{Type: ast.NodeBang})
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{

{"212", "<p>foo <img draggable=\"false\" class=\"emoji\" alt=\"❓\" src=\"https://twemoji.maxcdn.com/v/14.0.2/72x72/2753.png\"> bar</p>", "foo ❓ bar\n"},
{"211", "<pre><textarea></textarea><span class=\"copyTooltip\" style=\"display: inline;\"><img src=\"https://learnblockchain.cn/css/default/copy.svg\"></span><code class=\"language-go hljs\"><span class=\"hljs-keyword\">type</span> PurchaseOrder <span class=\"hljs-keyword\">struct</span> { \n Id <span class=\"hljs-type\">uint</span> <span class=\"hljs-string\">`json:\"id\" gorm:\"primaryKey\"`</span> \n UserId <span class=\"hljs-type\">string</span> <span class=\"hljs-string\">`json:\"userId\"`</span> \n Product []Product <span class=\"hljs-string\">`json:\"product\" gorm:\"foreignKey:Id\"`</span> \n Date time.Time <span class=\"hljs-string\">`json:\"date\"`</span> \n}\n</code></pre>", "```go\ntype PurchaseOrder struct { \n Id uint `json:\"id\" gorm:\"primaryKey\"` \n UserId string `json:\"userId\"` \n Product []Product `json:\"product\" gorm:\"foreignKey:Id\"` \n Date time.Time `json:\"date\"` \n}\n```\n"},
{"210", "<pre><textarea></textarea><code class=\"language-go hljs\">this is code</code></pre>", "```go\nthis is code\n```\n"},
{"209", "<figure> <img alt=\"c03f001.eps\" class=\"center\" src=\"https://www.w3schools.com/tags/pic_trulli.jpg\"> <figcaption><p><a id=\"figure3-1\" href=\"#figureanchor3-1\"><b>Figure 3-1:</b></a> If you try to design an automobile that pleases every possible driver, you end up with a car with every possible feature that pleases nobody. Software today is too often designed to please too many users, resulting in low user satisfaction. <a id=\"figureanchor3-2\" href=\"#figure3-2\">Figure 3-2</a> provides an alternative approach.</p></figcaption> </figure>", "![c03f001.eps](https://www.w3schools.com/tags/pic_trulli.jpg \"Figure 3-1: If you try to design an automobile that pleases every possible driver, you end up with a car with every possible feature that pleases nobody. Software today is too often designed to please too many users, resulting in low user satisfaction. Figure 3-2 provides an alternative approach.\")\n"},
Expand Down

0 comments on commit 8a0f920

Please sign in to comment.