Skip to content

fix: highlight backtick spans that start at the beginning of a line#17

Merged
dpecos merged 1 commit into
masterfrom
fix/issue-2-highlight-spans-line-start
Apr 16, 2026
Merged

fix: highlight backtick spans that start at the beginning of a line#17
dpecos merged 1 commit into
masterfrom
fix/issue-2-highlight-spans-line-start

Conversation

@dpecos
Copy link
Copy Markdown
Contributor

@dpecos dpecos commented Apr 16, 2026

Summary

  • Fixes the highlightSpans regex in slideView.ts so that backtick spans at the start of a line (or the start of the HTML string) are matched and highlighted correctly
  • Applies the same fix to the custom RegExp path
  • Adds a new test file highlightSpans.test.ts with 6 cases covering the bug scenario and surrounding edge cases

Root cause

// before — requires a non-backtick character before the opening backtick
pattern = /([^`])`([^`]+?)`/g;

// after — also allows start-of-line as the "preceding context"
pattern = /(^|[^`])`([^`]+?)`/gm;

The original ([^\])` group consumed exactly one character, so a span whose opening backtick was the first character on a line (or the first character in the string) never matched.

Fix

Changed the leading group to (^|[^\])and added them(multiline) flag so^matches the start of every line, not just the start of the full string. The replacement callback already handlese` being an empty string correctly — it simply prepends nothing.

Closes #2

The highlightSpans pattern required a non-backtick character immediately
before the opening backtick, so spans at the start of a line (or the
start of a string) were never matched and rendered as plain text.

Changed the leading capture group from ([^`]) to (^|[^`]) with the
/m flag so that the start-of-line anchor is a valid alternative to a
preceding character. Applied the same fix to the custom RegExp path.

Closes #2
@dpecos dpecos merged commit 3cb9e5b into master Apr 16, 2026
4 checks passed
@dpecos dpecos deleted the fix/issue-2-highlight-spans-line-start branch April 16, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: highlightSpans fails when backtick is the first character on a line

1 participant