resolve: #97 convert markdown in clipboard
This commit is contained in:
parent
2e4facdd28
commit
96f0e7460f
|
|
@ -40,6 +40,7 @@
|
|||
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
|
||||
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
|
||||
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation'});" />
|
||||
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertMD'});" />
|
||||
<command id="cmd_treeview_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(1);" />
|
||||
<command id="cmd_mindmap_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(2);" />
|
||||
<command id="cmd_bubblemap_betternotes" oncommand="Zotero.Knowledge4Zotero.views.switchView(3);" />
|
||||
|
|
@ -86,6 +87,8 @@
|
|||
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
|
||||
<menuseparator />
|
||||
<menuitem id="menu_autoannotation_betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.autoannotation;" command="cmd_autoannotation_betternotes" />
|
||||
<menuseparator />
|
||||
<menuitem id="menu_convertmd_betternotes" label="&zotero.__addonRef__.workspace.menu.convertmd;" command="cmd_convertmd_betternotes" />
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="menu_viewPopup">
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@
|
|||
<!-- <command id="cmd_importlink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'importLink'});" />
|
||||
<command id="cmd_updatelink_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateLink'});" /> -->
|
||||
<command id="cmd_autoannotation_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'updateAutoAnnotation', content: {event: event}});" />
|
||||
<command id="cmd_convertmd_betternotes" oncommand="Zotero.Knowledge4Zotero.events.onEditorEvent({type: 'convertMD'});" />
|
||||
<command id="cmd_treeview" oncommand="Zotero.Knowledge4Zotero.views.switchView(1);" />
|
||||
<command id="cmd_mindmap" oncommand="Zotero.Knowledge4Zotero.views.switchView(2);" />
|
||||
<command id="cmd_bubblemap" oncommand="Zotero.Knowledge4Zotero.views.switchView(3);" />
|
||||
|
|
@ -92,6 +93,8 @@
|
|||
<menuitem id="menu_updatelink_betternotes" class="menu-type-betternotes" label="&zotero.__addonRef__.workspace.menu.updateLink;" command="cmd_updatelink_betternotes" /> -->
|
||||
<menuseparator />
|
||||
<menuitem id="menu_autoannotation_betternotes" type="checkbox" label="&zotero.__addonRef__.workspace.menu.autoannotation;" command="cmd_autoannotation_betternotes" />
|
||||
<menuseparator />
|
||||
<menuitem id="menu_convertmd_betternotes" label="&zotero.__addonRef__.workspace.menu.convertmd;" command="cmd_convertmd_betternotes" />
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<!ENTITY zotero.__addonRef__.workspace.menu.importLink "Import Selected Note Link Content">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.updateLink "Update Selected Note Link Text">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.autoannotation "Auto Insert New Annotations to Note">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.convertmd "Convert MarkDown In Clipboard">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.treeview "Outline: Tree View">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.mindmap "Outline: Mind Map">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.bubblemap "Outline: Bubble Map">
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<!ENTITY zotero.__addonRef__.workspace.menu.importLink "导入选中的笔记链接内容">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.updateLink "更新选中的笔记链接文本">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.autoannotation "自动插入新注释到笔记">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.convertmd "转换剪贴板中的MarkDown内容">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.treeview "大纲: 树视图">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.mindmap "大纲: 思维导图">
|
||||
<!ENTITY zotero.__addonRef__.workspace.menu.bubblemap "大纲: 气泡导图">
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1684,6 +1684,42 @@ class AddonEvents extends AddonBase {
|
|||
"Better Notes",
|
||||
"Image copied to clipboard."
|
||||
);
|
||||
} else if (message.type == "convertMD") {
|
||||
/*
|
||||
message.content = {}
|
||||
*/
|
||||
const source = Zotero.Utilities.Internal.getClipboard("text/unicode");
|
||||
if (!source) {
|
||||
this._Addon.views.showProgressWindow(
|
||||
"Better Notes",
|
||||
"No MarkDown found."
|
||||
);
|
||||
return;
|
||||
}
|
||||
const html = this._Addon.parse.parseMDToHTML(source);
|
||||
console.log(source, html);
|
||||
let transferable = Components.classes[
|
||||
"@mozilla.org/widget/transferable;1"
|
||||
].createInstance(Components.interfaces.nsITransferable);
|
||||
let clipboardService = Components.classes[
|
||||
"@mozilla.org/widget/clipboard;1"
|
||||
].getService(Components.interfaces.nsIClipboard);
|
||||
const str = Components.classes[
|
||||
"@mozilla.org/supports-string;1"
|
||||
].createInstance(Components.interfaces.nsISupportsString);
|
||||
str.data = html;
|
||||
transferable.addDataFlavor("text/html");
|
||||
transferable.setTransferData("text/html", str, html.length * 2);
|
||||
|
||||
clipboardService.setData(
|
||||
transferable,
|
||||
null,
|
||||
Components.interfaces.nsIClipboard.kGlobalClipboard
|
||||
);
|
||||
this._Addon.views.showProgressWindow(
|
||||
"Better Notes",
|
||||
"Converted MarkDown is updated to the clipboard. You can paste them in the note."
|
||||
);
|
||||
} else {
|
||||
Zotero.debug(`Knowledge4Zotero: message not handled.`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { AddonBase } from "./base";
|
||||
import { HTML2Markdown, Markdown2HTML } from "./convertMD";
|
||||
const TreeModel = require("./treemodel");
|
||||
|
||||
class AddonParse extends AddonBase {
|
||||
|
|
@ -340,6 +341,14 @@ class AddonParse extends AddonBase {
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
parseMDToHTML(str: string): string {
|
||||
return Markdown2HTML(str);
|
||||
}
|
||||
|
||||
parseHTMLToMD(str: string): string {
|
||||
return HTML2Markdown(str);
|
||||
}
|
||||
}
|
||||
|
||||
export default AddonParse;
|
||||
|
|
|
|||
Loading…
Reference in New Issue