Skip to content

Commit

Permalink
🎨 Supports disabling Markdown * and _ syntax input #11206
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 13, 2024
1 parent 0309e17 commit f50c0d6
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "After enabling, <code class='fn__code'>#foo#</code> inline tag input syntax will be supported",
"editorMarkdownInlineMath": "Markdown inline formula syntax",
"editorMarkdownInlineMathTip": "After enabling, <code class='fn__code'>$foo$</code> inline formula syntax input will be supported",
"editorMarkdownInlineAsterisk": "Markdown inline asterisk syntax",
"editorMarkdownInlineAsteriskTip": "After enabling, <code class='fn__code'>*foo*</code> italic syntax and <code class='fn__code'>**foo**</code> bold syntax input will be supported",
"editorMarkdownInlineUnderscore": "Markdown inline underline syntax",
"editorMarkdownInlineUnderscoreTip": "After enabling, <code class='fn__code'>_foo_</code> italic syntax and <code class='fn__code'>__foo__</code> bold syntax input will be supported",
"currentNotebook": "Current Notebook",
"containerBlockTip1": "Enabling container blocks will result in duplicate search results",
"containerBlockTip2": "Enabling document blocks currently only supports searching for document titles",
Expand Down
4 changes: 4 additions & 0 deletions app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "Después de habilitar, se admitirá la sintaxis de entrada de etiqueta en línea <code class='fn__code'>#foo#</code>",
"editorMarkdownInlineMath": "Sintaxis de fórmula en línea de Markdown",
"editorMarkdownInlineMathTip": "Después de habilitar, se admitirá la entrada de sintaxis de fórmula en línea <code class='fn__code'>$foo$</code>",
"editorMarkdownInlineAsterisk": "Sintaxis de asterisco en línea de Markdown",
"editorMarkdownInlineAsteriskTip": "Después de habilitar, se admitirá la entrada de sintaxis <code class='fn__code'>*foo*</code> en cursiva y <code class='fn__code'>**foo**</code> en negrita" ,
"editorMarkdownInlineUnderscore": "Sintaxis de subrayado en línea de Markdown",
"editorMarkdownInlineUnderscoreTip": "Después de habilitar, se admitirá la sintaxis <code class='fn__code'>_foo_</code> en cursiva y <code class='fn__code'>__foo__</code> en negrita",
"currentNotebook": "Cuaderno actual",
"containerBlockTip1": "Habilitar bloques de contenedores generará resultados de búsqueda duplicados",
"containerBlockTip2": "Habilitar bloques de documentos actualmente solo admite la búsqueda de títulos de documentos",
Expand Down
4 changes: 4 additions & 0 deletions app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "Après l'activation, la syntaxe de saisie des balises en ligne <code class='fn__code'>#foo#</code> sera prise en charge",
"editorMarkdownInlineMath": "Syntaxe de formule en ligne Markdown",
"editorMarkdownInlineMathTip": "Après l'activation, la saisie de la syntaxe de formule en ligne <code class='fn__code'>$foo$</code> sera prise en charge",
"editorMarkdownInlineAsterisk": "Syntaxe d'astérisque en ligne Markdown",
"editorMarkdownInlineAsteriskTip": "Après l'activation, la syntaxe <code class='fn__code'>*foo*</code> italique et la syntaxe <code class='fn__code'>**foo**</code> en gras seront prises en charge" ,
"editorMarkdownInlineUnderscore": "Syntaxe de soulignement en ligne Markdown",
"editorMarkdownInlineUnderscoreTip": "Après l'activation, la syntaxe <code class='fn__code'>_foo_</code> italique et la syntaxe <code class='fn__code'>__foo__</code> gras seront prises en charge",
"currentNotebook": "Carnet actuel",
"containerBlockTip1": "L'activation des blocs de conteneurs entraînera des résultats de recherche en double",
"containerBlockTip2": "L'activation des blocs de documents ne prend actuellement en charge que la recherche de titres de documents",
Expand Down
4 changes: 4 additions & 0 deletions app/appearance/langs/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "<code class='fn__code'>#foo#</code> 形式のインラインタグ構文を有効にします",
"editorMarkdownInlineMath": "Markdown インライン数式構文",
"editorMarkdownInlineMathTip": "<code class='fn__code'>$foo$</code> 形式のインライン数式構文を有効にします",
"editorMarkdownInlineAsterisk": "マークダウン インライン アスタリスク構文",
"editorMarkdownInlineAsteriskTip": "有効にすると、<code class='fn__code'>*foo*</code> 斜体構文と <code class='fn__code'>**foo**</code> 太字構文の入力がサポートされます。"
"editorMarkdownInlineUnderscore": "マークダウンのインライン下線構文",
"editorMarkdownInlineUnderscoreTip": "有効にすると、<code class='fn__code'>_foo_</code> 斜体構文と <code class='fn__code'>__foo__</code> 太字構文の入力がサポートされます",
"currentNotebook": "現在のノートブック",
"containerBlockTip1": "コンテナブロックを有効にすると重複した検索結果が表示されます",
"containerBlockTip2": "ドキュメントブロックはタイトルの検索のみをサポートしています",
Expand Down
4 changes: 4 additions & 0 deletions app/appearance/langs/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "啟用後將支援 <code class='fn__code'>#foo#</code> 行級標籤語法輸入",
"editorMarkdownInlineMath": "Markdown 行級公式語法",
"editorMarkdownInlineMathTip": "啟用後將支援 <code class='fn__code'>$foo$</code> 行級公式語法輸入",
"editorMarkdownInlineAsterisk": "Markdown 行級星號語法",
"editorMarkdownInlineAsteriskTip": "啟用後將支援 <code class='fn__code'>*foo*</code> 傾斜語法和 <code class='fn__code'>**foo**</code> 加粗語法輸入",
"editorMarkdownInlineUnderscore": "Markdown 行級底線語法",
"editorMarkdownInlineUnderscoreTip": "啟用後將支援 <code class='fn__code'>_foo_</code> 傾斜語法和 <code class='fn__code'>__foo__</code> 加粗語法輸入",
"currentNotebook": "目前筆記本",
"containerBlockTip1": "啟用容器區塊後會導致搜尋結果重複",
"containerBlockTip2": "啟用文件區塊目前僅支援搜尋文件名稱",
Expand Down
4 changes: 4 additions & 0 deletions app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"editorMarkdownInlineTagTip": "启用后将支持 <code class='fn__code'>#foo#</code> 行级标签语法输入",
"editorMarkdownInlineMath": "Markdown 行级公式语法",
"editorMarkdownInlineMathTip": "启用后将支持 <code class='fn__code'>$foo$</code> 行级公式语法输入",
"editorMarkdownInlineAsterisk": "Markdown 行级星号语法",
"editorMarkdownInlineAsteriskTip": "启用后将支持 <code class='fn__code'>*foo*</code> 倾斜语法和 <code class='fn__code'>**foo**</code> 加粗语法输入",
"editorMarkdownInlineUnderscore": "Markdown 行级下划线语法",
"editorMarkdownInlineUnderscoreTip": "启用后将支持 <code class='fn__code'>_foo_</code> 倾斜语法和 <code class='fn__code'>__foo__</code> 加粗语法输入",
"currentNotebook": "当前笔记本",
"containerBlockTip1": "启用容器块后会导致搜索结果重复",
"containerBlockTip2": "启用文档块目前仅支持搜索文档名",
Expand Down
18 changes: 18 additions & 0 deletions app/src/config/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ export const editor = {
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="allowHTMLBLockScript" type="checkbox"${window.siyuan.config.editor.allowHTMLBLockScript ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineAsterisk}
<div class="b3-label__text">${window.siyuan.languages.editorMarkdownInlineAsteriskTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="editorMarkdownInlineAsterisk" type="checkbox"${window.siyuan.config.editor.markdown.inlineAsterisk ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineUnderscore}
<div class="b3-label__text">${window.siyuan.languages.editorMarkdownInlineUnderscoreTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="editorMarkdownInlineUnderscore" type="checkbox"${window.siyuan.config.editor.markdown.inlineUnderscore ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineSup}
Expand Down Expand Up @@ -332,6 +348,8 @@ export const editor = {
fetchPost("/api/setting/setEditor", {
fullWidth: (editor.element.querySelector("#fullWidth") as HTMLInputElement).checked,
markdown: {
inlineAsterisk: (editor.element.querySelector("#editorMarkdownInlineAsterisk") as HTMLInputElement).checked,
inlineUnderscore: (editor.element.querySelector("#editorMarkdownInlineUnderscore") as HTMLInputElement).checked,
inlineSup: (editor.element.querySelector("#editorMarkdownInlineSup") as HTMLInputElement).checked,
inlineSub: (editor.element.querySelector("#editorMarkdownInlineSub") as HTMLInputElement).checked,
inlineTag: (editor.element.querySelector("#editorMarkdownInlineTag") as HTMLInputElement).checked,
Expand Down
7 changes: 4 additions & 3 deletions app/src/config/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const initConfigSearch = (element: HTMLElement, app: App) => {
"outdent", "floatWindowMode", "floatWindowModeTip", "justify", "justifyTip", "rtl", "rtlTip", "spellcheck",
"spellcheckTip", "backlinkExpand", "backlinkExpandTip", "backmentionExpand", "backmentionExpandTip",
"onlySearchForDoc", "onlySearchForDocTip", "dynamicLoadBlocks", "dynamicLoadBlocksTip", "fontSizeScrollZoom", "fontSizeScrollZoomTip",
"listItemDotNumberClickFocus", "listItemDotNumberClickFocusTip", "editorMarkdownInlineSup", "editorMarkdownInlineSupTip",
"editorMarkdownInlineSub", "editorMarkdownInlineSubTip", "editorMarkdownInlineTag", "editorMarkdownInlineTagTip",
"editorMarkdownInlineMath", "editorMarkdownInlineMathTip", "allowHTMLBLockScript", "allowHTMLBLockScriptTip",
"listItemDotNumberClickFocus", "listItemDotNumberClickFocusTip", "editorMarkdownInlineAsterisk", "editorMarkdownInlineUnderscore",
"editorMarkdownInlineSup", "editorMarkdownInlineSupTip", "editorMarkdownInlineSub", "editorMarkdownInlineSubTip",
"editorMarkdownInlineTag", "editorMarkdownInlineTagTip", "editorMarkdownInlineMath", "editorMarkdownInlineMathTip",
"allowHTMLBLockScript", "allowHTMLBLockScriptTip",
]),

// 文档树
Expand Down
18 changes: 18 additions & 0 deletions app/src/mobile/settings/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const setEditor = (modelMainElement: Element) => {
(modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value = "1024";
}
window.siyuan.config.editor.markdown = {
inlineAsterisk: (modelMainElement.querySelector("#editorMarkdownInlineAsterisk") as HTMLInputElement).checked,
inlineUnderscore: (modelMainElement.querySelector("#editorMarkdownInlineUnderscore") as HTMLInputElement).checked,
inlineSup: (modelMainElement.querySelector("#editorMarkdownInlineSup") as HTMLInputElement).checked,
inlineSub: (modelMainElement.querySelector("#editorMarkdownInlineSub") as HTMLInputElement).checked,
inlineTag: (modelMainElement.querySelector("#editorMarkdownInlineTag") as HTMLInputElement).checked,
Expand Down Expand Up @@ -262,6 +264,22 @@ export const initEditor = () => {
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="allowHTMLBLockScript" type="checkbox"${window.siyuan.config.editor.allowHTMLBLockScript ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineAsterisk}
<div class="b3-label__text">${window.siyuan.languages.editorMarkdownInlineAsteriskTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="editorMarkdownInlineAsterisk" type="checkbox"${window.siyuan.config.editor.markdown.inlineAsterisk ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineUnderscore}
<div class="b3-label__text">${window.siyuan.languages.editorMarkdownInlineUnderscoreTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="editorMarkdownInlineUnderscore" type="checkbox"${window.siyuan.config.editor.markdown.inlineUnderscore ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.editorMarkdownInlineSup}
Expand Down
2 changes: 2 additions & 0 deletions app/src/protyle/render/setLute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const setLute = (options: ILuteOptions) => {
lute.SetTag(true);
lute.SetSuperBlock(true);
lute.SetMark(true);
lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);
lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);
lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);
lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);
lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);
Expand Down
2 changes: 2 additions & 0 deletions app/src/protyle/util/reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?
}
protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);
protyle.lute.SetSpellcheck(window.siyuan.config.editor.spellcheck);
protyle.lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);
protyle.lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);
protyle.lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);
protyle.lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);
protyle.lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);
Expand Down
8 changes: 8 additions & 0 deletions app/src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ declare namespace Config {
* SiYuan editor markdown related configuration
*/
interface IMarkdown {
/**
* Whether to enable the inline asterisk
*/
inlineAsterisk: boolean;
/**
* Whether to enable the inline underscore
*/
inlineUnderscore: boolean;
/**
* Whether to enable the inline superscript
*/
Expand Down
4 changes: 4 additions & 0 deletions app/src/types/protyle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ declare class Lute {

public SetSup(enable: boolean): void;

public SetInlineAsterisk(enable: boolean): void;

public SetInlineUnderscore(enable: boolean): void;

public SetBlockRef(enable: boolean): void;

public SetSanitize(enable: boolean): void;
Expand Down
2 changes: 1 addition & 1 deletion kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240612035750-c9cf5f7a4d02
github.com/88250/lute v1.7.7-0.20240912031742-019dc0c2f23a
github.com/88250/lute v1.7.7-0.20240913030339-dd8f3f4ef1fd
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
Expand Down
4 changes: 2 additions & 2 deletions kernel/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240912031742-019dc0c2f23a h1:LKuQgW8p6QdhsGOGVOupcR+zya2peo6VuD1aXpEgQ5I=
github.com/88250/lute v1.7.7-0.20240912031742-019dc0c2f23a/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20240913030339-dd8f3f4ef1fd h1:NeJKjnczuhE6DWjXQe4xDi2LNC+xoEEjZAPDnYj++PQ=
github.com/88250/lute v1.7.7-0.20240913030339-dd8f3f4ef1fd/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=
Expand Down
24 changes: 16 additions & 8 deletions kernel/util/lute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ import (

// MarkdownSettings 运行时 Markdown 配置。
var MarkdownSettings = &Markdown{
InlineSup: true,
InlineSub: true,
InlineTag: true,
InlineMath: true,
InlineAsterisk: true,
InlineUnderscore: true,
InlineSup: true,
InlineSub: true,
InlineTag: true,
InlineMath: true,
}

type Markdown struct {
InlineSup bool `json:"inlineSup"` // 是否启用行级上标
InlineSub bool `json:"inlineSub"` // 是否启用行级下标
InlineTag bool `json:"inlineTag"` // 是否启用行级标签
InlineMath bool `json:"inlineMath"` // 是否启用行级公式
InlineAsterisk bool `json:"inlineAsterisk"` // 是否启用行级 * 语法
InlineUnderscore bool `json:"inlineUnderscore"` // 是否启用行级 _ 语法
InlineSup bool `json:"inlineSup"` // 是否启用行级上标
InlineSub bool `json:"inlineSub"` // 是否启用行级下标
InlineTag bool `json:"inlineTag"` // 是否启用行级标签
InlineMath bool `json:"inlineMath"` // 是否启用行级公式
}

func NewLute() (ret *lute.Lute) {
Expand All @@ -51,6 +55,8 @@ func NewLute() (ret *lute.Lute) {
ret.SetImgPathAllowSpace(true)
ret.SetGitConflict(true)
ret.SetMark(true)
ret.SetInlineAsterisk(MarkdownSettings.InlineAsterisk)
ret.SetInlineUnderscore(MarkdownSettings.InlineUnderscore)
ret.SetSup(MarkdownSettings.InlineSup)
ret.SetSub(MarkdownSettings.InlineSub)
ret.SetTag(MarkdownSettings.InlineTag)
Expand Down Expand Up @@ -84,6 +90,8 @@ func NewStdLute() (ret *lute.Lute) {
ret.SetGFMAutoLink(false) // 导入 Markdown 时不自动转换超链接 https://github.com/siyuan-note/siyuan/issues/7682
ret.SetImgPathAllowSpace(true)
ret.SetInlineMathAllowDigitAfterOpenMarker(true) // Formula parsing supports $ followed by numbers when importing Markdown https://github.com/siyuan-note/siyuan/issues/8362
ret.SetInlineAsterisk(MarkdownSettings.InlineAsterisk)
ret.SetInlineUnderscore(MarkdownSettings.InlineUnderscore)
ret.SetSup(MarkdownSettings.InlineSup)
ret.SetSub(MarkdownSettings.InlineSub)
ret.SetTag(MarkdownSettings.InlineTag)
Expand Down

0 comments on commit f50c0d6

Please sign in to comment.