Skip to content

Commit

Permalink
fix: 修复图片路径中包含反斜杠时无法识别的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
lpreterite committed Feb 27, 2023
1 parent 5d31a79 commit cc31a61
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function MD2Docx({decodeImgPath=true}={}){
marked.use({
renderer: {
image(href, title, text){
href = href.replace('\\','/')
if(decodeImgPath) href = decodeURIComponent(href)
// console.log("image::%s", href)
return `<img src="${href}"${text?` alt="${text}"`:''}${title?` title="${title}"`:''} />`
Expand All @@ -33,8 +32,8 @@ function MD2Docx({decodeImgPath=true}={}){
})

const mdSource = fs.readFileSync(input, encoding)
const htmlSource = marked.parse(mdSource)
// console.log(htmlSource)
const htmlSource = marked.parse(mdSource.replace(/\((\S+)\\(\S+)\)/g, "($1//$2)"))
// console.log(mdSource)

toDocx.generate(output, htmlSource, { pwd })
}
Expand Down

0 comments on commit cc31a61

Please sign in to comment.