-
-
Notifications
You must be signed in to change notification settings - Fork 737
fix: skip frontmatter when rewriting wiki links #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ interface ParsedWikiLink { | |
|
|
||
| const WIKI_LINK_PATTERN = /\[\[([^\]|#]*)(?:#([^\]|]+))?(?:\|([^\]]+))?\]\]/g; | ||
| const FENCE_PATTERN = /^(`{3,}|~{3,})/; | ||
| const FRONTMATTER_DELIMITER = '---'; | ||
|
|
||
| function encodeLinkPath(pathValue: string): string { | ||
| return encodeURI(normalizePathSeparators(pathValue)); | ||
|
|
@@ -218,8 +219,21 @@ export function restoreWikiLinks(markdown: string): string { | |
| export function rewriteWikiLinks(source: string): string { | ||
| const lines = source.split('\n'); | ||
| let activeFence: string | null = null; | ||
| let inFrontmatter = lines[0]?.trim() === FRONTMATTER_DELIMITER | ||
| && lines.slice(1).some((line) => line.trim() === FRONTMATTER_DELIMITER); | ||
|
|
||
| return lines.map((line, index) => { | ||
| if (index === 0 && inFrontmatter) { | ||
| return line; | ||
| } | ||
|
|
||
| if (inFrontmatter) { | ||
| if (line.trim() === FRONTMATTER_DELIMITER) { | ||
| inFrontmatter = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The frontmatter close check uses Severity Level: Major
|
||
| } | ||
| return line; | ||
| } | ||
|
|
||
| return lines.map((line) => { | ||
| const trimmedStart = line.trimStart(); | ||
| const fenceMatch = trimmedStart.match(FENCE_PATTERN); | ||
| if (fenceMatch) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.