🧑‍💻 Add parameter imgTag for kernel API exportMdContent and copyStdMarkdown https://github.com/siyuan-note/siyuan/issues/15454

This commit is contained in:
Daniel 2025-08-07 20:16:58 +08:00
parent c2c927ecc2
commit 99fca2f716
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 24 additions and 12 deletions

View file

@ -437,7 +437,12 @@ func exportMdContent(c *gin.Context) {
adjustHeadingLevel = arg["adjustHeadingLevel"].(bool) adjustHeadingLevel = arg["adjustHeadingLevel"].(bool)
} }
hPath, content := model.ExportMarkdownContent(id, refMode, embedMode, yfm, fillCSSVar, adjustHeadingLevel) imgTag := false
if nil != arg["imgTag"] {
imgTag = arg["imgTag"].(bool)
}
hPath, content := model.ExportMarkdownContent(id, refMode, embedMode, yfm, fillCSSVar, adjustHeadingLevel, imgTag)
ret.Data = map[string]interface{}{ ret.Data = map[string]interface{}{
"hPath": hPath, "hPath": hPath,
"content": content, "content": content,

View file

@ -59,7 +59,12 @@ func copyStdMarkdown(c *gin.Context) {
adjustHeadingLevel = arg["adjustHeadingLevel"].(bool) adjustHeadingLevel = arg["adjustHeadingLevel"].(bool)
} }
ret.Data = model.ExportStdMarkdown(id, assetsDestSpace2Underscore, fillCSSVar, adjustHeadingLevel) imgTag := false
if nil != arg["imgTag"] {
imgTag = arg["imgTag"].(bool)
}
ret.Data = model.ExportStdMarkdown(id, assetsDestSpace2Underscore, fillCSSVar, adjustHeadingLevel, imgTag)
} }
func html2BlockDOM(c *gin.Context) { func html2BlockDOM(c *gin.Context) {

View file

@ -8,7 +8,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48 github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689 github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689
github.com/88250/lute v1.7.7-0.20250807111935-2082cd962215 github.com/88250/lute v1.7.7-0.20250807121338-5e107ba6c37c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4 github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
github.com/ConradIrwin/font v0.2.1 github.com/ConradIrwin/font v0.2.1

View file

@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689 h1:39y5g7vnFAIcXhTN3IXPk7h2xBhC4a9hBTykDhHJqRY= github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689 h1:39y5g7vnFAIcXhTN3IXPk7h2xBhC4a9hBTykDhHJqRY=
github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU= github.com/88250/gulu v1.2.3-0.20250227144607-7f4570b0d689/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU=
github.com/88250/lute v1.7.7-0.20250807111935-2082cd962215 h1:mJ3ilLbCYThH1RwFNFU64uA7lCT3XtKAnVOEP+kz9NQ= github.com/88250/lute v1.7.7-0.20250807121338-5e107ba6c37c h1:RzJLUTtxklE75Hf8YxrT9nsRKZTK34AA5nnLPjZ4lpM=
github.com/88250/lute v1.7.7-0.20250807111935-2082cd962215/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o= github.com/88250/lute v1.7.7-0.20250807121338-5e107ba6c37c/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46 h1:Bq1JsDfVbHKUxNL/B2JXd8cC/1h6aFjrlXpGycnh0Hk= github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46 h1:Bq1JsDfVbHKUxNL/B2JXd8cC/1h6aFjrlXpGycnh0Hk=
github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI= github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY= github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -268,7 +268,8 @@ func Export2Liandi(id string) (err error) {
title := path.Base(tree.HPath) title := path.Base(tree.HPath)
tags := tree.Root.IALAttr("tags") tags := tree.Root.IALAttr("tags")
content := exportMarkdownContent0(id, tree, util.GetCloudForumAssetsServer()+time.Now().Format("2006/01")+"/siyuan/"+Conf.GetUser().UserId+"/", true, false, content := exportMarkdownContent0(id, tree, util.GetCloudForumAssetsServer()+time.Now().Format("2006/01")+"/siyuan/"+Conf.GetUser().UserId+"/",
true, false, false,
".md", 3, 1, 1, ".md", 3, 1, 1,
"#", "#", "#", "#",
"", "", "", "",
@ -1459,7 +1460,7 @@ func processPDFLinkEmbedAssets(pdfCtx *model.Context, assetDests []string, remov
} }
} }
func ExportStdMarkdown(id string, assetsDestSpace2Underscore, fillCSSVar, adjustHeadingLevel bool) string { func ExportStdMarkdown(id string, assetsDestSpace2Underscore, fillCSSVar, adjustHeadingLevel, imgTag bool) string {
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
if nil == bt { if nil == bt {
logging.LogErrorf("block tree [%s] not found", id) logging.LogErrorf("block tree [%s] not found", id)
@ -1498,7 +1499,7 @@ func ExportStdMarkdown(id string, assetsDestSpace2Underscore, fillCSSVar, adjust
} }
defBlockIDs = gulu.Str.RemoveDuplicatedElem(defBlockIDs) defBlockIDs = gulu.Str.RemoveDuplicatedElem(defBlockIDs)
return exportMarkdownContent0(id, tree, cloudAssetsBase, assetsDestSpace2Underscore, adjustHeadingLevel, return exportMarkdownContent0(id, tree, cloudAssetsBase, assetsDestSpace2Underscore, adjustHeadingLevel, imgTag,
".md", Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode, ".md", Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker, Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight, Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
@ -1984,7 +1985,7 @@ func walkRelationAvs(avID string, exportAvIDs *hashset.Set) {
} }
} }
func ExportMarkdownContent(id string, refMode, embedMode int, addYfm, fillCSSVar, adjustHeadingLv bool) (hPath, exportedMd string) { func ExportMarkdownContent(id string, refMode, embedMode int, addYfm, fillCSSVar, adjustHeadingLv, imgTag bool) (hPath, exportedMd string) {
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
if nil == bt { if nil == bt {
return return
@ -1992,7 +1993,7 @@ func ExportMarkdownContent(id string, refMode, embedMode int, addYfm, fillCSSVar
tree := prepareExportTree(bt) tree := prepareExportTree(bt)
hPath = tree.HPath hPath = tree.HPath
exportedMd = exportMarkdownContent0(id, tree, "", false, adjustHeadingLv, exportedMd = exportMarkdownContent0(id, tree, "", false, adjustHeadingLv, imgTag,
".md", refMode, embedMode, Conf.Export.FileAnnotationRefMode, ".md", refMode, embedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker, Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight, Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
@ -2015,7 +2016,7 @@ func exportMarkdownContent(id, ext string, exportRefMode int, defBlockIDs []stri
isEmpty = nil == tree.Root.FirstChild.FirstChild isEmpty = nil == tree.Root.FirstChild.FirstChild
} }
exportedMd = exportMarkdownContent0(id, tree, "", false, false, exportedMd = exportMarkdownContent0(id, tree, "", false, false, false,
ext, exportRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode, ext, exportRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker, Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight, Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
@ -2028,7 +2029,7 @@ func exportMarkdownContent(id, ext string, exportRefMode int, defBlockIDs []stri
return return
} }
func exportMarkdownContent0(id string, tree *parse.Tree, cloudAssetsBase string, assetsDestSpace2Underscore, adjustHeadingLv bool, func exportMarkdownContent0(id string, tree *parse.Tree, cloudAssetsBase string, assetsDestSpace2Underscore, adjustHeadingLv, imgTag bool,
ext string, blockRefMode, blockEmbedMode, fileAnnotationRefMode int, ext string, blockRefMode, blockEmbedMode, fileAnnotationRefMode int,
tagOpenMarker, tagCloseMarker string, blockRefTextLeft, blockRefTextRight string, tagOpenMarker, tagCloseMarker string, blockRefTextLeft, blockRefTextRight string,
addTitle, inlineMemo bool, defBlockIDs []string, singleFile, fillCSSVar bool, treeCache *map[string]*parse.Tree) (ret string) { addTitle, inlineMemo bool, defBlockIDs []string, singleFile, fillCSSVar bool, treeCache *map[string]*parse.Tree) (ret string) {
@ -2148,6 +2149,7 @@ func exportMarkdownContent0(id string, tree *parse.Tree, cloudAssetsBase string,
} }
luteEngine.SetUnorderedListMarker("-") luteEngine.SetUnorderedListMarker("-")
luteEngine.SetImgTag(imgTag)
renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions) renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
ret = gulu.Str.FromBytes(renderer.Render()) ret = gulu.Str.FromBytes(renderer.Render())
return return