mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 Support replacing inline tags with plain text https://github.com/siyuan-note/siyuan/issues/11238
This commit is contained in:
parent
a1a8e2d7f7
commit
45bb96fad1
1 changed files with 17 additions and 5 deletions
|
|
@ -937,13 +937,25 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
|
||||||
|
|
||||||
func replaceNodeTextMarkTextContent(n *ast.Node, method int, keyword, escapedKey string, replacement string, r *regexp.Regexp, typ string) {
|
func replaceNodeTextMarkTextContent(n *ast.Node, method int, keyword, escapedKey string, replacement string, r *regexp.Regexp, typ string) {
|
||||||
if 0 == method {
|
if 0 == method {
|
||||||
if "tag" == typ {
|
if strings.Contains(typ, "tag") {
|
||||||
keyword = strings.TrimPrefix(keyword, "#")
|
keyword = strings.TrimPrefix(keyword, "#")
|
||||||
keyword = strings.TrimSuffix(keyword, "#")
|
keyword = strings.TrimSuffix(keyword, "#")
|
||||||
escapedKey = strings.TrimPrefix(replacement, "#")
|
escapedKey = strings.TrimPrefix(escapedKey, "#")
|
||||||
escapedKey = strings.TrimSuffix(replacement, "#")
|
escapedKey = strings.TrimSuffix(escapedKey, "#")
|
||||||
|
if strings.HasPrefix(replacement, "#") && strings.HasSuffix(replacement, "#") {
|
||||||
replacement = strings.TrimPrefix(replacement, "#")
|
replacement = strings.TrimPrefix(replacement, "#")
|
||||||
replacement = strings.TrimSuffix(replacement, "#")
|
replacement = strings.TrimSuffix(replacement, "#")
|
||||||
|
} else { // 将标签转换为纯文本
|
||||||
|
if "tag" == n.TextMarkType { // 没有其他类型,仅是标签时直接转换
|
||||||
|
n.InsertBefore(&ast.Node{Type: ast.NodeText, Tokens: []byte(n.TextMarkTextContent)})
|
||||||
|
n.TextMarkTextContent = ""
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在其他类型时仅移除标签类型
|
||||||
|
n.TextMarkType = strings.ReplaceAll(n.TextMarkType, "tag", "")
|
||||||
|
n.TextMarkType = strings.TrimSpace(n.TextMarkType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(n.TextMarkTextContent, escapedKey) {
|
if strings.Contains(n.TextMarkTextContent, escapedKey) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue