diff --git a/src/index.ts b/src/index.ts index adcf4fb..0667d6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -349,17 +349,23 @@ export default function rehypePrettyCode( const charsListNumbers: Array = []; const charsListIdMap = new Map(); const charsMatches = meta - ? [...meta.matchAll(/\/(.*?)\/(\S*)/g)] + ? [ + ...meta.matchAll( + /(?["/])(?.*?)\k(?\S*)/g, + ), + ] : undefined; if (Array.isArray(charsMatches)) { - charsMatches.forEach((_, index) => { - const word = charsMatches[index][1]; - const charsIdOrRange = charsMatches[index][2]; - const [range, id] = charsIdOrRange.split('#'); - charsList.push(word); + charsMatches.forEach((name) => { + const { chars, charsIdAndOrRange } = name.groups as { + chars: string; + charsIdAndOrRange: string; + }; + const [range, id] = charsIdAndOrRange.split('#'); + charsList.push(chars); range && charsListNumbers.push(rangeParser(range)); - id && charsListIdMap.set(word, id); + id && charsListIdMap.set(chars, id); }); } diff --git a/test/fixtures/highlightChars.md b/test/fixtures/highlightChars.md index 5e1043e..20ecaf2 100644 --- a/test/fixtures/highlightChars.md +++ b/test/fixtures/highlightChars.md @@ -7,3 +7,9 @@ function carrot() { return 'carrot'; } ``` + +"path/to/carrot" + +```js "path/to/carrot" +const path = 'path/to/carrot'; +``` diff --git a/test/results/highlightChars.html b/test/results/highlightChars.html index 7d1e7df..cc83f12 100644 --- a/test/results/highlightChars.html +++ b/test/results/highlightChars.html @@ -63,3 +63,12 @@

Highlight chars

return 'carrot'; } +

"path/to/carrot"

+
+
const path = 'path/to/carrot';
+