Skip to content

Commit

Permalink
🎨 Improve HTML to markdown siyuan-note/siyuan#11281 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 12, 2024
1 parent 60f8b15 commit 859ae9c
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 @@ -512,7 +512,7 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
case atom.A:
node.Type = ast.NodeLink
text := util.DomText(n)
if "" == text && nil != n.Parent && (atom.H1 == n.Parent.DataAtom || atom.H2 == n.Parent.DataAtom || atom.H3 == n.Parent.DataAtom || atom.H4 == n.Parent.DataAtom || atom.H5 == n.Parent.DataAtom || atom.H6 == n.Parent.DataAtom) {
if "" == text && nil != n.Parent && (atom.H1 == n.Parent.DataAtom || atom.H2 == n.Parent.DataAtom || atom.H3 == n.Parent.DataAtom || atom.H4 == n.Parent.DataAtom || atom.H5 == n.Parent.DataAtom || atom.H6 == n.Parent.DataAtom || atom.Div == n.Parent.DataAtom) {
// 丢弃标题中文本为空的链接,这样的链接可能是锚点 https://github.com/Vanessa219/vditor/issues/359
return
}
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{

{"99", "<div class=\"markdown-heading\"><h3 class=\"heading-element\"><code>subject:matches-attr(arg)</code></h3><a id=\"user-content-subjectmatches-attrarg\" class=\"anchor\" aria-label=\"Permalink: subject:matches-attr(arg)\" href=\"#subjectmatches-attrarg\"><svg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"></path></svg></a></div>", "### `subject:matches-attr(arg)`\n"},
{"98", "<code class=\"notranslate\"><span>capture_stdout=True,</span><span>&nbsp;</span><span>stderr=subprocess.STDOUT</span></code>", "`capture_stdout=True, stderr=subprocess.STDOUT`\n"},
{"97", "<pre class=\"prettyprint linenums prettyprinted\" style=\"\"><ol class=\"linenums\"><li class=\"L0\"><span class=\"pln\">sudo xattr </span><span class=\"pun\">-</span><span class=\"pln\">r </span><span class=\"pun\">-</span><span class=\"pln\">d com</span><span class=\"pun\">.</span><span class=\"pln\">apple</span><span class=\"pun\">.</span><span class=\"pln\">quarantine </span><span class=\"pun\">/</span><span class=\"typ\">Applications</span><span class=\"pun\">/</span><span class=\"pln\">host</span><span class=\"pun\">防验证工具.</span><span class=\"pln\">app</span></li></ol></pre>", "```\nsudo xattr -r -d com.apple.quarantine /Applications/host防验证工具.app\n```\n"},
{"96", "<pre class=\"prettyprint linenums prettyprinted\" style=\"overflow: auto;\"><ol class=\"linenums\"><li class=\"L0\"><code class=\"go\"><span class=\"pln\">today </span><span class=\"pun\">:=</span><span class=\"pln\"> time</span><span class=\"pun\">.</span><span class=\"typ\">Date</span><span class=\"pun\">(</span><span class=\"lit\">2022</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">10</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">31</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">0</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">0</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">0</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">0</span><span class=\"pun\">,</span><span class=\"pln\"> time</span><span class=\"pun\">.</span><span class=\"typ\">Local</span><span class=\"pun\">)</span></code></li><li class=\"L1\"><code class=\"go\"><span class=\"pln\">nextDay </span><span class=\"pun\">:=</span><span class=\"pln\"> today</span><span class=\"pun\">.</span><span class=\"typ\">AddDate</span><span class=\"pun\">(</span><span class=\"lit\">0</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">1</span><span class=\"pun\">,</span><span class=\"pln\"> </span><span class=\"lit\">0</span><span class=\"pun\">)</span></code></li><li class=\"L2\"><code class=\"go\"><span class=\"pln\">fmt</span><span class=\"pun\">.</span><span class=\"typ\">Println</span><span class=\"pun\">(</span><span class=\"pln\">nextDay</span><span class=\"pun\">.</span><span class=\"typ\">Format</span><span class=\"pun\">(</span><span class=\"str\">\"20060102\"</span><span class=\"pun\">))</span></code></li><li class=\"L3\"><code class=\"go\"></code></li><li class=\"L4\"><code class=\"go\"><span class=\"com\">// 输出:20221201</span></code></li></ol></pre>", "```go\ntoday := time.Date(2022, 10, 31, 0, 0, 0, 0, time.Local)\nnextDay := today.AddDate(0, 1, 0)\nfmt.Println(nextDay.Format(\"20060102\"))\n\n// 输出:20221201\n```\n"},
Expand Down

0 comments on commit 859ae9c

Please sign in to comment.