-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
206 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
"importer": "导入插件", | ||
"selectFile": "选择文件", | ||
"cancel": "取消", | ||
"startImport": "单个导入", | ||
"importerLoaded": "导入工具已加载", | ||
"importerUnloaded": "导入工具已卸载", | ||
|
@@ -28,7 +27,7 @@ | |
"importFolder": "批量导入", | ||
"importFolderTip": "支持混合.epub,.docx,.opml", | ||
"importNotRecursive1": "1、不递归", | ||
"importNotRecursive2": "2、不支持MD,批量导入MD请使用笔记本自带功能。", | ||
"importNotRecursive2": "2、不支持MD,批量导入MD请使用笔记本自带功能", | ||
"importNotRecursive3": "3、不支持html,因为安全限制,浏览器现在无法获取绝对路径,可通过单个导入(支持资源文件)", | ||
"importTipNotAllowed": "不允许的文件类型:", | ||
"importError": "导入出错:", | ||
|
@@ -39,5 +38,16 @@ | |
"tempCountExists": "请先清理临时文件在进行批量导入", | ||
"reportBug1": "遇到问题? 发邮件到 [email protected] 或者 给开发者 terwer ", | ||
"reportBug2": "反馈一下", | ||
"reportBug3": " 吧~" | ||
"reportBug3": " 吧~", | ||
"setting": "设置", | ||
"cancel": "取消", | ||
"save": "保存", | ||
"customFnHandler": "自定义处理函数", | ||
"customFnSwitch": "自定义处理函数开关", | ||
"customFnSwitchTips": "启用或者禁用自定义处理函数", | ||
"customFnHandlerTips": "可以在这里自定义处理函数,导入过程中会自动调用,请注意:修改此处可能会导致导入不工作,若出现问题可禁用自定义处理函数。正则表达式在线测试可参考:", | ||
"customFnHandlerPlaceholder": "自定义处理函数", | ||
"enableCustomFn": "启用自定义函数", | ||
"enableCustomFnTips": "确认要启用自定义函数吗,此操作可能导致导入不可用,请确认您已经了解自定义函数的工作原理?", | ||
"importConfigSaveSuccess": "配置保存成功" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<!-- | ||
- Copyright (c) 2023, Terwer . All rights reserved. | ||
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
- | ||
- This code is free software; you can redistribute it and/or modify it | ||
- under the terms of the GNU General Public License version 2 only, as | ||
- published by the Free Software Foundation. Terwer designates this | ||
- particular file as subject to the "Classpath" exception as provided | ||
- by Terwer in the LICENSE file that accompanied this code. | ||
- | ||
- This code is distributed in the hope that it will be useful, but WITHOUT | ||
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
- version 2 for more details (a copy is included in the LICENSE file that | ||
- accompanied this code). | ||
- | ||
- You should have received a copy of the GNU General Public License version | ||
- 2 along with this work; if not, write to the Free Software Foundation, | ||
- Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
- | ||
- Please contact Terwer, Shenzhen, Guangdong, China, [email protected] | ||
- or visit www.terwer.space if you need additional information or have any | ||
- questions. | ||
--> | ||
|
||
<script lang="ts"> | ||
import ImporterPlugin from "../index" | ||
import { onMount } from "svelte" | ||
import { confirm, showMessage } from "siyuan" | ||
import { loadImporterConfig, saveImporterConfig } from "../store/config" | ||
export let pluginInstance: ImporterPlugin | ||
export let dialog | ||
let customFnSwitch = false | ||
let customFn | ||
let importerConfig = {} | ||
const onSaveSetting = async () => { | ||
dialog.destroy() | ||
importerConfig.customFnSwitch = customFnSwitch | ||
importerConfig.customFn = customFn | ||
await saveImporterConfig(pluginInstance, importerConfig) | ||
pluginInstance.logger.info("saved important config =>", importerConfig) | ||
showMessage(`${pluginInstance.i18n.importConfigSaveSuccess}`, 2000, "info") | ||
} | ||
const onCancel = async () => { | ||
dialog.destroy() | ||
} | ||
const updateSwitch = (event) => { | ||
event.stopPropagation() | ||
if (!customFnSwitch) { | ||
confirm( | ||
`⚠️${pluginInstance.i18n.enableCustomFn}`, | ||
`${pluginInstance.i18n.enableCustomFnTips}`, | ||
() => { | ||
const inputEl = document.querySelector("#customFnSwitch") | ||
inputEl.checked = customFnSwitch | ||
}, | ||
() => { | ||
customFnSwitch = !customFnSwitch | ||
} | ||
) | ||
} | ||
} | ||
onMount(async () => { | ||
// 加载配置 | ||
importerConfig = await loadImporterConfig(pluginInstance) | ||
customFnSwitch = importerConfig.customFnSwitch ?? false | ||
customFn = | ||
importerConfig.customFn ?? | ||
` | ||
// 您可以参考这个案例进行修改,注意:请勿修改方法名,只需修改实现即可 | ||
// 将字符串中形如"xxx^yyy"的部分替换成"xxx" | ||
export function customFn(mdText) { | ||
const regex = /\\^\\(\\[.*[0-9].*]\\(#.*#.*\\)\\)/g // 匹配格式为 ^[[数字]](#链接) 的脚注 | ||
return mdText.replace(regex, "") // 使用空字符串替换匹配到的脚注 | ||
} | ||
` | ||
}) | ||
</script> | ||
|
||
<div class="config__tab-container"> | ||
<label class="fn__flex b3-label"> | ||
<div class="fn__flex-1"> | ||
{pluginInstance.i18n.customFnSwitch} | ||
<div class="b3-label__text">{pluginInstance.i18n.customFnSwitchTips}</div> | ||
</div> | ||
<span class="fn__space" /> | ||
<input | ||
id="customFnSwitch" | ||
class="b3-switch fn__flex-center" | ||
type="checkbox" | ||
on:click={(event) => updateSwitch(event)} | ||
bind:checked={customFnSwitch} | ||
/> | ||
</label> | ||
|
||
<label class="fn__flex b3-label"> | ||
<div class="fn__flex-1"> | ||
{pluginInstance.i18n.customFnHandler} | ||
<div class="b3-label__text"> | ||
{pluginInstance.i18n.customFnHandlerTips} | ||
<a href="https://www.regextester.com" target="_blank">https://www.regextester.com</a> | ||
</div> | ||
<div class="fn__hr" /> | ||
<textarea | ||
class="b3-text-field fn__block" | ||
placeholder={pluginInstance.i18n.customFnHandlerPlaceholder} | ||
rows="10" | ||
spellcheck="false" | ||
bind:value={customFn} | ||
/> | ||
</div> | ||
</label> | ||
|
||
<div class="b3-dialog__action"> | ||
<button class="b3-button b3-button--cancel" on:click={onCancel}>{pluginInstance.i18n.cancel}</button> | ||
<div class="fn__space" /> | ||
<button class="b3-button b3-button--text" on:click={onSaveSetting}>{pluginInstance.i18n.save}</button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters