fix: Headers parsing fix (#5)

* fix: html tag symbol parsing

* fix: missing contributors in parsing
This commit is contained in:
Filip Pajic 2024-05-09 11:24:54 +02:00 committed by GitHub
parent 276328e60b
commit c51271253a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 8 deletions

View File

@ -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 &lt; and &gt;, respectively
// Be cautious with this replacement; adjust as needed based on your context
content = content.replace(/(?<!`)<(?!.*?`)/g, '&lt;')
content = content.replace(/(?<!`)>(?!.*?`)/g, '&gt;')
return content;
}
function unescapeHtmlComments(htmlString) {
return htmlString.replace(/\\<\!--/g, '\n<!--').replace(/--\\>/g, '-->\n')
return htmlString.replace(/&lt;\!--/g, '\n<!--').replace(/--&gt;/g, '-->\n')
}
function updateMarkdownLinksToExcludeMD(content) {
@ -107,9 +114,7 @@ export function vacMarkdownToDocusaurusMarkdown(fileContent) {
// Replace <br> with <br/>
convertedContent = convertedContent.replace(/<br>/g, '<br/>')
// Escape < and > with \< and \>, respectively
// Be cautious with this replacement; adjust as needed based on your context
convertedContent = convertedContent.replace(/</g, '\\<').replace(/>/g, '\\>')
convertedContent = escapeHtmlTagSymbols(convertedContent)
// NEW: Remove 'slug' line from frontmatter
convertedContent = convertedContent.replace(/^slug:.*\n?/m, '')