mirror of
https://github.com/vacp2p/rfc.vac.dev.git
synced 2025-02-22 12:28:22 +00:00
Merge pull request #7 from vacp2p/develop
Fix bugs with links in markdown
This commit is contained in:
commit
5e42014be1
@ -53,7 +53,7 @@ function enhanceMarkdownWithBulletPointsCorrected(input) {
|
||||
if (field.includes('\n')) {
|
||||
const [label, ...values] = field.split('\n')
|
||||
return `- ${label.charAt(0).toUpperCase() +
|
||||
label.slice(1)}:\n ${values.join('\n ')}`
|
||||
label.slice(1)}:\n ${values.join('\n ')}`
|
||||
} else {
|
||||
return `- ${field.charAt(0).toUpperCase() + field.slice(1)}`
|
||||
}
|
||||
@ -85,31 +85,31 @@ function parseSlugFromFrontmatter(content) {
|
||||
function escapeHtmlTagSymbols(content) {
|
||||
function replaceComparisonSymbol(text, symbol) {
|
||||
// Regex to match everything, but we'll handle what to replace in the callback
|
||||
let regex = /(```[\s\S]+?```|`[^`]*`)|(<)/g;
|
||||
let replacementString = "<";
|
||||
let regex = /(```[\s\S]+?```|`[^`]*`)|(<)/g
|
||||
let replacementString = '<'
|
||||
|
||||
if (symbol === ">") {
|
||||
regex = /(```[\s\S]+?```|`[^`]*`)|(>)/g;
|
||||
replacementString = ">";
|
||||
if (symbol === '>') {
|
||||
regex = /(```[\s\S]+?```|`[^`]*`)|(>)/g
|
||||
replacementString = '>'
|
||||
}
|
||||
|
||||
return text.replace(regex, function(match, code, lessThan) {
|
||||
if (code) {
|
||||
// It's a code segment, return it unchanged
|
||||
return code;
|
||||
return code
|
||||
} else if (lessThan) {
|
||||
// It's a '<' outside of code blocks, replace with '<'
|
||||
return replacementString;
|
||||
return replacementString
|
||||
}
|
||||
// Default return (though practically unused in this setup)
|
||||
return match;
|
||||
});
|
||||
return match
|
||||
})
|
||||
}
|
||||
|
||||
content = replaceComparisonSymbol(content, "<")
|
||||
content = replaceComparisonSymbol(content, ">")
|
||||
content = replaceComparisonSymbol(content, '<')
|
||||
content = replaceComparisonSymbol(content, '>')
|
||||
|
||||
return content;
|
||||
return content
|
||||
}
|
||||
|
||||
function unescapeHtmlComments(htmlString) {
|
||||
@ -118,9 +118,15 @@ function unescapeHtmlComments(htmlString) {
|
||||
|
||||
function updateMarkdownLinksToExcludeMD(content) {
|
||||
function replaceLinks(match, p1, p2, p3) {
|
||||
let url = p2.replace(/\.md$/, ''); // Remove .md extension from URL
|
||||
let anchor = p3.replace(/^\//, ''); // Remove preceding '/' from anchor if exists
|
||||
return `[${p1}](${url}${anchor ? '#' + anchor : ''})`;
|
||||
// Skip if the link is an external link (starts with 'http://' or 'https://')
|
||||
if (match.includes('http://') || match.includes('https://')) {
|
||||
return match
|
||||
}
|
||||
|
||||
let url = p2.replace(/\.md$/, '') // Remove .md extension from URL
|
||||
let anchor = p3.replace(/^\//, '') // Remove preceding '/' from anchor if exists
|
||||
|
||||
return `[${p1}](${url}${anchor ? '#' + anchor : ''})`
|
||||
}
|
||||
|
||||
const regex = /\[((?:(?!\]).)+)\]\(([^)]*?\.md)(?:\/#|\/#)?([^)]*)\)/g
|
||||
@ -129,7 +135,7 @@ function updateMarkdownLinksToExcludeMD(content) {
|
||||
}
|
||||
|
||||
export function vacMarkdownToDocusaurusMarkdown(fileContent) {
|
||||
let convertedContent = fileContent;
|
||||
let convertedContent = fileContent
|
||||
|
||||
// Remove 'tags' line from frontmatter because the format is wrong
|
||||
convertedContent = convertedContent.replace(/tags:.*\n?/, '')
|
||||
@ -151,7 +157,7 @@ export function vacMarkdownToDocusaurusMarkdown(fileContent) {
|
||||
|
||||
convertedContent = updateMarkdownLinksToExcludeMD(convertedContent)
|
||||
|
||||
return convertedContent;
|
||||
return convertedContent
|
||||
}
|
||||
|
||||
export function adjustPathForMarkdown(filePath) {
|
||||
@ -165,4 +171,4 @@ export function adjustPathForMarkdown(filePath) {
|
||||
}
|
||||
|
||||
return parts.join('/')
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
"build:full": "yarn scrape && yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.174",
|
||||
"@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.181",
|
||||
"@docusaurus/core": "2.4.1",
|
||||
"@docusaurus/preset-classic": "2.4.1",
|
||||
"@docusaurus/theme-mermaid": "^2.4.1",
|
||||
|
18
yarn.lock
18
yarn.lock
@ -19,14 +19,14 @@
|
||||
satori "^0.10.1"
|
||||
sharp "^0.32.1"
|
||||
|
||||
"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.174":
|
||||
version "1.0.0-alpha.174"
|
||||
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.174.tgz#34b588a2b81c140e194c00eabd52d0d623f2477c"
|
||||
integrity sha512-lz8Zm+x3tJF9DepSTfZkiBSKfhsTa1h1WnA5py5lXo5fqZiDmzlIyr0m3Tnxm9hFoejw0DMshgGJmwNNaNFFNA==
|
||||
"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.181":
|
||||
version "1.0.0-alpha.181"
|
||||
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.181.tgz#31e42de1b84f6e145368e5f252aafd42983b15a9"
|
||||
integrity sha512-KvMyDGFwst7P5HzlWQ4G08Q6Ep9gPZ9mt35nBN7dksiVzu1heVj3hfY91of2u1EXZszHDmzztU1iqoGYNinOhg==
|
||||
dependencies:
|
||||
"@acid-info/docusaurus-og" "^1.0.0-alpha.131"
|
||||
"@acid-info/logos-docusaurus-search-local" "^1.0.0-alpha.111"
|
||||
"@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.174"
|
||||
"@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.181"
|
||||
"@docusaurus/core" "^2.4.1"
|
||||
"@docusaurus/module-type-aliases" "^2.4.1"
|
||||
"@docusaurus/preset-classic" "^2.4.1"
|
||||
@ -54,10 +54,10 @@
|
||||
"@easyops-cn/docusaurus-search-local" "^0.33.6"
|
||||
lodash "^4.17.21"
|
||||
|
||||
"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.174":
|
||||
version "1.0.0-alpha.174"
|
||||
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.174.tgz#6457c75645e88f2e30d1be691c8008bb33f145e9"
|
||||
integrity sha512-IgoTGv5zGkZ2lUHnUF0fQiGAdboEbb1L4pR4Ov0wmTfWAQ4aH3vwsjD4ARJ3qLjVapwHG1mEcjzdOqId3wIy2g==
|
||||
"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.181":
|
||||
version "1.0.0-alpha.181"
|
||||
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.181.tgz#c68946a3372700284f2b9d0d4fc8cd7fc576125c"
|
||||
integrity sha512-hKLClMNHMrVhoApz+uY096tLAswScKq/FXUGb3VeY675QO75P1OMaPAKdKLnFeLXTRs3lbU3TA6YpkwEZDiJAA==
|
||||
dependencies:
|
||||
"@acid-info/docusaurus-og" "^1.0.0-alpha.131"
|
||||
"@acid-info/lsd-react" "^0.1.0-beta.3"
|
||||
|
Loading…
x
Reference in New Issue
Block a user