feat: dont show image duplicate in beginnign of markdown
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user