feat: support GitLab inline diff and multiline blockquote (#954) (#5649) · marktext/marktext@c2a7f59 · GitHub
Skip to content

Commit c2a7f59

Browse files
authored
feat: support GitLab inline diff and multiline blockquote (#954) (#5649)
* feat: support GitLab inline diff and multiline blockquote (#954) Add two off-by-default preferences that read the GitLab Flavored Markdown extensions MarkText was missing, in the editor and in every export path. - `inlineDiff` renders `{+ … +}` / `[+ … +]` additions as `<ins>` and `{- … -}` / `[- … -]` deletions as `<del>`. The opener and closer must match, the body is plain text (no nested markdown), and the span is line-scoped — all matching GitLab's own diff filter. - `multilineBlockquote` reads `>>>` … `>>>` fenced blockquotes. They reuse the existing block-quote block; a `meta.style = 'fenced'` flag only drives markdown serialization so the fence round-trips instead of collapsing to `>`. Typing `>>>` alone on a line and pressing Enter opens one. Editor rules live in muya (inline tokens + a block extension); the HTML / PDF / print and copy-as-HTML paths get matching marked extensions wired through getHighlightHtml, getClipboardHtml, MarkdownToHtml and renderToStaticHTML. Pandoc has no native reader extension for either syntax, so the Pandoc export flags are unchanged. Adds the two preferences to the schema, shipped defaults, Preferences UI, editor option plumbing and all 12 locales, plus the markdown syntax and preferences docs. Verified with engine unit + CommonMark/GFM spec suites. Refs #954 * fix: address inline diff / multiline blockquote review feedback (#954) - A run of `>` with nothing else no longer auto-promotes to a blockquote while `multilineBlockquote` is on, so typing `>>>` reaches the fence instead of being swallowed after the second character. - An empty or whitespace-only diff body (`{++}`, `{+ +}`) stays literal, matching how `**` behaves. - Inline diff delimiters are matched by four explicit regexes, one per valid opener/closer pair, instead of the hand-rolled `tryInlineDiff` bracket check. JS regex has no branch-reset groups, so `{` cannot be back-referenced to `}`; one pattern per pair keeps the pairing in the regex while the shared `tryChunks` pipeline handles the token. - Inline diffs render like GitLab's `.idiff`: a green wash for additions and a red one for deletions (no underline / strikethrough), in the editor and in the exported HTML. The colours are exposed as `--code-new/old-inline-diff-background-color` for themes. - Drop the added comments that only restated the code. Refs #954 * fix: keep `>>>` fences literal while multilineBlockquote is off (#954) Copilot review: enabling the preference on an already-open document could not recognise existing fences. With the option off, Marked had already folded each fence into ordinary nested blockquote state, and re-parsing `getMarkdown()` then emitted spaced `> > >` markers the extension could no longer match. The `multilineBlockquote` extension is now always registered and, while the preference is off, returns a literal paragraph instead of a nested blockquote. That keeps `>>>` verbatim on load, save and export — the same "stays literal while off" behaviour as `==` under `highlightSyntax` — and gives an off → on toggle the fence it needs to rebuild the quote. The marked export path follows the same rule. Only the fence shape (`>>>` alone on a line, closed by `>>>` alone on a line) is affected; `>>> foo` and the other CommonMark blockquote spellings are untouched. Refs #954
1 parent 67ea037 commit c2a7f59

54 files changed

Lines changed: 882 additions & 22 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/desktop/src/main/preferences/schema.json‎

Lines changed: 10 additions & 0 deletions

‎packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ const {
197197
texMathSingleBackslash,
198198
texMathDoubleBackslash,
199199
highlightSyntax,
200+
inlineDiff,
201+
multilineBlockquote,
200202
isHtmlEnabled,
201203
softNewlineAsSpace,
202204
lineHeight,
@@ -608,6 +610,14 @@ watch(highlightSyntax, (value, oldValue) => {
608610
if (value !== oldValue) applyOutlineAffectingOption({ highlightSyntax: value })
609611
})
610612
613+
watch(inlineDiff, (value, oldValue) => {
614+
if (value !== oldValue) applyOutlineAffectingOption({ inlineDiff: value })
615+
})
616+
617+
watch(multilineBlockquote, (value, oldValue) => {
618+
if (value !== oldValue) applyOutlineAffectingOption({ multilineBlockquote: value })
619+
})
620+
611621
watch(softNewlineAsSpace, (value, oldValue) => {
612622
if (value !== oldValue && editor.value) {
613623
editor.value.setOptions({ softNewlineAsSpace: value }, true)
@@ -1778,6 +1788,8 @@ onMounted(() => {
17781788
texMathSingleBackslash: texMathSingleBackslash.value,
17791789
texMathDoubleBackslash: texMathDoubleBackslash.value,
17801790
highlightSyntax: highlightSyntax.value,
1791+
inlineDiff: inlineDiff.value,
1792+
multilineBlockquote: multilineBlockquote.value,
17811793
disableHtml: !isHtmlEnabled.value,
17821794
softNewlineAsSpace: softNewlineAsSpace.value,
17831795
hideQuickInsertHint: hideQuickInsertHint.value,

‎packages/desktop/src/renderer/src/prefComponents/markdown/index.vue‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@
9393
:on-change="(value) => onSelectChange('highlightSyntax', value)"
9494
more="https://www.markdownguide.org/extended-syntax/#highlight"
9595
/>
96+
<bool
97+
:description="t('preferences.markdown.extensions.inlineDiff')"
98+
:bool="inlineDiff"
99+
:on-change="(value) => onSelectChange('inlineDiff', value)"
100+
more="https://docs.gitlab.com/user/markdown/#inline-diff"
101+
/>
102+
<bool
103+
:description="t('preferences.markdown.extensions.multilineBlockquote')"
104+
:bool="multilineBlockquote"
105+
:on-change="(value) => onSelectChange('multilineBlockquote', value)"
106+
more="https://docs.gitlab.com/user/markdown/#multiline-blockquote"
107+
/>
96108
</template>
97109
</compound>
98110

@@ -194,6 +206,8 @@ const {
194206
texMathSingleBackslash,
195207
texMathDoubleBackslash,
196208
highlightSyntax,
209+
inlineDiff,
210+
multilineBlockquote,
197211
isHtmlEnabled,
198212
softNewlineAsSpace,
199213
sequenceTheme,

‎packages/desktop/src/renderer/src/store/preferences.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export interface PreferencesState {
8383
texMathSingleBackslash: boolean
8484
texMathDoubleBackslash: boolean
8585
highlightSyntax: boolean
86+
inlineDiff: boolean
87+
multilineBlockquote: boolean
8688
isHtmlEnabled: boolean
8789
softNewlineAsSpace: boolean
8890
sequenceTheme: SequenceTheme | string
@@ -205,6 +207,8 @@ export const usePreferencesStore = defineStore('preferences', {
205207
texMathSingleBackslash: false,
206208
texMathDoubleBackslash: false,
207209
highlightSyntax: false,
210+
inlineDiff: false,
211+
multilineBlockquote: false,
208212
isHtmlEnabled: true,
209213
softNewlineAsSpace: false,
210214
sequenceTheme: 'hand',

‎packages/desktop/src/shared/types/preferences.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface IUserPreferences {
4848
texMathSingleBackslash?: boolean
4949
texMathDoubleBackslash?: boolean
5050
highlightSyntax?: boolean
51+
inlineDiff?: boolean
52+
multilineBlockquote?: boolean
5153
isHtmlEnabled?: boolean
5254
softNewlineAsSpace?: boolean
5355
theme?: string

‎packages/desktop/static/locales/de.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@
419419
"texMathSingleBackslash": "Pandocs Markdown-Erweiterung tex_math_single_backslash aktivieren",
420420
"texMathDoubleBackslash": "Pandocs Markdown-Erweiterung tex_math_double_backslash aktivieren",
421421
"highlightSyntax": "Die nicht standardmäßige ==text==-Hervorhebungssyntax aktivieren",
422+
"inlineDiff": "Die nicht standardmäßige Inline-Diff-Syntax {+ … +} / [- … -] aktivieren",
423+
"multilineBlockquote": "Die nicht standardmäßige mehrzeilige Zitat-Syntax >>> … >>> aktivieren",
422424
"isHtmlEnabled": "HTML-Rendering aktivieren",
423425
"softNewlineAsSpace": "Weiche Zeilenumbrüche als Leerzeichen behandeln",
424426
"sequenceTheme": "Sequenzdiagramm-Theme",
@@ -648,6 +650,8 @@
648650
"texMathSingleBackslash": "TeX-Mathematik mit einfachem Backslash",
649651
"texMathDoubleBackslash": "TeX-Mathematik mit doppeltem Backslash",
650652
"highlightSyntax": "Hervorhebung (==text==)",
653+
"inlineDiff": "Inline-Diff ({+ … +})",
654+
"multilineBlockquote": "Mehrzeiliges Zitat (>>>)",
651655
"frontmatterType": {
652656
"jsonBrace": "JSON-Klammer",
653657
"jsonSemicolon": "JSON-Semikolon",

‎packages/desktop/static/locales/en.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@
418418
"texMathSingleBackslash": "Enable pandoc's markdown extension tex_math_single_backslash",
419419
"texMathDoubleBackslash": "Enable pandoc's markdown extension tex_math_double_backslash",
420420
"highlightSyntax": "Enable the non-standard ==text== highlight syntax",
421+
"inlineDiff": "Enable the non-standard {+ … +} / [- … -] inline diff syntax",
422+
"multilineBlockquote": "Enable the non-standard >>> … >>> multiline blockquote syntax",
421423
"isHtmlEnabled": "Enable HTML rendering",
422424
"softNewlineAsSpace": "Treat soft newlines as spaces",
423425
"sequenceTheme": "Sequence diagram theme",
@@ -648,6 +650,8 @@
648650
"texMathSingleBackslash": "TeX math with single-backslash delimiters",
649651
"texMathDoubleBackslash": "TeX math with double-backslash delimiters",
650652
"highlightSyntax": "Highlight (==text==)",
653+
"inlineDiff": "Inline diff ({+ … +})",
654+
"multilineBlockquote": "Multiline blockquote (>>>)",
651655
"frontmatterType": {
652656
"jsonBrace": "JSON with Braces",
653657
"jsonSemicolon": "JSON with Semicolon",

‎packages/desktop/static/locales/es.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@
419419
"texMathSingleBackslash": "Activar la extensión de markdown de pandoc tex_math_single_backslash",
420420
"texMathDoubleBackslash": "Activar la extensión de markdown de pandoc tex_math_double_backslash",
421421
"highlightSyntax": "Habilitar la sintaxis de resaltado no estándar ==texto==",
422+
"inlineDiff": "Habilitar la sintaxis de diff en línea no estándar {+ … +} / [- … -]",
423+
"multilineBlockquote": "Habilitar la sintaxis de cita de varias líneas no estándar >>> … >>>",
422424
"isHtmlEnabled": "Habilitar renderizado HTML",
423425
"softNewlineAsSpace": "Tratar los saltos de línea suaves como espacios",
424426
"sequenceTheme": "Tema del diagrama de secuencia",
@@ -648,6 +650,8 @@
648650
"texMathSingleBackslash": "Matemáticas TeX con barra invertida simple",
649651
"texMathDoubleBackslash": "Matemáticas TeX con barra invertida doble",
650652
"highlightSyntax": "Resaltado (==texto==)",
653+
"inlineDiff": "Diff en línea ({+ … +})",
654+
"multilineBlockquote": "Cita de varias líneas (>>>)",
651655
"frontmatterType": {
652656
"jsonBrace": "JSON con Llaves",
653657
"jsonSemicolon": "JSON con Punto y Coma",

‎packages/desktop/static/locales/fr.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@
419419
"texMathSingleBackslash": "Activer l'extension markdown de pandoc tex_math_single_backslash",
420420
"texMathDoubleBackslash": "Activer l'extension markdown de pandoc tex_math_double_backslash",
421421
"highlightSyntax": "Activer la syntaxe de surlignage non standard ==texte==",
422+
"inlineDiff": "Activer la syntaxe de diff en ligne non standard {+ … +} / [- … -]",
423+
"multilineBlockquote": "Activer la syntaxe de citation multiligne non standard >>> … >>>",
422424
"isHtmlEnabled": "Activer le rendu HTML",
423425
"softNewlineAsSpace": "Traiter les sauts de ligne simples comme des espaces",
424426
"sequenceTheme": "Thème du diagramme de séquence",
@@ -648,6 +650,8 @@
648650
"texMathSingleBackslash": "Maths TeX avec barre oblique inverse simple",
649651
"texMathDoubleBackslash": "Maths TeX avec barre oblique inverse double",
650652
"highlightSyntax": "Surlignage (==texte==)",
653+
"inlineDiff": "Diff en ligne ({+ … +})",
654+
"multilineBlockquote": "Citation multiligne (>>>)",
651655
"frontmatterType": {
652656
"jsonBrace": "Accolade JSON",
653657
"jsonSemicolon": "Point-virgule JSON",

‎packages/desktop/static/locales/ja.json‎

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)