Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformerMetaWordHighlight fail to highlight overlapping text instances #908

Open
4 of 5 tasks
artt opened this issue Jan 27, 2025 · 1 comment · May be fixed by #909
Open
4 of 5 tasks

transformerMetaWordHighlight fail to highlight overlapping text instances #908

artt opened this issue Jan 27, 2025 · 1 comment · May be fixed by #909

Comments

@artt
Copy link

artt commented Jan 27, 2025

Validations

Describe the bug

When using transformerMetaWordHighlight to highlight words that overlap, Shiki fails.

Example:

```js /xx/
xxx
``` .

Shiki will try to create two spans with class highlighted-word: (xx)x and x(xx) and will result in the following error:

Failed to parse Markdown file "...":
Decorations {"line":0,"character":0,"offset":0} and {"line":0,"character":1,"offset":1} intersect.

Perhaps a way to fix is to allow highlighting words by character position?

On a related note, why the use of /.../ that resembles regex?

Reproduction

https://stackblitz.com/edit/shiki-intersect?file=src%2Fpages%2Findex.astro,astro.config.mjs,src%2Fcomponents%2Ftest.md

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests
@artt
Copy link
Author

artt commented Jan 27, 2025

Perhaps instead of doing this:

const indexes = findAllSubstringIndexes(code, word)

it would be easier to just use regex to get the match indices?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant