mirror of
https://github.com/logseq/logseq.git
synced 2026-05-15 08:22:23 +00:00
fix(marketplace): enhance image tag handling in Markdown content
This commit is contained in:
@@ -96,11 +96,11 @@
|
||||
|
||||
marked.use({
|
||||
renderer: {
|
||||
link (href, title, text) {
|
||||
link({ href, title, text }) {
|
||||
return `<a href="${href}" target="_blank" title="${title}">${text}</a>`
|
||||
},
|
||||
|
||||
image (href, title, text) {
|
||||
image({ href, title, text }) {
|
||||
let link = isRelative(href)
|
||||
|
||||
if (link) {
|
||||
@@ -113,8 +113,20 @@
|
||||
},
|
||||
})
|
||||
|
||||
// force fix Markdown content
|
||||
function fixAllImageTagHref (content) {
|
||||
const isRelativeImageSrc = (src) => src && !src.match(/^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i) && isRelative(src)
|
||||
|
||||
return content.replace(/<img\b[^>]*>/gi, (img) => {
|
||||
return img.replace(/\bsrc\s*=\s*(['"]?)([^'"\s>]+)\1/i, (attr, quote, src) => {
|
||||
const link = isRelativeImageSrc(src)
|
||||
return link ? attr.replace(src, fixLink(link)) : attr
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// load exist points content
|
||||
async function loadPage (points) {
|
||||
async function loadPage(points) {
|
||||
setMsg('Loading ...')
|
||||
|
||||
for (let url of points) {
|
||||
@@ -131,7 +143,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
content = marked.parse(content).replace('src="./', `src="${fixLink('')}`)
|
||||
content = marked.parse(fixAllImageTagHref(content))
|
||||
setContent(DOMPurify.sanitize(content))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user