Skip to content

Commit

Permalink
🎨 Improve inline code markdown editing siyuan-note/siyuan#9978
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 26, 2023
1 parent 9cf092e commit 79b81a8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
17 changes: 17 additions & 0 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ func randStr(length int) string {
return string(b)
}

func (n *Node) Marker() (ret string) {
// 该函数尚未完善,仅支持有限的场景

switch n.Type {
case NodeTag:
return "#"
case NodeEmphasis:
return "*"
case NodeStrong:
return "**"
case NodeStrikethrough:
return "~~"
}

return ""
}

func (n *Node) IsTextMarkType(typ string) bool {
types := strings.Split(n.TextMarkType, " ")
for _, t := range types {
Expand Down
4 changes: 2 additions & 2 deletions 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.

3 changes: 3 additions & 0 deletions parse/code_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ func (t *Tree) parseCodeSpan(block *ast.Node, ctx *InlineContext) (ret *ast.Node
content := bytes.Buffer{}
ast.Walk(inlineTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
content.WriteString(n.Marker())
return ast.WalkContinue
}

content.WriteString(n.Marker())

if ast.NodeTextMark == n.Type {
content.WriteString(n.TextMarkTextContent)
} else if ast.NodeText == n.Type {
Expand Down
1 change: 1 addition & 0 deletions test/m2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

var md2BlockDOMTests = []parseTest{

{"78", "`#foo# *foo* **foo** \\foo ~~foo~~`", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\">\u200b<span data-type=\"code\">\u200b#foo# *foo* **foo** \\foo ~~foo~~</span>\u200b</div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"77", "\\*foo\\*", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20060102150405\"><div contenteditable=\"true\" spellcheck=\"false\"><span data-type=\"backslash\">*</span>foo<span data-type=\"backslash\">*</span></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"76", "| `foo\\\\\\|bar` |\n| - |", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20060102150405\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /></colgroup><thead><tr><th>\u200b<span data-type=\"code\">\u200bfoo\\\\&#124;bar</span>\u200b</th></tr></thead><tbody></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
{"75", "| `foo\\\\|bar` |\n| - |", "<div data-node-id=\"20060102150405-1a2b3c4\" data-node-index=\"1\" data-type=\"NodeTable\" class=\"table\" updated=\"20060102150405\"><div contenteditable=\"false\"><table contenteditable=\"true\" spellcheck=\"false\"><colgroup><col /></colgroup><thead><tr><th>\u200b<span data-type=\"code\">\u200bfoo\\&#124;bar</span>\u200b</th></tr></thead><tbody></tbody></table><div class=\"protyle-action__table\"><div class=\"table__resize\"></div><div class=\"table__select\"></div></div></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
Expand Down

0 comments on commit 79b81a8

Please sign in to comment.