-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
refactor(utils): use Remark to parse Markdown server-side #5670
Changes from all commits
a01e8ec
e65254b
46399b8
cc89cef
9c86c8a
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 |
---|---|---|
|
@@ -32,20 +32,25 @@ export type ReplaceMarkdownLinksReturn<T extends ContentPaths> = { | |
brokenMarkdownLinks: BrokenMarkdownLink<T>[]; | ||
}; | ||
|
||
const stripHtmlComments = (fileString: string) => { | ||
return fileString.replace(/<!--.*?-->/gs, ''); | ||
}; | ||
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. Notice that it would also remove that text when it is inside another block as string or fenced codeblock. Even worse when start-comment and end-comment are in separated blocks. 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. Agree
Not sure what you mean here? 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. My first comment was for fenced codeblock (or any "block") for example: ```md
html comment have the following form <!-- comment with possibly [link_in_block_considered_in_comment](link.md) -->"
``` for which the removal for the tools might not be important. but cases like 2 separates blocks: ```md
start of html comment is '<!--'
```
[link_falsely_considered_as_in_comment](link.md)
```md
end of html comment is '-->'
``` would be more problematic. |
||
|
||
export function replaceMarkdownLinks<T extends ContentPaths>({ | ||
siteDir, | ||
fileString, | ||
filePath, | ||
contentPaths, | ||
sourceToPermalink, | ||
}: ReplaceMarkdownLinksParams<T>): ReplaceMarkdownLinksReturn<T> { | ||
const fileStringWithoutHtmlComments = stripHtmlComments(fileString); | ||
const {contentPath, contentPathLocalized} = contentPaths; | ||
|
||
const brokenMarkdownLinks: BrokenMarkdownLink<T>[] = []; | ||
|
||
// Replace internal markdown linking (except in fenced blocks). | ||
let fencedBlock = false; | ||
const lines = fileString.split('\n').map((line) => { | ||
const lines = fileStringWithoutHtmlComments.split('\n').map((line) => { | ||
if (line.trim().startsWith('```')) { | ||
fencedBlock = !fencedBlock; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a different behavior here, don't know for sure what is best though 🤷♂️