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
13 changes: 4 additions & 9 deletions src/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,10 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
let maskedSrc = src;

// Mask out reflinks
if (this.tokens.links) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still check if (this.tokens.links && Object.entries(this.tokens.links).length > 0) to prevent checking if we don't need to

const links = Object.keys(this.tokens.links);
if (links.length > 0) {
maskedSrc = maskedSrc.replace(this.tokenizer.rules.inline.reflinkSearch, match0 =>
links.includes(match0.slice(match0.lastIndexOf('[') + 1, -1))
? '[' + 'a'.repeat(match0.length - 2) + ']'
: match0);
}
}
maskedSrc = maskedSrc.replace(this.tokenizer.rules.inline.reflinkSearch, match0 =>
Object.hasOwn(this.tokens.links, match0.slice(match0.lastIndexOf('[') + 1, -1))
? '[' + 'a'.repeat(match0.length - 2) + ']'
: match0);

// Mask out escaped characters.
// Every mask must keep the length it replaces: emStrong and del line
Expand Down