Skip to content
Merged
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
18 changes: 16 additions & 2 deletions lexilla/lexers/LexMarkdown.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************
/******************************************************************
* LexMarkdown.cxx
*
* A simple Markdown lexer for scintilla.
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion lexilla/np3_patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

---

Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
```

---
Expand Down
39 changes: 38 additions & 1 deletion test/test_files/StyleLexers/styleLexMARKDOWN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[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.
Loading