Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions packages/mdx/src/plugins/rehype/rehypeSyntaxHighlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ function traverseNode({

const linkMap = options.linkMap ?? new Map();
if (shouldUseTwoslash) {
const splitCode = code.split('\n');

for (const [i, line] of splitCode.entries()) {
const parsedLineComment = parseLineComment(line);
if (!parsedLineComment) continue;
const { word, href } = parsedLineComment;
linkMap.set(word, href);
splitCode.splice(i, 1);
}

code = splitCode.join('\n');
code = code
.split('\n')
.filter((line) => {
const parsedLineComment = parseLineComment(line);
if (!parsedLineComment) return true;
linkMap.set(parsedLineComment.word, parsedLineComment.href);
return false;
})
.join('\n');
}

const twoslashOptions = getTwoslashOptions({ linkMap });
Expand Down