feat: dont show image duplicate in beginnign of markdown

This commit is contained in:
2025-01-26 02:00:59 +01:00
parent 6a54bdeec6
commit d450f4ed42
8 changed files with 99 additions and 42 deletions

View File

@@ -132,8 +132,35 @@ export function parseDocument(doc: string) {
.parse(doc);
}
function removeFrontmatter(doc: string) {
if (doc.trim().startsWith("---")) {
return doc.trim().split("---").filter((s) => s.length).slice(1).join("---");
}
return doc;
}
export function removeImage(doc: string, imageUrl?: string) {
if (!imageUrl) {
return doc;
}
// Remove image from content
const first = doc.slice(0, 500);
const second = doc.slice(500);
// Regex pattern to match the image Markdown syntax with the specific URL
const pattern = new RegExp(
`!\\[.*?\\]\\(${imageUrl.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\)`,
"g",
);
// Remove the matched image
const updatedMarkdown = first.replace(pattern, "");
return updatedMarkdown + second;
}
export function renderMarkdown(doc: string) {
return render(doc, {
return render(removeFrontmatter(doc), {
baseUrl: SILVERBULLET_SERVER,
allowMath: true,
});
}
@@ -172,4 +199,3 @@ export function getTextOfChild(child: DocumentChild): string | undefined {
}
return;
}