fix: highlight backtick spans that start at the beginning of a line#17
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
highlightSpansregex inslideView.tsso that backtick spans at the start of a line (or the start of the HTML string) are matched and highlighted correctlyRegExppathhighlightSpans.test.tswith 6 cases covering the bug scenario and surrounding edge casesRoot cause
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