From a9fb75120270e2a46a5988375bb12540a49884d0 Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Thu, 21 May 2026 09:48:04 +0200 Subject: [PATCH] fix: Markdown lexer --- lexilla/lexers/LexMarkdown.cxx | 18 ++++++++- lexilla/np3_patches/README.md | 21 +++++++++- .../StyleLexers/styleLexMARKDOWN/README.md | 39 ++++++++++++++++++- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/lexilla/lexers/LexMarkdown.cxx b/lexilla/lexers/LexMarkdown.cxx index 667b3b5345..8cbffec222 100644 --- a/lexilla/lexers/LexMarkdown.cxx +++ b/lexilla/lexers/LexMarkdown.cxx @@ -1,4 +1,4 @@ -/****************************************************************** + /****************************************************************** * LexMarkdown.cxx * * A simple Markdown lexer for scintilla. @@ -119,7 +119,21 @@ bool HasPrevLineContent(StyleContext &sc) { } bool AtTermStart(const StyleContext &sc) noexcept { - return sc.currentPos == 0 || sc.chPrev == 0 || isspacechar(sc.chPrev); + if (sc.currentPos == 0 || sc.chPrev == 0 || isspacechar(sc.chPrev)) + return true; + // NP3 patch: also accept common opening punctuation so inline spans + // (code, strong, emphasis, strikeout) can open directly after them, + // e.g. (`x`), [`x`], {`x`}, <`x`>, "`x`", '`x`'. CommonMark and VS + // Code accept these — code spans have no left-flank restriction at + // all, and emphasis after opening punctuation is a valid + // left-flanking delimiter run. + switch (sc.chPrev) { + case '(': case '[': case '{': case '<': + case '"': case '\'': + return true; + default: + return false; + } } bool IsCompleteStyleRegion(StyleContext &sc, const char *token) { diff --git a/lexilla/np3_patches/README.md b/lexilla/np3_patches/README.md index 7d074e39c4..7a0713ec68 100644 --- a/lexilla/np3_patches/README.md +++ b/lexilla/np3_patches/README.md @@ -8,6 +8,7 @@ This directory contains documentation of all modifications made to the upstream |----|------------|-------------|-------------|----------| | 001 | `001_StyleContext_MatchNext.patch` | `lexlib/StyleContext.h` | Adds `MatchNext()` and `Match(char,char,char)` overloads | ✅ Yes | | 002 | `002_Lexilla_CustomCatalogue.patch` | `src/Lexilla.cxx` | Custom lexer catalogue (NP3 subset only) | ✅ Yes | +| 003 | `003_LexMarkdown_AtTermStart.patch` | `lexers/LexMarkdown.cxx` | `AtTermStart` accepts opening punctuation `( [ { < " '` so `` (`x`) `` highlights as code | ✅ Yes | --- @@ -36,6 +37,22 @@ bool MatchNext(char ch0, char ch1, char ch2) const noexcept; --- +### 003: LexMarkdown `AtTermStart` accepts opening punctuation + +**File:** `lexers/LexMarkdown.cxx` +**Status:** Local fix; candidate for upstream submission. See +`003_LexMarkdown_AtTermStart.md` for the full write-up. + +Stock Lexilla only opens inline spans (code, strong, emphasis, +strikeout) when the preceding character is whitespace, so +`` (`Hello`) `` is rendered as plain text. The patch extends +`AtTermStart` to additionally accept `(`, `[`, `{`, `<`, `"`, `'`. + +Visual smoke-test: open +`test/test_files/StyleLexers/styleLexMARKDOWN/README.md` after build. + +--- + ### 002: Custom Lexer Catalogue **File:** `src/Lexilla.cxx` @@ -69,7 +86,9 @@ When upgrading Lexilla to a new version: lexilla/np3_patches/ ├── README.md # This file ├── 001_StyleContext_MatchNext.patch # StyleContext extensions -└── 002_Lexilla_CustomCatalogue.patch # Custom lexer catalogue diff +├── 002_Lexilla_CustomCatalogue.patch # Custom lexer catalogue diff +├── 003_LexMarkdown_AtTermStart.patch # Markdown: open inline spans after ( [ { < " ' +└── 003_LexMarkdown_AtTermStart.md # Patch 003 write-up ``` --- diff --git a/test/test_files/StyleLexers/styleLexMARKDOWN/README.md b/test/test_files/StyleLexers/styleLexMARKDOWN/README.md index 0895040e24..d4a44ba43f 100644 --- a/test/test_files/StyleLexers/styleLexMARKDOWN/README.md +++ b/test/test_files/StyleLexers/styleLexMARKDOWN/README.md @@ -87,4 +87,41 @@ During development time the strings in the code are presented to the user. If th break existing clients using TypeScript 1.8.x. ## LICENSE -[MIT](LICENSE) \ No newline at end of file +[MIT](LICENSE) + +## NP3 Patch 003 — inline spans adjacent to opening punctuation + +These lines exercise `AtTermStart` accepting `( [ { < " '`. Every +backtick/asterisk/underscore/tilde region below MUST render in its +inline-span style (code / strong / em / strikeout), not as plain text. + +Inline code immediately after openers: + +- parenthesis: (`Hello`) and (`x` + `y`) +- square brackets: [`Hello`] +- curly braces: {`Hello`} +- angle brackets: <`Hello`> +- double quote: "`Hello`" +- single quote: '`Hello`' + +Multi-backtick code spans (uses `AtTermStart` directly): + +- (``a `b` c``) and [``a `b` c``] + +Strong, emphasis, strikeout after the same openers: + +- (**bold**) [**bold**] {**bold**} <**bold**> "**bold**" '**bold**' +- (__bold__) [__bold__] {__bold__} +- (*em*) [*em*] {*em*} <*em*> "*em*" '*em*' +- (_em_) [_em_] {_em_} +- (~~struck~~) [~~struck~~] {~~struck~~} + +Regression checks — these should still NOT be styled as inline spans +(word-adjacent delimiters are intentionally rejected): + +- foo`bar`baz (no code span — `chPrev='o'`) +- foo*bar*baz (no emphasis — `chPrev='o'`) + +Whitespace-adjacent baseline (must still work): + +- a `code` span, a **strong** span, an *em* span, a ~~struck~~ span. \ No newline at end of file