Skip to content

Commit 870b5fb

Browse files
committedJun 1, 2023
feat: #47 导入html支持图片
1 parent 6e0ca9f commit 870b5fb

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed
 

‎src/api/kernel-api.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ class KernelApi extends BaseApi {
107107
/**
108108
* 转换服务
109109
*
110-
* @param type - 类型
111110
* @param from - 原始文件名,不包括路径,路径必须放在 /temp/convert/pandoc
112111
* @param to - 转换后的文件名,不包括路径,路径相对于 /temp/convert/pandoc
113112
*/
114-
public async convertPandoc(type: string, from: string, to: string): Promise<SiyuanData> {
113+
public async convertPandoc(from: string, to: string): Promise<SiyuanData> {
115114
const params = {
116115
args: [
117116
"--to",
118-
type,
117+
"markdown_strict-raw_html",
119118
from,
120119
"-o",
121120
to,

‎src/service/importService.ts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class ImportService {
4242
// 修正文件名
4343
const originalFilename = fromFilename.substring(0, fromFilename.lastIndexOf("."))
4444
// 去除标题多余的空格,包括开始中间以及结尾的空格
45-
const filename = originalFilename.replace(/\s+/g, "")
46-
const toFilename = `${filename}.md`
45+
// const filename = originalFilename.replace(/\s+/g, "")
46+
const toFilename = `${originalFilename}.md`
4747

4848
// 扩展名
4949
const ext = fromFilename.split(".").pop().toLowerCase()
@@ -69,7 +69,7 @@ export class ImportService {
6969
const fullDirPath = path.join(dirPath, `${originalFilename}_files`)
7070
pluginInstance.logger.info("fullDirPath=>", fullDirPath)
7171

72-
await copyDir(fullDirPath, `${workspaceDir}/temp/convert/pandoc/${filename}_files`)
72+
await copyDir(fullDirPath, `${workspaceDir}/temp/convert/pandoc/${originalFilename}_files`)
7373
}
7474
}
7575

@@ -90,32 +90,7 @@ export class ImportService {
9090
}
9191

9292
// 文件转换
93-
const args: string[] = [
94-
"--to",
95-
"markdown_strict-raw_html",
96-
fromFilename,
97-
"-o",
98-
toFilename,
99-
"--extract-media",
100-
`${mediaDir}/${shortHash(fromFilename).toLowerCase()}`,
101-
"--wrap=none",
102-
]
103-
// const args = [
104-
// "--to",
105-
// "markdown_strict-raw_html",
106-
// fromFilename,
107-
// "-o",
108-
// toFilename,
109-
// "--extract-media",
110-
// `${mediaDir}/${shortHash(fromFilename).toLowerCase()}`,
111-
// "--wrap=none",
112-
// ]
113-
const convertResult = await pluginInstance.kernelApi.convertPandocCustom(args)
114-
// const convertResult = await pluginInstance.kernelApi.convertPandoc(
115-
// "markdown_strict-raw_html",
116-
// fromFilename,
117-
// toFilename
118-
// )
93+
const convertResult = await pluginInstance.kernelApi.convertPandoc(fromFilename, toFilename)
11994
if (convertResult.code !== 0) {
12095
showMessage(`${pluginInstance.i18n.msgFileConvertError}${convertResult.msg}`, 7000, "error")
12196
return

0 commit comments

Comments
 (0)