🎨 Supports disabling Markdown syntax input for some inline elements https://github.com/siyuan-note/siyuan/issues/11141

This commit is contained in:
Daniel 2024-04-26 12:08:01 +08:00
parent 53f5b08038
commit b9f269ae85
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
17 changed files with 185 additions and 41 deletions

View file

@ -330,6 +330,8 @@ func setEditor(c *gin.Context) {
util.BroadcastByType("main", "readonly", 0, "", model.Conf.Editor.ReadOnly)
}
util.MarkdownSettings = model.Conf.Editor.Markdown
ret.Data = model.Conf.Editor
}

View file

@ -16,38 +16,41 @@
package conf
import "github.com/siyuan-note/siyuan/kernel/util"
type Editor struct {
FontSize int `json:"fontSize"` // 字体大小
FontSizeScrollZoom bool `json:"fontSizeScrollZoom"` // 字体大小是否支持滚轮缩放
FontFamily string `json:"fontFamily"` // 字体
CodeSyntaxHighlightLineNum bool `json:"codeSyntaxHighlightLineNum"` // 代码块是否显示行号
CodeTabSpaces int `json:"codeTabSpaces"` // 代码块中 Tab 转换空格数,配置为 0 则表示不转换
CodeLineWrap bool `json:"codeLineWrap"` // 代码块是否自动折行
CodeLigatures bool `json:"codeLigatures"` // 代码块是否连字
DisplayBookmarkIcon bool `json:"displayBookmarkIcon"` // 是否显示书签图标
DisplayNetImgMark bool `json:"displayNetImgMark"` // 是否显示网络图片角标
GenerateHistoryInterval int `json:"generateHistoryInterval"` // 生成历史时间间隔,单位:分钟
HistoryRetentionDays int `json:"historyRetentionDays"` // 历史保留天数
Emoji []string `json:"emoji"` // 常用表情
VirtualBlockRef bool `json:"virtualBlockRef"` // 是否启用虚拟引用
VirtualBlockRefExclude string `json:"virtualBlockRefExclude"` // 虚拟引用关键字排除列表
VirtualBlockRefInclude string `json:"virtualBlockRefInclude"` // 虚拟引用关键字包含列表
BlockRefDynamicAnchorTextMaxLen int `json:"blockRefDynamicAnchorTextMaxLen"` // 块引动态锚文本最大长度
PlantUMLServePath string `json:"plantUMLServePath"` // PlantUML 伺服地址
FullWidth bool `json:"fullWidth"` // 是否使用最大宽度
KaTexMacros string `json:"katexMacros"` // KeTex 宏定义
ReadOnly bool `json:"readOnly"` // 只读模式
EmbedBlockBreadcrumb bool `json:"embedBlockBreadcrumb"` // 嵌入块是否显示面包屑
ListLogicalOutdent bool `json:"listLogicalOutdent"` // 列表逻辑反向缩进
ListItemDotNumberClickFocus bool `json:"listItemDotNumberClickFocus"` // 单击列表项标记聚焦
FloatWindowMode int `json:"floatWindowMode"` // 浮窗触发模式0光标悬停1按住 Ctrl 悬停2不触发浮窗
DynamicLoadBlocks int `json:"dynamicLoadBlocks"` // 块动态数,可配置区间 [48, 1024]
Justify bool `json:"justify"` // 是否两端对齐
RTL bool `json:"rtl"` // 是否从右到左显示
Spellcheck bool `json:"spellcheck"` // 是否启用拼写检查
OnlySearchForDoc bool `json:"onlySearchForDoc"` // 是否启用 [[ 仅搜索文档块
BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量
BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量
FontSize int `json:"fontSize"` // 字体大小
FontSizeScrollZoom bool `json:"fontSizeScrollZoom"` // 字体大小是否支持滚轮缩放
FontFamily string `json:"fontFamily"` // 字体
CodeSyntaxHighlightLineNum bool `json:"codeSyntaxHighlightLineNum"` // 代码块是否显示行号
CodeTabSpaces int `json:"codeTabSpaces"` // 代码块中 Tab 转换空格数,配置为 0 则表示不转换
CodeLineWrap bool `json:"codeLineWrap"` // 代码块是否自动折行
CodeLigatures bool `json:"codeLigatures"` // 代码块是否连字
DisplayBookmarkIcon bool `json:"displayBookmarkIcon"` // 是否显示书签图标
DisplayNetImgMark bool `json:"displayNetImgMark"` // 是否显示网络图片角标
GenerateHistoryInterval int `json:"generateHistoryInterval"` // 生成历史时间间隔,单位:分钟
HistoryRetentionDays int `json:"historyRetentionDays"` // 历史保留天数
Emoji []string `json:"emoji"` // 常用表情
VirtualBlockRef bool `json:"virtualBlockRef"` // 是否启用虚拟引用
VirtualBlockRefExclude string `json:"virtualBlockRefExclude"` // 虚拟引用关键字排除列表
VirtualBlockRefInclude string `json:"virtualBlockRefInclude"` // 虚拟引用关键字包含列表
BlockRefDynamicAnchorTextMaxLen int `json:"blockRefDynamicAnchorTextMaxLen"` // 块引动态锚文本最大长度
PlantUMLServePath string `json:"plantUMLServePath"` // PlantUML 伺服地址
FullWidth bool `json:"fullWidth"` // 是否使用最大宽度
KaTexMacros string `json:"katexMacros"` // KeTex 宏定义
ReadOnly bool `json:"readOnly"` // 只读模式
EmbedBlockBreadcrumb bool `json:"embedBlockBreadcrumb"` // 嵌入块是否显示面包屑
ListLogicalOutdent bool `json:"listLogicalOutdent"` // 列表逻辑反向缩进
ListItemDotNumberClickFocus bool `json:"listItemDotNumberClickFocus"` // 单击列表项标记聚焦
FloatWindowMode int `json:"floatWindowMode"` // 浮窗触发模式0光标悬停1按住 Ctrl 悬停2不触发浮窗
DynamicLoadBlocks int `json:"dynamicLoadBlocks"` // 块动态数,可配置区间 [48, 1024]
Justify bool `json:"justify"` // 是否两端对齐
RTL bool `json:"rtl"` // 是否从右到左显示
Spellcheck bool `json:"spellcheck"` // 是否启用拼写检查
OnlySearchForDoc bool `json:"onlySearchForDoc"` // 是否启用 [[ 仅搜索文档块
BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量
BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量
Markdown *util.Markdown `json:"markdown"` // Markdown 配置
}
const (
@ -83,5 +86,6 @@ func NewEditor() *Editor {
RTL: false,
BacklinkExpandCount: 8,
BackmentionExpandCount: 8,
Markdown: util.MarkdownSettings,
}
}

View file

@ -10,7 +10,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30
github.com/88250/lute v1.7.7-0.20240425021622-7773b213b113
github.com/88250/lute v1.7.7-0.20240426034208-275376345554
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -12,8 +12,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/gulu v1.2.3-0.20240324024901-3c1bb82cba30 h1:IeE4DVRWnVpcbMj7gGZoSMiBWs3h/ihiyOmualS1Mas=
github.com/88250/gulu v1.2.3-0.20240324024901-3c1bb82cba30/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240425021622-7773b213b113 h1:s4geGWFDTu1rF+/6p+AqODDhy7pS5KBgWGKTgPnJk70=
github.com/88250/lute v1.7.7-0.20240425021622-7773b213b113/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20240426034208-275376345554 h1:XwSEW6Jts20V/uOKBljMl2AFSPyPbpx+4pCRluKuVVk=
github.com/88250/lute v1.7.7-0.20240426034208-275376345554/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -267,6 +267,10 @@ func InitConf() {
if 0 > Conf.Editor.BackmentionExpandCount {
Conf.Editor.BackmentionExpandCount = 0
}
if nil == Conf.Editor.Markdown {
Conf.Editor.Markdown = &util.Markdown{}
}
util.MarkdownSettings = Conf.Editor.Markdown
if nil == Conf.Export {
Conf.Export = conf.NewExport()

View file

@ -24,6 +24,21 @@ import (
"github.com/siyuan-note/logging"
)
// MarkdownSettings 运行时 Markdown 配置。
var MarkdownSettings = &Markdown{
InlineSup: false,
InlineSub: false,
InlineTag: false,
InlineMath: false,
}
type Markdown struct {
InlineSup bool `json:"inlineSup"` // 是否启用行级上标
InlineSub bool `json:"inlineSub"` // 是否启用行级下标
InlineTag bool `json:"inlineTag"` // 是否启用行级标签
InlineMath bool `json:"inlineMath"` // 是否启用行级公式
}
func NewLute() (ret *lute.Lute) {
ret = lute.New()
ret.SetTextMark(true)
@ -36,9 +51,12 @@ func NewLute() (ret *lute.Lute) {
ret.SetImgPathAllowSpace(true)
ret.SetGitConflict(true)
ret.SetMark(true)
ret.SetSup(true)
ret.SetSub(true)
ret.SetSup(MarkdownSettings.InlineSup)
ret.SetSub(MarkdownSettings.InlineSub)
ret.SetTag(MarkdownSettings.InlineTag)
ret.SetInlineMath(MarkdownSettings.InlineMath)
ret.SetInlineMathAllowDigitAfterOpenMarker(true)
ret.SetGFMStrikethrough1(false)
ret.SetFootnotes(false)
ret.SetToC(false)
ret.SetIndentCodeBlock(false)

View file

@ -38,7 +38,7 @@ import (
"github.com/siyuan-note/logging"
)
// UseSingleLineSave 是否使用单行保存 .sy 文件。
// UseSingleLineSave 是否使用单行保存 .sy 和数据库 .json 文件。
var UseSingleLineSave = true
// IsUILoaded 是否已经加载了 UI。