diff --git a/src/index.ts b/src/index.ts index f024bc0..a234e84 100644 --- a/src/index.ts +++ b/src/index.ts @@ -383,10 +383,14 @@ export default function rehypePrettyCode( chars: string; charsIdAndOrRange: string; }; - const [range, id] = charsIdAndOrRange.split('#'); charsList.push(chars); - range && charsListNumbers.push(rangeParser(range)); - id && charsListIdMap.set(chars, id); + if (charsIdAndOrRange === '') { + charsListNumbers.push([]); + } else { + const [range, id] = charsIdAndOrRange.split('#'); + range && charsListNumbers.push(rangeParser(range)); + id && charsListIdMap.set(chars, id); + } }); } diff --git a/test/fixtures/highlightedMultipleCharsRange.md b/test/fixtures/highlightedMultipleCharsRange.md index aa69644..8fe566d 100644 --- a/test/fixtures/highlightedMultipleCharsRange.md +++ b/test/fixtures/highlightedMultipleCharsRange.md @@ -9,3 +9,33 @@ const strLen = getStringLength('str'); const anotherStrLen = getStringLength('anotherStr'); ``` + +/getStringLength/ /str/2,3 + +```js /getStringLength/ /str/2,3 +const getStringLength = (str) => str.length; + +const strLen = getStringLength('str'); + +const anotherStrLen = getStringLength('anotherStr'); +``` + +/getStringLength/2 /str/ + +```js /getStringLength/2 /str/ +const getStringLength = (str) => str.length; + +const strLen = getStringLength('str'); + +const anotherStrLen = getStringLength('anotherStr'); +``` + +/Length/1 /str/ /const/2-3 /get/ + +```js /Length/1 /str/ /const/2-3 /get/ +const getStringLength = (str) => str.length; + +const strLen = getStringLength('str'); + +const anotherStrLen = getStringLength('anotherStr'); +``` \ No newline at end of file diff --git a/test/results/highlightedMultipleCharsRange.html b/test/results/highlightedMultipleCharsRange.html index 5089122..e527ad0 100644 --- a/test/results/highlightedMultipleCharsRange.html +++ b/test/results/highlightedMultipleCharsRange.html @@ -65,3 +65,42 @@

Highlight multiple chars range

const anotherStrLen = getStringLength('anotherStr'); +

/getStringLength/ /str/2,3

+
+
const getStringLength = (str) => str.length;
+ 
+const strLen = getStringLength('str');
+ 
+const anotherStrLen = getStringLength('anotherStr');
+
+

/getStringLength/2 /str/

+
+
const getStringLength = (str) => str.length;
+ 
+const strLen = getStringLength('str');
+ 
+const anotherStrLen = getStringLength('anotherStr');
+
+

/Length/1 /str/ /const/2-3 /get/

+
+
const getStringLength = (str) => str.length;
+ 
+const strLen = getStringLength('str');
+ 
+const anotherStrLen = getStringLength('anotherStr');
+