Skip to content

Commit

Permalink
feat: 合并文本图片导入使用新关键字
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiuChen committed Apr 12, 2023
1 parent 7c1a393 commit a53b639
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
10 changes: 8 additions & 2 deletions public/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pluginName": "超级Markdown",
"description": "强大的Markdown编辑器 从文本创建笔记",
"description": "强大的Markdown编辑器 从文本与图片创建笔记",
"author": "ZiuChen",
"homepage": "https://github.com/ZiuChen",
"main": "index.html",
Expand Down Expand Up @@ -39,7 +39,13 @@
"explain": "从文本或图片创建笔记",
"cmds": [
{ "type": "over", "label": "从文本创建笔记", "maxLength": 999999 },
{ "type": "img", "label": "从图片创建笔记" }
{ "type": "img", "label": "从图片创建笔记" },
{
"type": "regex",
"label": "从文本与图片创建笔记",
"match": "/^__IMPORT_CONTENT_FLAG__*/",
"maxLength": 999999
}
]
}
]
Expand Down
81 changes: 42 additions & 39 deletions src/components/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,48 @@ useEventBus(ENTER_IMPORT, async (payload: IPayloadFile[]) => {
useEventBus(ENTER_CONTENT, async ({ type, payload }: { type: string; payload: string }) => {
// 文本内容
if (type === 'over') {
// 纯文本 正常导入
const nodeList = handleArticleImport([
{
title: '导入的文章',
data: payload
}
])
const len = nodeList.length
if (!len) return
// 选中导入的最后一个文章
const node = nodeList[len - 1]
if (node) selectedNode.value = node
return
}
// 图片内容 上传图片
if (type === 'img') {
useImageUpload(payload).then((hash) => {
if (!hash) return Message.error('图片上传失败')
const nodeList = handleArticleImport([
{
title: '导入的文章',
data: `![导入的图片](attachment:${hash})`
}
])
const len = nodeList.length
if (!len) return
// 选中导入的最后一个文章
const node = nodeList[len - 1]
if (node) selectedNode.value = node
})
return
}
// 结构化数据
if (type === 'regex') {
// 检查是否为结构化数据
if (payload.startsWith(IMPORT_CONTENT_FLAG.description!)) {
const data = payload.replace(IMPORT_CONTENT_FLAG.description!, '')
Expand Down Expand Up @@ -312,45 +354,6 @@ useEventBus(ENTER_CONTENT, async ({ type, payload }: { type: string; payload: st
}
return
}
// 纯文本 正常导入
const nodeList = handleArticleImport([
{
title: '导入的文章',
data: payload
}
])
const len = nodeList.length
if (!len) return
// 选中导入的最后一个文章
const node = nodeList[len - 1]
if (node) selectedNode.value = node
return
}
// 图片内容 上传图片
if (type === 'img') {
useImageUpload(payload).then((hash) => {
if (!hash) return Message.error('图片上传失败')
const nodeList = handleArticleImport([
{
title: '导入的文章',
data: `![导入的图片](attachment:${hash})`
}
])
const len = nodeList.length
if (!len) return
// 选中导入的最后一个文章
const node = nodeList[len - 1]
if (node) selectedNode.value = node
})
return
}
})
Expand Down

0 comments on commit a53b639

Please sign in to comment.