Skip to content

Commit

Permalink
feat: 支持Base64图片的Markdown解析
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiuChen committed Apr 22, 2023
1 parent 4776db7 commit c76a8f3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common/plugins/customImagePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ export function customImagePlugin(): BytemdPlugin {
visit(tree, (node) => {
if (node.type === 'element' && node.tagName === 'img') {
const image = markdownImages[count]
// 处理自定义图片
if (image && image.url.startsWith('attachment:')) {
const attachmentId = image.url.split(':')[1]
const imageData = imageCache[attachmentId] || loadImage(attachmentId)
imageCache[attachmentId] = imageData
node.properties.src = imageData
}
// 处理Base64图片
if (image && image.url.startsWith('data:image')) {
node.properties.src = image.url
}
count++
}
})
Expand Down

0 comments on commit c76a8f3

Please sign in to comment.