rehype-highlight-code-lines 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -4
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +42 -36
- package/dist/esm/index.js.map +1 -1
- package/package.json +10 -5
- package/src/index.ts +60 -50
package/README.md
CHANGED
|
@@ -140,6 +140,8 @@ All options are **optional** and have **default values**.
|
|
|
140
140
|
```typescript
|
|
141
141
|
type HighlightLinesOptions = {
|
|
142
142
|
showLineNumbers?: boolean; // default is "false"
|
|
143
|
+
lineContainerTagName?: "span" | "div"; // deprecated, always span
|
|
144
|
+
trimBlankLines?: boolean; // default is "false"
|
|
143
145
|
};
|
|
144
146
|
|
|
145
147
|
use(rehypeHighlightLines, HighlightLinesOptions);
|
|
@@ -173,20 +175,53 @@ Sometimes you may want to start the line numbering from a specific number. In th
|
|
|
173
175
|
|
|
174
176
|
**\`\`\`showLineNumbers=8**
|
|
175
177
|
|
|
176
|
-
#### `lineContainerTagName`
|
|
178
|
+
#### `lineContainerTagName` (Deprecated)
|
|
177
179
|
|
|
178
|
-
**It is
|
|
180
|
+
**It is marked as `@deprecated` and will be removed in the next versions.
|
|
179
181
|
|
|
180
|
-
It was a **union**
|
|
182
|
+
It was a **union** option which was **"div" | "span"** for providing custom HTML tag name for code lines.
|
|
181
183
|
|
|
182
184
|
By default, it is `span` which is **inline** level container. If you set it as `div`, the container will still be `span` after deprecation.
|
|
183
185
|
|
|
184
186
|
```javascript
|
|
185
187
|
use(rehypeHighlightLines, {
|
|
186
|
-
lineContainerTagName: "div", // @deprecated, always "span"
|
|
188
|
+
lineContainerTagName: "div", // @deprecated, effectless, always "span"
|
|
187
189
|
});
|
|
188
190
|
```
|
|
189
191
|
|
|
192
|
+
#### `trimBlankLines`
|
|
193
|
+
|
|
194
|
+
It is a **boolean** option. It is designed to delete one blank/empty line at the beginning and one at the end of the code block, if happened due to html parsing `<pre><code /></pre>`.
|
|
195
|
+
|
|
196
|
+
By default, it is `false`.
|
|
197
|
+
|
|
198
|
+
Let's assume you want to highlight `pre`, and `code` element in markdown (not code fence).
|
|
199
|
+
|
|
200
|
+
```markdown
|
|
201
|
+
Here is markdown content
|
|
202
|
+
|
|
203
|
+
<pre><code class="language-javascript">
|
|
204
|
+
console.log("rehype-highlight-code-lines");
|
|
205
|
+
</code></pre>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
For above markdown, the parsed result (for example via `rehype-parse` and `rehype-stringfy`) is going to contain empty/blank code lines due to nature of `pre` preserving whitespaces. In order to prevent having unintentionally blank lines, use the option `trimBlankLines`.
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
use(rehypeHighlightLines, {
|
|
212
|
+
trimBlankLines: true,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Actually, the trimming could have been the default behaviour. However, some developers may intentionally include empty lines at the beginning and at the end in code fences for specific reasons and may want to preserve them.
|
|
217
|
+
````markdown
|
|
218
|
+
```javascript
|
|
219
|
+
|
|
220
|
+
console.log("rehype-highlight-code-lines");
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
````
|
|
224
|
+
|
|
190
225
|
### Examples:
|
|
191
226
|
|
|
192
227
|
```typescript
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import rangeParser from "parse-numeric-range";
|
|
|
3
3
|
const DEFAULT_SETTINGS = {
|
|
4
4
|
showLineNumbers: false,
|
|
5
5
|
lineContainerTagName: "span",
|
|
6
|
+
trimBlankLines: false,
|
|
6
7
|
};
|
|
7
8
|
// a simple util for our use case, like clsx package
|
|
8
9
|
export function clsx(arr) {
|
|
@@ -25,7 +26,7 @@ function hasClassName(node, className) {
|
|
|
25
26
|
}
|
|
26
27
|
// match all common types of line breaks
|
|
27
28
|
const REGEX_LINE_BREAKS = /\r?\n|\r/g;
|
|
28
|
-
const REGEX_LINE_BREAKS_IN_THE_BEGINNING = /^(\r?\n|\r)
|
|
29
|
+
const REGEX_LINE_BREAKS_IN_THE_BEGINNING = /^(\r?\n|\r)+/;
|
|
29
30
|
/**
|
|
30
31
|
*
|
|
31
32
|
* add line numbers to code blocks and allow highlighting of desired code lines
|
|
@@ -149,31 +150,32 @@ const plugin = (options) => {
|
|
|
149
150
|
*
|
|
150
151
|
*/
|
|
151
152
|
function handleFirstElementContent(code) {
|
|
152
|
-
const replacement = [];
|
|
153
153
|
const elementNode = code.children[0];
|
|
154
154
|
if (!isElementWithTextNode(elementNode))
|
|
155
155
|
return;
|
|
156
156
|
const textNode = elementNode.children[0];
|
|
157
157
|
if (!REGEX_LINE_BREAKS_IN_THE_BEGINNING.test(textNode.value))
|
|
158
158
|
return;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
textNode.value = textNode.value.slice(1);
|
|
164
|
-
// iterate the match
|
|
165
|
-
match = REGEX_LINE_BREAKS_IN_THE_BEGINNING.exec(textNode.value);
|
|
159
|
+
const match = REGEX_LINE_BREAKS_IN_THE_BEGINNING.exec(textNode.value);
|
|
160
|
+
if (match) {
|
|
161
|
+
code.children.unshift({ type: "text", value: match[0] });
|
|
162
|
+
textNode.value = textNode.value.replace(REGEX_LINE_BREAKS_IN_THE_BEGINNING, "");
|
|
166
163
|
}
|
|
167
|
-
code.children.unshift(...replacement);
|
|
168
164
|
}
|
|
169
165
|
/**
|
|
170
166
|
*
|
|
171
|
-
*
|
|
167
|
+
* handle trimming blank line for the last text node
|
|
172
168
|
*
|
|
173
169
|
*/
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
|
|
170
|
+
function handleTrimmingBlankLines(code, directiveTrimBlankLines) {
|
|
171
|
+
if (!directiveTrimBlankLines)
|
|
172
|
+
return;
|
|
173
|
+
const lastChild = code.children[code.children.length - 1];
|
|
174
|
+
if (lastChild.type === "text") {
|
|
175
|
+
if (/(\r?\n|\r)(\1)$/.test(lastChild.value)) {
|
|
176
|
+
lastChild.value = lastChild.value.replace(/(\r?\n|\r)(\1)$/, "$1");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
177
179
|
}
|
|
178
180
|
/**
|
|
179
181
|
*
|
|
@@ -181,26 +183,23 @@ const plugin = (options) => {
|
|
|
181
183
|
* mutates the code
|
|
182
184
|
*
|
|
183
185
|
*/
|
|
184
|
-
function gutter(code, { directiveShowLineNumbers, directiveHighlightLines, }) {
|
|
186
|
+
function gutter(code, { directiveShowLineNumbers, directiveHighlightLines, directiveTrimBlankLines, }) {
|
|
185
187
|
hasFlatteningNeed(code) && flattenCodeTree(code); // mutates the code
|
|
186
188
|
handleMultiLineComments(code); // mutates the code
|
|
187
189
|
handleFirstElementContent(code); // mutates the code
|
|
190
|
+
handleTrimmingBlankLines(code, directiveTrimBlankLines);
|
|
188
191
|
const replacement = [];
|
|
189
192
|
let start = 0;
|
|
190
193
|
let startTextRemainder = "";
|
|
191
194
|
let lineNumber = 0;
|
|
192
195
|
for (let index = 0; index < code.children.length; index++) {
|
|
193
196
|
const child = code.children[index];
|
|
194
|
-
// if (index === 0 && /^[\n][\s]*$/.test(child.value)) {
|
|
195
|
-
// console.log(child.value, index);
|
|
196
|
-
// }
|
|
197
197
|
if (child.type !== "text")
|
|
198
198
|
continue;
|
|
199
199
|
let textStart = 0;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// Nodes in this line. (current child is exclusive)
|
|
203
|
-
// Array.prototype.slice() start to end (end not included)
|
|
200
|
+
const matches = Array.from(child.value.matchAll(REGEX_LINE_BREAKS));
|
|
201
|
+
matches.forEach((match, iteration) => {
|
|
202
|
+
// Nodes in this line. (current child (index) is exclusive)
|
|
204
203
|
const line = code.children.slice(start, index);
|
|
205
204
|
// Prepend text from a partial matched earlier text.
|
|
206
205
|
if (startTextRemainder) {
|
|
@@ -212,13 +211,17 @@ const plugin = (options) => {
|
|
|
212
211
|
const value = child.value.slice(textStart, match.index);
|
|
213
212
|
line.push({ type: "text", value });
|
|
214
213
|
}
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
const isFirstIteration = index === 0 && iteration === 0;
|
|
215
|
+
if (isFirstIteration && directiveTrimBlankLines && line.length === 0) {
|
|
216
|
+
replacement.push({ type: "text", value: match[0] }); // eol
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
lineNumber += 1;
|
|
220
|
+
replacement.push(createLine(line, lineNumber, directiveShowLineNumbers, directiveHighlightLines), { type: "text", value: match[0] });
|
|
221
|
+
}
|
|
217
222
|
start = index + 1;
|
|
218
223
|
textStart = match.index + match[0].length;
|
|
219
|
-
|
|
220
|
-
match = REGEX_LINE_BREAKS.exec(child.value);
|
|
221
|
-
}
|
|
224
|
+
});
|
|
222
225
|
// If we matched, make sure to not drop the text after the last line ending.
|
|
223
226
|
if (start === index + 1) {
|
|
224
227
|
startTextRemainder = child.value.slice(textStart);
|
|
@@ -231,13 +234,9 @@ const plugin = (options) => {
|
|
|
231
234
|
startTextRemainder = "";
|
|
232
235
|
}
|
|
233
236
|
if (line.length > 0) {
|
|
234
|
-
|
|
235
|
-
replacement.push(...line)
|
|
236
|
-
|
|
237
|
-
else {
|
|
238
|
-
lineNumber += 1;
|
|
239
|
-
replacement.push(createLine(line, lineNumber, directiveShowLineNumbers, directiveHighlightLines));
|
|
240
|
-
}
|
|
237
|
+
directiveTrimBlankLines
|
|
238
|
+
? replacement.push(...line)
|
|
239
|
+
: replacement.push(createLine(line, ++lineNumber, directiveShowLineNumbers, directiveHighlightLines));
|
|
241
240
|
}
|
|
242
241
|
// Replace children with new array.
|
|
243
242
|
code.children = replacement;
|
|
@@ -285,7 +284,8 @@ const plugin = (options) => {
|
|
|
285
284
|
const language = getLanguage(classNames);
|
|
286
285
|
if (language?.startsWith("{") ||
|
|
287
286
|
language?.startsWith("showlinenumbers") ||
|
|
288
|
-
language?.startsWith("nolinenumbers")
|
|
287
|
+
language?.startsWith("nolinenumbers") ||
|
|
288
|
+
language?.startsWith("trimblanklines")) {
|
|
289
289
|
// add specifiers to meta
|
|
290
290
|
meta = (language + " " + meta).trim();
|
|
291
291
|
// correct the code's meta
|
|
@@ -305,14 +305,20 @@ const plugin = (options) => {
|
|
|
305
305
|
const REGEX2 = /{(?<lines>[\d\s,-]+)}/g;
|
|
306
306
|
const strLineNumbers = REGEX2.exec(meta)?.groups?.lines?.replace(/\s/g, "");
|
|
307
307
|
const directiveHighlightLines = strLineNumbers ? rangeParser(strLineNumbers) : [];
|
|
308
|
+
// find the directive for trimming blank lines
|
|
309
|
+
const REGEX3 = /trimblanklines/i;
|
|
310
|
+
const directiveTrimBlankLines = settings.trimBlankLines || REGEX3.test(meta);
|
|
308
311
|
// if nothing to do for numbering, highlihting or trimming blank lines, just return;
|
|
309
|
-
if (directiveShowLineNumbers === false &&
|
|
312
|
+
if (directiveShowLineNumbers === false &&
|
|
313
|
+
directiveHighlightLines.length === 0 &&
|
|
314
|
+
directiveTrimBlankLines === false) {
|
|
310
315
|
return;
|
|
311
316
|
}
|
|
312
317
|
// add container for each line mutating the code element
|
|
313
318
|
gutter(code, {
|
|
314
319
|
directiveShowLineNumbers,
|
|
315
320
|
directiveHighlightLines,
|
|
321
|
+
directiveTrimBlankLines,
|
|
316
322
|
});
|
|
317
323
|
});
|
|
318
324
|
};
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAsB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAyB9C,MAAM,gBAAgB,GAA0B;IAC9C,eAAe,EAAE,KAAK;IACtB,oBAAoB,EAAE,MAAM;CAC7B,CAAC;AAMF,oDAAoD;AACpD,MAAM,UAAU,IAAI,CAAC,GAA8C;IACjE,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,CAAC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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE7E,oFAAoF;YACpF,IACE,wBAAwB,KAAK,KAAK;gBAClC,uBAAuB,CAAC,MAAM,KAAK,CAAC;gBACpC,uBAAuB,KAAK,KAAK,EACjC,CAAC;gBACD,OAAO;YACT,CAAC;YAED,wDAAwD;YACxD,MAAM,CAAC,IAAI,EAAE;gBACX,wBAAwB;gBACxB,uBAAuB;gBACvB,uBAAuB;aACxB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rehype-highlight-code-lines",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Rehype plugin to add line numbers to code blocks and allow highlighting of desired code lines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/esm/index.js",
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
"lint": "eslint .",
|
|
14
14
|
"test": "vitest --watch=false",
|
|
15
15
|
"test:watch": "vitest",
|
|
16
|
-
"test:file1": "vitest test.
|
|
17
|
-
"test:file2": "vitest test.
|
|
16
|
+
"test:file1": "vitest test.md.spec.ts",
|
|
17
|
+
"test:file2": "vitest test.html.spec.ts",
|
|
18
|
+
"test:file3": "vitest test.cases.spec.ts",
|
|
19
|
+
"test:file4": "vitest from-rehype-highlight/test.rhcl2.spec.ts",
|
|
18
20
|
"prepack": "npm run build",
|
|
19
21
|
"prepublishOnly": "npm run test && npm run format && npm run test-coverage",
|
|
20
22
|
"test-coverage": "vitest run --coverage"
|
|
@@ -75,14 +77,17 @@
|
|
|
75
77
|
"typescript-eslint": "^8.23.0",
|
|
76
78
|
"unist-util-remove-position": "^5.0.0",
|
|
77
79
|
"vfile": "^6.0.3",
|
|
78
|
-
"vitest": "^3.0.5"
|
|
80
|
+
"vitest": "^3.0.5",
|
|
81
|
+
"unified": "^11.0.5"
|
|
79
82
|
},
|
|
80
83
|
"dependencies": {
|
|
81
84
|
"@types/hast": "^3.0.4",
|
|
82
85
|
"parse-numeric-range": "^1.3.0",
|
|
83
|
-
"unified": "^11.0.5",
|
|
84
86
|
"unist-util-visit": "^5.0.0"
|
|
85
87
|
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"unified": "^11"
|
|
90
|
+
},
|
|
86
91
|
"typeCoverage": {
|
|
87
92
|
"atLeast": 100,
|
|
88
93
|
"detail": true,
|
package/src/index.ts
CHANGED
|
@@ -24,17 +24,25 @@ export type HighlightLinesOptions = {
|
|
|
24
24
|
* will be removed in the next versions
|
|
25
25
|
*/
|
|
26
26
|
lineContainerTagName?: "div" | "span";
|
|
27
|
+
trimBlankLines?: boolean;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
const DEFAULT_SETTINGS: HighlightLinesOptions = {
|
|
30
31
|
showLineNumbers: false,
|
|
31
32
|
lineContainerTagName: "span",
|
|
33
|
+
trimBlankLines: false,
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
type PartiallyRequiredHighlightLinesOptions = Prettify<
|
|
35
37
|
PartiallyRequired<HighlightLinesOptions, "showLineNumbers" | "lineContainerTagName">
|
|
36
38
|
>;
|
|
37
39
|
|
|
40
|
+
type GutterOptions = {
|
|
41
|
+
directiveShowLineNumbers: boolean | number;
|
|
42
|
+
directiveHighlightLines: number[];
|
|
43
|
+
directiveTrimBlankLines: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
38
46
|
// a simple util for our use case, like clsx package
|
|
39
47
|
export function clsx(arr: (string | false | null | undefined | 0)[]): string[] {
|
|
40
48
|
return arr.filter((item): item is string => !!item);
|
|
@@ -65,7 +73,7 @@ function hasClassName(node: ElementContent | undefined, className: string): bool
|
|
|
65
73
|
|
|
66
74
|
// match all common types of line breaks
|
|
67
75
|
const REGEX_LINE_BREAKS = /\r?\n|\r/g;
|
|
68
|
-
const REGEX_LINE_BREAKS_IN_THE_BEGINNING = /^(\r?\n|\r)
|
|
76
|
+
const REGEX_LINE_BREAKS_IN_THE_BEGINNING = /^(\r?\n|\r)+/;
|
|
69
77
|
|
|
70
78
|
/**
|
|
71
79
|
*
|
|
@@ -213,39 +221,36 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
213
221
|
*
|
|
214
222
|
*/
|
|
215
223
|
function handleFirstElementContent(code: Element): undefined {
|
|
216
|
-
const replacement: ElementContent[] = [];
|
|
217
|
-
|
|
218
224
|
const elementNode = code.children[0];
|
|
219
225
|
if (!isElementWithTextNode(elementNode)) return;
|
|
220
226
|
|
|
221
227
|
const textNode = elementNode.children[0];
|
|
222
228
|
if (!REGEX_LINE_BREAKS_IN_THE_BEGINNING.test(textNode.value)) return;
|
|
223
229
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
while (match !== null) {
|
|
227
|
-
replacement.push({ type: "text", value: match[0] });
|
|
230
|
+
const match = REGEX_LINE_BREAKS_IN_THE_BEGINNING.exec(textNode.value);
|
|
228
231
|
|
|
229
|
-
|
|
230
|
-
|
|
232
|
+
if (match) {
|
|
233
|
+
code.children.unshift({ type: "text", value: match[0] });
|
|
231
234
|
|
|
232
|
-
|
|
233
|
-
match = REGEX_LINE_BREAKS_IN_THE_BEGINNING.exec(textNode.value);
|
|
235
|
+
textNode.value = textNode.value.replace(REGEX_LINE_BREAKS_IN_THE_BEGINNING, "");
|
|
234
236
|
}
|
|
235
|
-
|
|
236
|
-
code.children.unshift(...replacement);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
240
|
*
|
|
241
|
-
*
|
|
241
|
+
* handle trimming blank line for the last text node
|
|
242
242
|
*
|
|
243
243
|
*/
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
function handleTrimmingBlankLines(code: Element, directiveTrimBlankLines: boolean) {
|
|
245
|
+
if (!directiveTrimBlankLines) return;
|
|
246
|
+
|
|
247
|
+
const lastChild = code.children[code.children.length - 1];
|
|
248
|
+
|
|
249
|
+
if (lastChild.type === "text") {
|
|
250
|
+
if (/(\r?\n|\r)(\1)$/.test(lastChild.value)) {
|
|
251
|
+
lastChild.value = lastChild.value.replace(/(\r?\n|\r)(\1)$/, "$1");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
249
254
|
}
|
|
250
255
|
|
|
251
256
|
/**
|
|
@@ -259,10 +264,8 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
259
264
|
{
|
|
260
265
|
directiveShowLineNumbers,
|
|
261
266
|
directiveHighlightLines,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
directiveHighlightLines: number[];
|
|
265
|
-
},
|
|
267
|
+
directiveTrimBlankLines,
|
|
268
|
+
}: GutterOptions,
|
|
266
269
|
) {
|
|
267
270
|
hasFlatteningNeed(code) && flattenCodeTree(code); // mutates the code
|
|
268
271
|
|
|
@@ -270,6 +273,8 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
270
273
|
|
|
271
274
|
handleFirstElementContent(code); // mutates the code
|
|
272
275
|
|
|
276
|
+
handleTrimmingBlankLines(code, directiveTrimBlankLines);
|
|
277
|
+
|
|
273
278
|
const replacement: ElementContent[] = [];
|
|
274
279
|
|
|
275
280
|
let start = 0;
|
|
@@ -279,18 +284,13 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
279
284
|
for (let index = 0; index < code.children.length; index++) {
|
|
280
285
|
const child = code.children[index];
|
|
281
286
|
|
|
282
|
-
// if (index === 0 && /^[\n][\s]*$/.test(child.value)) {
|
|
283
|
-
// console.log(child.value, index);
|
|
284
|
-
// }
|
|
285
|
-
|
|
286
287
|
if (child.type !== "text") continue;
|
|
287
288
|
|
|
288
289
|
let textStart = 0;
|
|
289
|
-
let match = REGEX_LINE_BREAKS.exec(child.value);
|
|
290
290
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
//
|
|
291
|
+
const matches = Array.from(child.value.matchAll(REGEX_LINE_BREAKS));
|
|
292
|
+
matches.forEach((match, iteration) => {
|
|
293
|
+
// Nodes in this line. (current child (index) is exclusive)
|
|
294
294
|
const line = code.children.slice(start, index);
|
|
295
295
|
|
|
296
296
|
// Prepend text from a partial matched earlier text.
|
|
@@ -305,18 +305,21 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
305
305
|
line.push({ type: "text", value });
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
{ type: "text", value: match[0] }
|
|
312
|
-
|
|
308
|
+
const isFirstIteration = index === 0 && iteration === 0;
|
|
309
|
+
|
|
310
|
+
if (isFirstIteration && directiveTrimBlankLines && line.length === 0) {
|
|
311
|
+
replacement.push({ type: "text", value: match[0] }); // eol
|
|
312
|
+
} else {
|
|
313
|
+
lineNumber += 1;
|
|
314
|
+
replacement.push(
|
|
315
|
+
createLine(line, lineNumber, directiveShowLineNumbers, directiveHighlightLines),
|
|
316
|
+
{ type: "text", value: match[0] }, // eol
|
|
317
|
+
);
|
|
318
|
+
}
|
|
313
319
|
|
|
314
320
|
start = index + 1;
|
|
315
321
|
textStart = match.index + match[0].length;
|
|
316
|
-
|
|
317
|
-
// iterate the match
|
|
318
|
-
match = REGEX_LINE_BREAKS.exec(child.value);
|
|
319
|
-
}
|
|
322
|
+
});
|
|
320
323
|
|
|
321
324
|
// If we matched, make sure to not drop the text after the last line ending.
|
|
322
325
|
if (start === index + 1) {
|
|
@@ -333,14 +336,11 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
333
336
|
}
|
|
334
337
|
|
|
335
338
|
if (line.length > 0) {
|
|
336
|
-
|
|
337
|
-
replacement.push(...line)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
createLine(line, lineNumber, directiveShowLineNumbers, directiveHighlightLines),
|
|
342
|
-
);
|
|
343
|
-
}
|
|
339
|
+
directiveTrimBlankLines
|
|
340
|
+
? replacement.push(...line)
|
|
341
|
+
: replacement.push(
|
|
342
|
+
createLine(line, ++lineNumber, directiveShowLineNumbers, directiveHighlightLines),
|
|
343
|
+
);
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
// Replace children with new array.
|
|
@@ -401,7 +401,8 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
401
401
|
if (
|
|
402
402
|
language?.startsWith("{") ||
|
|
403
403
|
language?.startsWith("showlinenumbers") ||
|
|
404
|
-
language?.startsWith("nolinenumbers")
|
|
404
|
+
language?.startsWith("nolinenumbers") ||
|
|
405
|
+
language?.startsWith("trimblanklines")
|
|
405
406
|
) {
|
|
406
407
|
// add specifiers to meta
|
|
407
408
|
meta = (language + " " + meta).trim();
|
|
@@ -427,8 +428,16 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
427
428
|
const strLineNumbers = REGEX2.exec(meta)?.groups?.lines?.replace(/\s/g, "");
|
|
428
429
|
const directiveHighlightLines = strLineNumbers ? rangeParser(strLineNumbers) : [];
|
|
429
430
|
|
|
431
|
+
// find the directive for trimming blank lines
|
|
432
|
+
const REGEX3 = /trimblanklines/i;
|
|
433
|
+
const directiveTrimBlankLines = settings.trimBlankLines || REGEX3.test(meta);
|
|
434
|
+
|
|
430
435
|
// if nothing to do for numbering, highlihting or trimming blank lines, just return;
|
|
431
|
-
if (
|
|
436
|
+
if (
|
|
437
|
+
directiveShowLineNumbers === false &&
|
|
438
|
+
directiveHighlightLines.length === 0 &&
|
|
439
|
+
directiveTrimBlankLines === false
|
|
440
|
+
) {
|
|
432
441
|
return;
|
|
433
442
|
}
|
|
434
443
|
|
|
@@ -436,6 +445,7 @@ const plugin: Plugin<[HighlightLinesOptions?], Root> = (options) => {
|
|
|
436
445
|
gutter(code, {
|
|
437
446
|
directiveShowLineNumbers,
|
|
438
447
|
directiveHighlightLines,
|
|
448
|
+
directiveTrimBlankLines,
|
|
439
449
|
});
|
|
440
450
|
});
|
|
441
451
|
};
|