Skip to content

Commit a48ff2c

Browse files
committed
chore: code review
1 parent d22dc9c commit a48ff2c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/rehype-shiki/src/plugin.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ const languagePrefix = 'language-';
1313
// The regex to match metadata
1414
const rMeta = /(\w+)(?:=(?:"([^"]+)"|(\S+)))?/g;
1515

16-
const getLineCount = value =>
17-
value
18-
.split('\n')
19-
.filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === '')).length;
20-
2116
/**
2217
* Parses a fenced code block metadata string into a JavaScript object.
2318
* @param {string} meta - The metadata string from a Markdown code fence.
@@ -170,7 +165,9 @@ export default async function rehypeShikiji(options) {
170165
// Retrieve the whole <pre> contents as a parsed DOM string
171166
const preElementContents = toString(preElement).replace(/\n$/, '');
172167

173-
const lineCount = getLineCount(preElementContents);
168+
// Since we removed the trailing newline, we can easily count the
169+
// amount of lines without worrying about an extra empty line at the end of the code block
170+
const lineCount = preElementContents.split('\n').length;
174171

175172
// Grabs the relevant alias/name of the language
176173
const languageId = codeLanguage.slice(languagePrefix.length);

0 commit comments

Comments
 (0)