File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed
packages/rehype-shiki/src Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,6 @@ const languagePrefix = 'language-';
1313// The regex to match metadata
1414const 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 ) ;
You can’t perform that action at this time.
0 commit comments