From c51271253a5147a9f0e50a3024272b183e37b030 Mon Sep 17 00:00:00 2001
From: Filip Pajic <42151917+pajicf@users.noreply.github.com>
Date: Thu, 9 May 2024 11:24:54 +0200
Subject: [PATCH] fix: Headers parsing fix (#5)
* fix: html tag symbol parsing
* fix: missing contributors in parsing
---
.../scrapper/markdown-convertor.mjs | 21 ++++++++++++-------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/docusaurus-utils/scrapper/markdown-convertor.mjs b/docusaurus-utils/scrapper/markdown-convertor.mjs
index e29a495..1c60bd5 100644
--- a/docusaurus-utils/scrapper/markdown-convertor.mjs
+++ b/docusaurus-utils/scrapper/markdown-convertor.mjs
@@ -14,7 +14,7 @@ function enhanceMarkdownWithBulletPointsCorrected(input) {
inFrontMatter = !inFrontMatter
if (!inFrontMatter && contributorsLines.length) {
// We're exiting frontmatter; time to add contributors
- extractedFields.push(`contributors:\n${contributorsLines.join('\n')}`)
+ extractedFields.push(`contributors\n${contributorsLines.join('\n')}`)
contributorsLines = [] // Reset for safety
}
return line // Keep the frontmatter delimiters
@@ -24,13 +24,11 @@ function enhanceMarkdownWithBulletPointsCorrected(input) {
if (line.startsWith('contributors:')) {
inContributors = true // Entering contributors section
} else if (inContributors) {
- if (line.startsWith(' -')) {
+ if (line.trim().startsWith('-')) {
contributorsLines.push(line.trim()) // Add contributors line
} else {
// Exiting contributors section
inContributors = false
- extractedFields.push(`contributors:\n${contributorsLines.join('\n')}`)
- contributorsLines = [] // Reset
}
} else {
const match = line.match(/(status|category|editor):(.*)/)
@@ -82,8 +80,17 @@ function parseSlugFromFrontmatter(content) {
return 1 // Return null if not found
}
+function escapeHtmlTagSymbols(content) {
+ // Escape < and > with < and >, respectively
+ // Be cautious with this replacement; adjust as needed based on your context
+ content = content.replace(/(?(?!.*?`)/g, '>')
+
+ return content;
+}
+
function unescapeHtmlComments(htmlString) {
- return htmlString.replace(/\\<\!--/g, '\n\n')
+ return htmlString.replace(/<\!--/g, '\n\n')
}
function updateMarkdownLinksToExcludeMD(content) {
@@ -107,9 +114,7 @@ export function vacMarkdownToDocusaurusMarkdown(fileContent) {
// Replace
with
convertedContent = convertedContent.replace(/
/g, '
')
- // Escape < and > with \< and \>, respectively
- // Be cautious with this replacement; adjust as needed based on your context
- convertedContent = convertedContent.replace(//g, '\\>')
+ convertedContent = escapeHtmlTagSymbols(convertedContent)
// NEW: Remove 'slug' line from frontmatter
convertedContent = convertedContent.replace(/^slug:.*\n?/m, '')