Skip to content

Commit

Permalink
🎨 Improve HTML custom tag clipping siyuan-note/siyuan#11813
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jun 28, 2024
1 parent 65118a2 commit b5d9173
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
tree.Context.Tip = node
defer tree.Context.ParentTip()
default:

}

for c := n.FirstChild; c != nil; c = c.NextSibling {
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{

{"164", "<div class=\"content\" id=\"zoomcon\">\n<ucapcontent><p align=\"\" style=\"text-indent: 2em; text-align: justify; line-height: 2;\">为适应节能与新能源汽车产业发展和技术进步需要,促进节约能源,鼓励使用新能源,现就《财政部 税务总局 工业和信息化部 交通运输部关于节能 新能源车船享受车船税优惠政策的通知》(财税〔2018〕74号)中享受车船税优惠的节能、新能源汽车产品技术要求有关事项公告如下:</p>\n</ucapcontent>\n</div>", "为适应节能与新能源汽车产业发展和技术进步需要,促进节约能源,鼓励使用新能源,现就《财政部 税务总局 工业和信息化部 交通运输部关于节能 新能源车船享受车船税优惠政策的通知》(财税〔2018〕74 号)中享受车船税优惠的节能、新能源汽车产品技术要求有关事项公告如下:\n"},
{"163", "<mjx-container jax=\"SVG\" role=\"presentation\" tabindex=\"0\" ctxtmenu_counter=\"6\" data-formula=\"(x_0,y_0)\" style=\"visibility: visible;\"><svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"7.421ex\" height=\"2.671ex\" viewBox=\"0 -835.3 3195 1149.8\" role=\"img\" focusable=\"false\" style=\"vertical-align: -0.73ex; font-size: 14px; visibility: visible;\" xmlns=\"http://www.w3.org/2000/svg\"><g stroke=\"currentColor\" fill=\"currentColor\" stroke-width=\"0\" transform=\"matrix(1 0 0 -1 0 0)\" style=\"visibility: visible;\"><path stroke-width=\"1\" d=\"M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z\" style=\"visibility: visible;\"></path><g transform=\"translate(389,0)\" style=\"visibility: visible;\"><path stroke-width=\"1\" d=\"M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z\" style=\"visibility: visible;\"></path><g transform=\"translate(572,-150)\" style=\"visibility: visible;\"><path stroke-width=\"1\" transform=\"scale(0.707)\" d=\"M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z\" style=\"visibility: visible;\"></path></g></g><g transform=\"translate(1415,0)\" style=\"visibility: visible;\"><path stroke-width=\"1\" d=\"M78 35T78 60T94 103T137 121Q165 121 187 96T210 8Q210 -27 201 -60T180 -117T154 -158T130 -185T117 -194Q113 -194 104 -185T95 -172Q95 -168 106 -156T131 -126T157 -76T173 -3V9L172 8Q170 7 167 6T161 3T152 1T140 0Q113 0 96 17Z\" style=\"visibility: visible;\"></path></g><g transform=\"translate(1861,0)\" style=\"visibility: visible;\"><path stroke-width=\"1\" d=\"M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z\" style=\"visibility: visible;\"></path><g transform=\"translate(490,-150)\" style=\"visibility: visible;\"><path stroke-width=\"1\" transform=\"scale(0.707)\" d=\"M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z\" style=\"visibility: visible;\"></path></g></g><g transform=\"translate(2805,0)\" style=\"visibility: visible;\"><path stroke-width=\"1\" d=\"M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z\" style=\"visibility: visible;\"></path></g></g></svg>&nbsp;</mjx-container>", "$(x_0,y_0)$\n"},
{"162", "<figure data-size=\"normal\"><noscript><img src=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.gif\" data-size=\"normal\" data-rawwidth=\"592\" data-rawheight=\"448\" data-thumbnail=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.jpg\" class=\"origin_image zh-lightbox-thumb\" width=\"592\" data-original=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_r.jpg\"/></noscript><div><div class=\"GifPlayer css-1isopsn\" data-size=\"normal\" data-za-detail-view-path-module=\"GifItem\"><img class=\"ztext-gif GifPlayer-gif2mp4Image\" width=\"592\" role=\"presentation\" src=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.jpg\" data-thumbnail=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.jpg\" data-size=\"normal\" alt=\"动图封面\" style=\"display: block;\"><video class=\"ztext-gif GifPlayer-gif2mp4 css-1xeqk96\" src=\"https://vdn6.vzuu.com/SD/acfbc2e8-236e-11eb-a7d2-3e2df5db3b6f.mp4?pkey=AAXyt-BzKx_ecDxDGOEtsGZ18YAiBUFu_6i-H-JQKevkuYIpsiXBtjkrOEHpIHq5jesfZ5lVrea8c4KHM-aH58MU&amp;c=avc.0.0&amp;f=mp4&amp;pu=078babd7&amp;bu=078babd7&amp;expiration=1719239939&amp;v=ks6\" data-thumbnail=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.jpg\" poster=\"https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.jpg\" data-size=\"normal\" preload=\"metadata\" loop=\"\" playsinline=\"\"></video><div class=\"GifPlayer-icon css-d39tw7\"><svg width=\"50\" height=\"50\" viewBox=\"0 0 60 60\" xmlns=\"http://www.w3.org/2000/svg\"><g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"><ellipse fill=\"#000\" opacity=\"0.45\" cx=\"30\" cy=\"30\" rx=\"30\" ry=\"30\"></ellipse><ellipse stroke=\"#FFF\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" opacity=\"0.5\" cx=\"30\" cy=\"30\" rx=\"26\" ry=\"26\"></ellipse></g><svg x=\"16\" y=\"18.5\"><g fill=\"#fff\"><path x=\"100\" y=\"100\" d=\"M12.8422852,12.9814453 L12.8422852,11.3994141 L7.63916016,11.3994141 L7.63916016,13.0517578 L10.9086914,13.0517578 L10.9086914,13.3242188 C10.8911133,15.2050781 9.46728516,16.4707031 7.39306641,16.4707031 C5.01123047,16.4707031 3.51708984,14.625 3.51708984,11.6367188 C3.51708984,8.70117188 5.00244141,6.84667969 7.34912109,6.84667969 C9.08056641,6.84667969 10.284668,7.68164062 10.7768555,9.2109375 L12.7543945,9.2109375 C12.3237305,6.64453125 10.2319336,5.00976562 7.34912109,5.00976562 C3.79833984,5.00976562 1.50439453,7.61132812 1.50439453,11.6542969 C1.50439453,15.75 3.77197266,18.3076172 7.36669922,18.3076172 C10.6889648,18.3076172 12.8422852,16.2246094 12.8422852,12.9814453 Z M17.5180664,18 L17.5180664,5.31738281 L15.5493164,5.31738281 L15.5493164,18 L17.5180664,18 Z M22.659668,18 L22.659668,12.7441406 L28.1088867,12.7441406 L28.1088867,11.0039062 L22.659668,11.0039062 L22.659668,7.11035156 L28.6098633,7.11035156 L28.6098633,5.31738281 L20.690918,5.31738281 L20.690918,18 L22.659668,18 Z\"></path></g></svg></svg></div></div></div><figcaption>异步更新动画示意图</figcaption></figure>", "![](https://pic2.zhimg.com/v2-75dc0f59d2630e85a79090c1c7cd7dd5_b.gif)\n异步更新动画示意图\n"},
{"161", "<span style=\"letter-spacing: 1px;\"><span style=\"outline: 0px;background-color: rgb(255, 104, 39);font-size: 17px;color: rgb(255, 255, 255);\"><strong style=\"outline: 0px;\"><span style=\"background-color: rgb(255, 104, 39);font-size: 17px;outline: 0px;font-family: Optima-Regular, PingFangTC-light;\">&nbsp;1&nbsp;</span></strong></span><span style=\"outline: 0px;font-size: 17px;\"><strong style=\"outline: 0px;\"><span style=\"outline: 0px;font-family: Optima-Regular, PingFangTC-light;\">&nbsp;</span></strong></span><strong style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 1px;outline: 0px;\"><span style=\"outline: 0px;font-family: Optima-Regular, PingFangTC-light;\">小米科技理念</span></strong><strong style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 1px;outline: 0px;\"></strong></span>", "**\u200b 1 \u200b** **小米科技理念**\n"},
Expand Down
19 changes: 19 additions & 0 deletions vditor_wysiwyg.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func (lute *Lute) adjustVditorDOM(root *html.Node) {
c = next
}

for c := root.FirstChild; nil != c; c = c.NextSibling {
lute.adjustCustomTag(c)
}

for c := root.FirstChild; nil != c; c = c.NextSibling {
lute.mergeSameStrong(c)
}
Expand All @@ -232,6 +236,21 @@ func (lute *Lute) adjustVditorDOM(root *html.Node) {
}
}

func (lute *Lute) adjustCustomTag(n *html.Node) {
// 将某些自定义标签转换为标准标签

if html.ElementNode == n.Type && 0 == n.DataAtom {
if "ucapcontent" == n.Data {
n.DataAtom = atom.Div
n.Data = "div"
}
}

for c := n.FirstChild; nil != c; c = c.NextSibling {
lute.adjustCustomTag(c)
}
}

func (lute *Lute) adjustNoscriptImg(n *html.Node) {
if nil != n.Parent && atom.Figure == n.Parent.DataAtom &&
atom.Noscript == n.DataAtom && nil != n.FirstChild && strings.HasPrefix(n.FirstChild.Data, "<img ") {
Expand Down

0 comments on commit b5d9173

Please sign in to comment.