Use Quick Copy (Markdown) for direct plain-text copying from note-editor

Fixes #2505
This commit is contained in:
Martynas Bagdonas 2022-07-15 15:06:19 +03:00 committed by Dan Stillman
parent bd18339797
commit 7089ce8fc7
2 changed files with 20 additions and 1 deletions

View file

@ -89,6 +89,25 @@ class EditorInstance {
return doc.execCommand(command, ui, value);
};
// Translate note HTML into Markdown, for setting it as text/plain in clipboard (on text copy/drag)
this._iframeWindow.wrappedJSObject.zoteroTranslateToMarkdown = (html) => {
let item = new Zotero.Item('note');
item.libraryID = this._item.libraryID;
item.setNote(html);
let text = '';
var translation = new Zotero.Translate.Export;
translation.noWait = true;
translation.setItems([item]);
translation.setTranslator(Zotero.Translators.TRANSLATOR_ID_NOTE_MARKDOWN);
translation.setHandler("done", (obj, worked) => {
if (worked) {
text = obj.string.replace(/\r\n/g, '\n');
}
});
translation.translate();
return text;
};
this._iframeWindow.addEventListener('message', this._messageHandler);
this._iframeWindow.addEventListener('error', (event) => {
Zotero.logError(event.error);

@ -1 +1 @@
Subproject commit 3c75eb213b23da239b5b0c69b9e61ff54a2f2a4c
Subproject commit 8e7b266875dc9d7dc14d5c9413197ae80d8dbf11