Skip to content

Commit

Permalink
feat: 兼容 292 版本API改动
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jun 25, 2023
1 parent de3ac78 commit af04e1e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules
dist
build
__pycache__
__pycache__
temp
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "terwer",
"url": "https://github.com/terwer/siyuan-plugin-importer",
"version": "1.6.0",
"minAppVersion": "2.8.9",
"minAppVersion": "2.9.2",
"backends": [
"windows",
"linux",
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

export const workspaceDir = `${(window as any).siyuan.config.system.workspaceDir}`
export const dataDir = `${(window as any).siyuan.config.system.dataDir}`
export const mediaDir = `./assets`
export const mediaDir = `./../assets`
export const isDev = process.env.DEV_MODE === "true"
export const siyuanApiUrl = ""
export const siyuanApiToken = ""
7 changes: 5 additions & 2 deletions src/service/importService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export class ImportService {
}

// 文件转换
const convertResult = await pluginInstance.kernelApi.convertPandoc(fromFilename, toFilename)
const fromAbsPath = `./../${fromFilename}`
const toAbsPath = `./../${toFilename}`
pluginInstance.logger.info(`convertPandoc from [${fromAbsPath}] to [${toAbsPath}]`)
const convertResult = await pluginInstance.kernelApi.convertPandoc(fromAbsPath, toAbsPath)
if (convertResult.code !== 0) {
showMessage(`${pluginInstance.i18n.msgFileConvertError}${convertResult.msg}`, 7000, "error")
return
Expand All @@ -114,7 +117,7 @@ export class ImportService {

// 文本处理
const importConfig = await loadImporterConfig(pluginInstance)
if (importConfig.bundledFnSwitch) {
if (importConfig.bundledFnSwitch !== false) {
pluginInstance.logger.info("Using bundled handler process text")
// 删除目录中链接
mdText = removeLinks(mdText)
Expand Down
19 changes: 13 additions & 6 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,27 @@ function convertPathToUnixStyle(path) {
/**
* 修复图片路径
*
* 修复要点
* 1、转 unix 路径
* 2、修复 pandoc 资源路径
*
* @param mdText - markdown 文本
*/
export function replaceImagePath(mdText) {
const regex = /!\[(.*?)\]\(([^\s]*?)\)/g
return mdText.replace(regex, (match, p1, p2) => {
const imagePath = p2
let title = p1
let imagePath = p2

if (!imagePath.startsWith(dataDir)) {
return match
}
// console.log("p1=>", title)
// console.log("p2=>", imagePath)

const relativePath = convertPathToUnixStyle(imagePath.substring(dataDir.length))
// 修复资源路径
imagePath = convertPathToUnixStyle(imagePath)
// 修复 pandoc 路径问题
imagePath = imagePath.replace(/\.\/\.\.\/assets/g, "./assets")

return `![${p1}](${relativePath})`
return `![${title}](${imagePath})`
})
}

Expand Down

0 comments on commit af04e1e

Please sign in to comment.