Skip to content

Commit

Permalink
🎨 Improve HTML code block clipping siyuan-note/siyuan#12014
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 25, 2024
1 parent 170030b commit ac4be43
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions h2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
buf := &bytes.Buffer{}
node.LastChild.CodeBlockInfo = []byte(language)
buf.WriteString(util.DomText(n))
content := &ast.Node{Type: ast.NodeCodeBlockCode, Tokens: buf.Bytes()}
tokens := buf.Bytes()
tokens = bytes.ReplaceAll(tokens, []byte("\u00A0"), []byte(" "))
content := &ast.Node{Type: ast.NodeCodeBlockCode, Tokens: tokens}
node.AppendChild(content)
node.AppendChild(&ast.Node{Type: ast.NodeCodeBlockFenceCloseMarker, Tokens: util.StrToBytes("```"), CodeBlockFenceLen: 3})
tree.Context.Tip.AppendChild(node)
Expand Down Expand Up @@ -398,7 +400,7 @@ func (lute *Lute) genASTByDOM(n *html.Node, tree *parse.Tree) {
firstc = n.FirstChild
}

if html.TextNode == firstc.Type || atom.Span == firstc.DataAtom || atom.Code == firstc.DataAtom || atom.Section == firstc.DataAtom || atom.Pre == firstc.DataAtom || atom.A == firstc.DataAtom {
if html.TextNode == firstc.Type || atom.Span == firstc.DataAtom || atom.Code == firstc.DataAtom || atom.Section == firstc.DataAtom || atom.Pre == firstc.DataAtom || atom.A == firstc.DataAtom || atom.P == firstc.DataAtom {
node.Type = ast.NodeCodeBlock
node.IsFencedCodeBlock = true
node.AppendChild(&ast.Node{Type: ast.NodeCodeBlockFenceOpenMarker, Tokens: util.StrToBytes("```"), CodeBlockFenceLen: 3})
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

Large diffs are not rendered by default.

0 comments on commit ac4be43

Please sign in to comment.