Skip to content

Commit

Permalink
Simplify the logic a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviocc committed May 3, 2024
1 parent 22777ce commit 7acb3db
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/extensions/String.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ String.prototype.removeObsidianLinks = function (this: string) {
const codeBlocksBounds = extractBounds(codeBlockRegex)
const inlineCodesBounds = extractBounds(inlineCodeRegex)

const cleanMarkdown = (match: string, content: string, index: number): string => {
const isInCodeBlock = codeBlocksBounds.some(
(block) => index >= block.start && index <= block.end
)
const isInInlineCode = inlineCodesBounds.some(
(code) => index >= code.start && index <= code.end
)
const isCode = (index: number) =>
codeBlocksBounds.some((block) => index >= block.start && index <= block.end) ||
inlineCodesBounds.some((code) => index >= code.start && index <= code.end)

if (isInCodeBlock || isInInlineCode) {
return match
} else {
return content.includes('|') ? content.split('|')[1] : content
}
}
const cleanMarkdown = (match: string, content: string, index: number) =>
isCode(index) ? match : content.includes("|") ? content.split("|")[1] : content

return this.replace(linkRegex, cleanMarkdown)
}
Expand Down

0 comments on commit 7acb3db

Please sign in to comment.