feat: add setting to disable inline math ($...$) parsing by briannnelson · Pull Request #4231 · marktext/marktext · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/preferences/schema.json
1 change: 1 addition & 0 deletions src/muya/lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export const MUYA_DEFAULT_OPTION = Object.freeze({
// Markdown extensions
superSubScript: false,
footnote: false,
inlineMath: true,
isGitlabCompatibilityEnabled: false,

// Whether HTML rendering is disabled or not.
Expand Down
6 changes: 4 additions & 2 deletions src/muya/lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top, labels, option
const tokens = []
let pending = ''
let pendingStartPos = pos
const { disableHtml, superSubScript, footnote } = options
const { disableHtml, superSubScript, footnote, inlineMath } = options
const pushPending = () => {
if (pending) {
tokens.push({
Expand Down Expand Up @@ -177,7 +177,9 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top, labels, option
if (inChunk) continue

// strong | em | emoji | inline_code | del | inline_math
const chunks = ['inline_code', 'del', 'emoji', 'inline_math']
const chunks = inlineMath !== false
? ['inline_code', 'del', 'emoji', 'inline_math']
: ['inline_code', 'del', 'emoji']
for (const rule of chunks) {
const to = inlineRules[rule].exec(src)
if (to && isLengthEven(to[3])) {
Expand Down
4 changes: 2 additions & 2 deletions src/muya/lib/parser/marked/inlineLexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function InlineLexer(links, footnotes, options) {
InlineLexer.prototype.output = function(src) {
// src = src
// .replace(/\u00a0/g, ' ')
const { disableInline, emoji, math, superSubScript, footnote } = this.options
const { disableInline, emoji, math, inlineMath, superSubScript, footnote } = this.options
if (disableInline) {
return escape(src)
}
Expand Down Expand Up @@ -193,7 +193,7 @@ InlineLexer.prototype.output = function(src) {
}

// math
if (math) {
if (math && inlineMath !== false) {
cap = this.rules.math.exec(src)
if (cap) {
src = src.substring(cap[0].length)
Expand Down
1 change: 1 addition & 0 deletions src/muya/lib/parser/marked/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
// User need to enable them in the user setting.
emoji: true,
math: true,
inlineMath: true,
frontMatter: true,
superSubScript: false,
footnote: false,
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/src/components/editorWithTabs/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const {
frontmatterType,
superSubScript,
footnote,
inlineMath,
isHtmlEnabled,
isGitlabCompatibilityEnabled,
lineHeight,
Expand Down Expand Up @@ -376,6 +377,12 @@ watch(footnote, (value, oldValue) => {
}
})

watch(inlineMath, (value, oldValue) => {
if (value !== oldValue && editor.value) {
editor.value.setOptions({ inlineMath: value }, true)
}
})

watch(isHtmlEnabled, (value, oldValue) => {
if (value !== oldValue && editor.value) {
editor.value.setOptions({ disableHtml: !value }, true)
Expand Down Expand Up @@ -1116,6 +1123,7 @@ onMounted(() => {
frontmatterType: frontmatterType.value,
superSubScript: superSubScript.value,
footnote: footnote.value,
inlineMath: inlineMath.value,
disableHtml: !isHtmlEnabled.value,
isGitlabCompatibilityEnabled: isGitlabCompatibilityEnabled.value,
hideQuickInsertHint: hideQuickInsertHint.value,
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/prefComponents/markdown/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
:on-change="(value) => onSelectChange('footnote', value)"
more="https://pandoc.org/MANUAL.html#footnotes"
/>
<bool
:description="t('preferences.markdown.extensions.inlineMath')"
:bool="inlineMath"
:on-change="(value) => onSelectChange('inlineMath', value)"
/>
</template>
</compound>

Expand Down Expand Up @@ -151,6 +156,7 @@ const {
frontmatterType,
superSubScript,
footnote,
inlineMath,
isHtmlEnabled,
isGitlabCompatibilityEnabled,
sequenceTheme
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/store/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const usePreferencesStore = defineStore('preferences', {
frontmatterType: '-',
superSubScript: false,
footnote: false,
inlineMath: true,
isHtmlEnabled: true,
isGitlabCompatibilityEnabled: false,
sequenceTheme: 'hand',
Expand Down
2 changes: 2 additions & 0 deletions static/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
"frontmatterType": "Der Frontmatter-Typ",
"superSubScript": "Pandocs Markdown-Erweiterung für hoch- und tiefgestellte Zeichen aktivieren",
"footnote": "Pandocs Markdown-Erweiterung für Fußnoten aktivieren",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "HTML-Rendering aktivieren",
"isGitlabCompatibilityEnabled": "GitLab-Kompatibilitätsmodus aktivieren",
"sequenceTheme": "Sequenzdiagramm-Theme",
Expand Down Expand Up @@ -769,6 +770,7 @@
"title": "Erweiterungen",
"superSubScript": "Hoch-/Tiefgestellt",
"footnote": "Fußnote",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML aktiviert",
"isGitlabCompatibilityEnabled": "GitLab-Kompatibilität",
"sequenceTheme": "Sequenz-Design",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
"frontmatterType": "The frontmatter type",
"superSubScript": "Enable pandoc's markdown extension superscript and subscript",
"footnote": "Enable pandoc's markdown extension footnote",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "Enable HTML rendering",
"isGitlabCompatibilityEnabled": "Enable GitLab compatibility mode",
"sequenceTheme": "Sequence diagram theme",
Expand Down Expand Up @@ -768,6 +769,7 @@
"title": "Extensions",
"superSubScript": "Super/Sub script",
"footnote": "Footnote",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML enabled",
"isGitlabCompatibilityEnabled": "GitLab compatibility",
"sequenceTheme": "Sequence theme",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
"frontmatterType": "El tipo de frontmatter",
"superSubScript": "Habilitar extensión markdown de pandoc superíndice y subíndice",
"footnote": "Habilitar extensión markdown de pandoc nota al pie",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "Habilitar renderizado HTML",
"isGitlabCompatibilityEnabled": "Habilitar modo de compatibilidad GitLab",
"sequenceTheme": "Tema del diagrama de secuencia",
Expand Down Expand Up @@ -769,6 +770,7 @@
"title": "Extensiones",
"superSubScript": "Super/Sub script",
"footnote": "Nota al pie",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML habilitado",
"isGitlabCompatibilityEnabled": "Compatibilidad con GitLab",
"sequenceTheme": "Tema de secuencia",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "Le type de frontmatter",
"superSubScript": "Activer l'extension markdown de pandoc pour exposant et indice",
"footnote": "Activer l'extension markdown de pandoc pour note de bas de page",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "Activer le rendu HTML",
"isGitlabCompatibilityEnabled": "Activer le mode de compatibilité GitLab",
"sequenceTheme": "Thème du diagramme de séquence",
Expand Down Expand Up @@ -771,6 +772,7 @@
"title": "Extensions",
"superSubScript": "Exposant/Indice",
"footnote": "Note de bas de page",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML activé",
"isGitlabCompatibilityEnabled": "Compatibilité GitLab",
"sequenceTheme": "Thème de séquence",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "フロントマターのタイプ",
"superSubScript": "Pandocのmarkdown拡張上付き文字と下付き文字を有効にする",
"footnote": "Pandocのmarkdown拡張脚注を有効にする",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "HTMLレンダリングを有効にする",
"isGitlabCompatibilityEnabled": "GitLab互換モードを有効にする",
"sequenceTheme": "シーケンス図のテーマ",
Expand Down Expand Up @@ -771,6 +772,7 @@
"title": "拡張機能",
"superSubScript": "上付き/下付き文字",
"footnote": "脚注",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML有効",
"isGitlabCompatibilityEnabled": "GitLab互換性",
"sequenceTheme": "シーケンステーマ",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "프론트매터 유형",
"superSubScript": "Pandoc의 마크다운 확장 위첨자와 아래첨자 활성화",
"footnote": "Pandoc의 마크다운 확장 각주 활성화",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "HTML 렌더링 활성화",
"isGitlabCompatibilityEnabled": "GitLab 호환 모드 활성화",
"sequenceTheme": "시퀀스 다이어그램 테마",
Expand Down Expand Up @@ -771,6 +772,7 @@
"title": "확장",
"superSubScript": "위/아래 첨자",
"footnote": "각주",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML 활성화",
"isGitlabCompatibilityEnabled": "GitLab 호환성",
"sequenceTheme": "시퀀스 테마",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "O tipo de frontmatter",
"superSubScript": "Habilitar extensão markdown do pandoc para sobrescrito e subscrito",
"footnote": "Habilitar extensão markdown do pandoc para nota de rodapé",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "Habilitar renderização HTML",
"isGitlabCompatibilityEnabled": "Habilitar modo de compatibilidade GitLab",
"sequenceTheme": "Tema do diagrama de sequência",
Expand Down Expand Up @@ -771,6 +772,7 @@
"title": "Extensões",
"superSubScript": "Super/Sub script",
"footnote": "Nota de rodapé",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML habilitado",
"isGitlabCompatibilityEnabled": "Compatibilidade GitLab",
"sequenceTheme": "Tema de sequência",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "前言类型",
"superSubScript": "启用 Pandoc 的 Markdown 扩展上标和下标",
"footnote": "启用 Pandoc 的 Markdown 扩展脚注",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "启用 HTML 渲染",
"isGitlabCompatibilityEnabled": "启用 GitLab 兼容模式",
"sequenceTheme": "序列图主题",
Expand Down Expand Up @@ -770,6 +771,7 @@
"title": "扩展",
"superSubScript": "上标/下标",
"footnote": "脚注",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "启用 HTML",
"isGitlabCompatibilityEnabled": "GitLab 兼容性",
"sequenceTheme": "序列主题",
Expand Down
2 changes: 2 additions & 0 deletions static/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"frontmatterType": "前言類型",
"superSubScript": "啟用 Pandoc 的 Markdown 擴充功能上標和下標",
"footnote": "啟用 Pandoc 的 Markdown 擴充功能腳註",
"inlineMath": "Enable inline math ($...$) parsing",
"isHtmlEnabled": "啟用 HTML 轉譯",
"isGitlabCompatibilityEnabled": "啟用 GitLab 相容模式",
"sequenceTheme": "序列圖主題",
Expand Down Expand Up @@ -771,6 +772,7 @@
"title": "擴充功能",
"superSubScript": "上標/下標",
"footnote": "腳註",
"inlineMath": "Inline math ($...$)",
"isHtmlEnabled": "HTML 已啟用",
"isGitlabCompatibilityEnabled": "GitLab 相容性",
"sequenceTheme": "序列主題",
Expand Down
1 change: 1 addition & 0 deletions static/preference.json
Loading