From d739fd84df1d3b6b58dc11b9bbdb1b8e699c5c48 Mon Sep 17 00:00:00 2001 From: Offerel Date: Sat, 16 Jul 2022 21:24:40 +0200 Subject: [PATCH] - Fix for pasting html/markdown --- CHANGELOG.md | 3 +++ composer.json | 6 +++--- js/primitivenotes.js | 5 +++-- js/primitivenotes.min.js | 2 +- primitivenotes.php | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) mode change 100755 => 100644 js/primitivenotes.min.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 155ed06..97ccccd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.1.1 +- Fix for pasting html/markdown + ### v2.1.0 - Rewrite of most parts - Added markdown linebreak in YAML diff --git a/composer.json b/composer.json index b4aa2f8..a83a510 100755 --- a/composer.json +++ b/composer.json @@ -2,14 +2,14 @@ "name": "offerel/primitivenotes", "description": "A deadly simple notes plugin for Roundcube", "keywords": ["notes","plugin","html","markdown","images","pdf","roundcube"], - "homepage": "https://github.com/Offerel/roundcube_primitivenotes", + "homepage": "https://codeberg.org/Offerel/roundcube_primitivenotes", "type": "roundcube-plugin", "license": "AGPL-3.0", - "version": "2.1.0", + "version": "2.1.1", "authors": [ { "name": "Offerel", - "homepage": "https://github.com/Offerel", + "homepage": "https://codeberg.org/Offerel", "role": "Developer" } ], diff --git a/js/primitivenotes.js b/js/primitivenotes.js index d5ea9a8..89a0707 100755 --- a/js/primitivenotes.js +++ b/js/primitivenotes.js @@ -1,7 +1,7 @@ /** * Roundcube Notes Plugin * - * @version 2.1.0 + * @version 2.1.1 * @author Offerel * @copyright Copyright (c) 2022, Offerel * @license GNU General Public License, version 3 @@ -212,6 +212,7 @@ function pasteParse(event) { event.stopPropagation(); const pastedString = event.clipboardData.getData('text/html') || event.clipboardData.getData('text/plain'); + console.log(pastedString); for (var i = 0; i < event.clipboardData.items.length ; i++) { let item = event.clipboardData.items[i]; @@ -284,7 +285,7 @@ function pasteParse(event) { } }); - let markdownString = pastedString.startsWith('') ? turndownService.turndown(pastedString) : pastedString; + let markdownString = pastedString.startsWith('<') ? turndownService.turndown(pastedString) : pastedString; if(markdownString.startsWith('---')) { let mdArr = markdownString.split('\n'); diff --git a/js/primitivenotes.min.js b/js/primitivenotes.min.js old mode 100755 new mode 100644 index 31acceb..d2443bd --- a/js/primitivenotes.min.js +++ b/js/primitivenotes.min.js @@ -1 +1 @@ -function uplMedia(){document.getElementById("dropMedia").click()}function osource(){let e=document.getElementById("source");e.readOnly&&e.value.length>1&&window.open(e.value,"_blank").focus()}function pasteParse(e){function t(e,t,n){let o=new XMLHttpRequest;o.onload=function(){if(200==o.status)mde.codemirror.replaceSelection(o.responseText),loader.remove();else{let e="Server Error! Upload failed. Can not connect to server";console.error(e),rcmail.display_message(e,"error")}},o.onerror=function(){let e="Server Error! Upload failed. Can not connect to server";console.error(e),rcmail.display_message(e,"error")};let l=new FormData;l.append("dropFile",e),o.open("POST",location.href+"&_action=uplMedia"),o.send(l)}e.preventDefault(),e.stopPropagation();const n=e.clipboardData.getData("text/html")||e.clipboardData.getData("text/plain");for(var o=0;o=0){let e=o.indexOf('alt="')+5,t=o.indexOf('"',e);var l=o.substr(e,t-e)}else l="";if(o.indexOf('title="')>=0){let e=o.indexOf('title="')+7,t=o.indexOf('"',e);var a=o.substr(e,t-e)}else a="";return document.getElementById("main_area").appendChild(loader),t(n.getAsFile(),l,a),!1}}let d={headingStyle:"atx",hr:"-",bulletListMarker:"-",codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",collapseMultipleWhitespaces:!0,preformattedCode:!0},i=new window.TurndownService(d);i.addRule("kbd",{filter:["kbd"],replacement:function(e){return""+e+""}});let r=n.startsWith("")?i.turndown(n):n;if(r.startsWith("---")){let e=r.split("\n"),t=r.indexOf("---",4)+3;for(let t=1;t<10&&"---"!=e[t];t++){let n=e[t].split(":");"tags"==n[0]&&tagify.addTags(n[1]),"author"==n[0]&&(document.getElementById("author").value=n[1].trim()),"date"==n[0]&&(document.getElementById("date").value=n.slice(1).join(":").trim()),"updated"==n[0]&&(document.getElementById("updated").value=n.slice(1).join(":").trim()),"source"==n[0]&&(document.getElementById("source").value=n.slice(1).join(":").trim())}r=r.substr(t).trim()}mde.codemirror.replaceSelection(r)}function manageDropUpload(e){document.getElementById("main_area").appendChild(loader);for(let t of e)if(rcmail.env.aformat.includes(t.name.split(".").slice(-1)[0]))filelist.push(t);else{let e="File '"+t.name+"' not allowed";console.error(e),rcmail.display_message(e,"error")}doDropUpload()}function doDropUpload(){if(filelist.length>0){let e=new FormData,t=filelist[0];filelist.shift(),e.append("dropFile",t);const n=new XMLHttpRequest;n.onload=(()=>{document.getElementById("pnlist").remove();const e=(new DOMParser).parseFromString(n.response,"text/html").getElementById("pnlist");document.getElementById("notes-list").appendChild(e),loader.remove(),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),cContextMenu()}),n.open("POST",location.href+"&_action=uplNote"),n.send(e)}}function cContextMenu(){if(rcmail.env.contextmenu){let e=rcmail.contextmenu.init({menu_name:"mymenu",menu_source:["#mymenu",{label:rcmail.gettext("note_show","primitivenotes"),command:"cCommand",props:"show",classes:"extwin"},{label:rcmail.gettext("note_edit","primitivenotes"),command:"cCommand",props:"edit",classes:"edit"},{label:rcmail.gettext("note_send","primitivenotes"),command:"cCommand",props:"send",classes:"send"},{label:rcmail.gettext("note_download","primitivenotes"),command:"cCommand",props:"download",classes:"download"},{label:rcmail.gettext("note_del","primitivenotes"),command:"cCommand",props:"delete",classes:"delete"}]},{beforeactivate:function(e){document.querySelectorAll("#pnlist li").forEach(function(e){e.classList.remove("lselected")}),e.source.classList.add("lselected")}});$("#pnlist li").each(function(){$(this).on("contextmenu",function(t){rcmail.contextmenu.show_one(t,this,this.id,e)})})}}function cCommand(e){let t=document.querySelector(".context-source"),n=null;switch(e){case"show":showNote(t.id,"show");break;case"edit":showNote(t.id,"edit");break;case"send":file=t.dataset.name,send_note({message:"done",name:file,type:file.slice(-3),note:""});break;case"download":downloadNote(t.dataset.name);break;case"delete":let o=document.getElementById("note_"+t.id).title;n={_file:t.dataset.name,_name:o},confirm(rcmail.gettext("note_del_note","primitivenotes").replace("%note%",o))&&rcmail.http_post("delNote",n,!1);break;default:return!1}}function downloadNote(e){let t=new XMLHttpRequest;t.onload=function(){if(200==t.status){let l=new Blob([t.response],{type:t.getResponseHeader("content-type")}),a=URL.createObjectURL(l),d=document.createElement("a");var e=t.getResponseHeader("Content-Disposition"),n=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/,o=n.exec(e);null!=o&&o[1]&&(filename=o[1].replace(/['"]/g,"")),d.href=a,d.download=filename,d.click(),setTimeout(function(){window.URL.revokeObjectURL(a)},100),loader.remove()}else{let e="Server Error! Download failed. Can't connect to server";console.error(e),rcmail.display_message(e,"error")}},t.onerror=function(){let e="Server Error! Download failed. Can't connect to server";console.error(e),rcmail.display_message(e,"error")},t.responseType="blob",t.open("GET",location.href+"&_action=getNote&_name="+e),t.send()}function tPreview(e=""){"show"===e||"edit"===e||(e=mde.isPreviewActive()?"edit":"show"),mde.isPreviewActive()?"edit"==e&&mde.togglePreview():"show"==e&&mde.togglePreview(),setTimeout(()=>{"show"==e?(document.querySelector(".preview").classList.add("active"),document.getElementById("headerTitle").classList.add("readOnly"),tagify.setReadonly(!0),document.querySelector(".tagify").classList.remove("taedit"),document.getElementById("author").readOnly=!0,document.getElementById("source").readOnly=!0,document.querySelector(".toc").classList.add("no-disable"),document.querySelector(".toc").removeAttribute("disabled")):(document.querySelector(".preview").classList.remove("active"),document.getElementById("headerTitle").classList.remove("readOnly"),tagify.setReadonly(!1),document.querySelector(".tagify").classList.add("taedit"),document.getElementById("author").readOnly=!1,document.getElementById("source").readOnly=!1,document.querySelector(".toc").classList.remove("no-disable"),document.querySelector(".toc").setAttribute("disabled",!0),document.getElementById("tocdiv")&&document.getElementById("tocdiv").classList.remove("tocShow"))},50)}function saveFile(){document.getElementById("main_area").appendChild(loader);let e=tagify.value,t=[];for(let n in e)t.push(e[n].value);const n={_oname:document.getElementById("fname").value,_content:mde.value(),_title:document.getElementById("headerTitle").value,_author:document.getElementById("author").value,_date:document.getElementById("date").dataset.tstamp,_updated:document.getElementById("updated").value,_source:document.getElementById("source").value,_tags:t};rcmail.http_post("saveNote",n,!1)}function togglemData(){document.getElementById("ndata").classList.toggle("mtoggle")}function loadNote(e){let t=window.location.protocol+"//"+window.location.host+window.location.pathname+"?_task=notes¬e="+e.note.filename;if(window.history.pushState({path:t},"",t),loader.remove(),screen.width<=480&&(document.getElementById("layout-list").classList.toggle("hidden"),document.getElementById("layout-content").classList.toggle("hidden")),document.getElementById("tocdiv")&&document.getElementById("tocdiv").remove(),document.getElementById("binobj")&&document.getElementById("binobj").remove(),tagify.removeAllTags(),document.getElementById("headerTitle").value=e.note.name,document.getElementById("ntags").value=e.note.tags,document.getElementById("author").value=e.note.author,document.getElementById("date").value=e.note.date,document.getElementById("date").dataset.tstamp=e.note.tstamp,document.getElementById("updated").value=e.note.updated,document.getElementById("source").value=e.note.source,document.getElementById("source").title=e.note.source,document.getElementById("fname").value=e.note.filename,document.querySelectorAll("#pnlist li").forEach(function(e){e.classList.remove("lselected")}),document.getElementById(e.note.id).classList.add("lselected"),0===e.note.mime_type.indexOf("text"))mde.value(e.note.content),document.querySelector(".EasyMDEContainer").classList.remove("mdeHide"),setTimeout(()=>{let e=document.querySelector(".CodeMirror").querySelectorAll("h1, h2, h3, h4, h5, h6"),t=document.querySelector(".toc");if(e.length>0){t.classList.add("no-disable");let n=document.createElement("div");n.id="tocdiv";let o=0,l=0,a="c%";e.forEach(function(e){l=e.tagName.substr(1,1),a=o
  • '+e.innerText+"
  • c%"):a.replace("c%",'
  • "):o>l?a.replace("c%",'
  • '+e.innerText+"
  • c%"):a.replace("c%",'
  • '+e.innerText+"
  • c%"),o=l}),a=a.replace("c%",""),n.innerHTML="

    "+rcmail.gettext("note_toc","primitivenotes")+"

    "+a+"
    ",document.querySelector(".EasyMDEContainer").appendChild(n),document.querySelectorAll("#tocdiv a").forEach(function(e){e.addEventListener("click",function(e){n.classList.toggle("tocShow")})})}else t.classList.remove("no-disable")},50),tagify.addTags(e.note.tags);else{document.querySelector(".EasyMDEContainer").classList.add("mdeHide");let t=document.createElement("div"),n=document.createElement("object");t.id="binobj",n.type=e.note.mime_type,n.data=e.note.content,n.classList.add("objcont"),t.classList.add("objdiv"),t.appendChild(n),document.getElementById("main_area").appendChild(t)}tPreview(e.mode),document.querySelectorAll(".hljs").forEach(function(e){e.addEventListener("click",function(){let e=this;navigator.clipboard.writeText(e.innerText).then(function(){let t=document.createElement("span");t.classList.add("success"),t.innerText="copied",e.appendChild(t),setTimeout(function(){t.remove()},1e3)},function(){console.error("Clipboard error")})})});let n=document.querySelectorAll(".editor-preview a.intlink");n.forEach(function(e){e.addEventListener("click",function(e){if(screen.width>480){e.preventDefault(),document.querySelector(".EasyMDEContainer").classList.add("mdeHide");let t=document.createElement("div"),n=document.createElement("object");t.id="binobj",n.data=e.target.attributes.href.nodeValue,n.classList.add("objcont"),t.classList.add("objdiv"),t.appendChild(n),document.getElementById("main_area").appendChild(t)}})})}function savedNote(e){document.getElementById("ndata").classList.remove("mtoggle"),loader.remove(),document.getElementById("notes-list").appendChild(loader);let t=["done","saved"];if(t.includes(e.message)){document.getElementById("pnlist").remove();const t=(new DOMParser).parseFromString(e.list,"text/html");document.getElementById("notes-list").appendChild(t.body.children[0])}document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),e.mfiles?confirm(e.mfiles.message)&&rcmail.http_post("delMedia","_media="+e.mfiles.files,!1):"saved"==e.message&&tPreview(),cContextMenu(),loader.remove()}function searchList(){var e,t,n,o,l;for(e=document.getElementById("notessearchform"),t=e.value.toUpperCase(),n=document.getElementById("pnlist"),o=n.getElementsByTagName("li"),l=0;l-1?o[l].style.display="":o[l].style.display="none"}function toggleTOC(){let e=document.getElementById("tocdiv");e&&e.classList.toggle("tocShow")}function showNote(e,t="show"){let n;document.getElementById("ndata").classList.remove("mtoggle");let o=["md","txt","html","jpg"],l=document.getElementById(e).dataset.format;screen.width>480||-1!=o.indexOf(l)?(document.getElementById("main_area").appendChild(loader),n={_name:document.getElementById(e).dataset.name,_id:e,_mode:t},rcmail.http_post("displayNote",n,!1)):downloadNote(document.getElementById(e).dataset.name)}function pnoptions(){location.href=window.location.origin+window.location.pathname+"?_task=settings&_action=preferences#pnotes"}function send_note(e){rcmail.goto_url("mail/compose",{_note_filename:e.name},!0)}function new_note(e){screen.width<=480&&(document.getElementById("layout-list").classList.toggle("hidden"),document.getElementById("layout-content").classList.toggle("hidden")),document.title=rcmail.env.nnote;let t=window.location.protocol+"//"+window.location.host+window.location.pathname+"?_task=notes";window.history.pushState({path:t},"",t),document.getElementById("headerTitle").placeholder=rcmail.gettext("note_title","primitivenotes"),document.querySelector(".tagify__input").dataset.placeholder="Tags",format=e||rcmail.env.dformat,mde.value(""),tPreview("edit"),document.getElementById("headerTitle").value="",document.getElementById("headerTitle").classList.remove("readOnly"),tagify.removeAllTags(),tagify.setReadonly(!1),document.querySelector(".tagify").classList.add("taedit"),document.getElementById("author").readOnly=!1,document.getElementById("author").value="",document.getElementById("source").readOnly=!1,document.getElementById("source").value="",document.getElementById("date").value="",document.getElementById("updated").value="",document.getElementById("fname").value="",document.querySelector(".toc").classList.remove("no-disable"),document.querySelector(".toc").setAttribute("disabled",!0),document.getElementById("tocdiv")&&document.getElementById("tocdiv").classList.remove("tocShow")}function add_note(){document.getElementById("upl").click()}function mform(){document.getElementById("main_area").appendChild(loader),fileName=this.value;let e=["pdf","jpg","jpeg","png"];if(e.includes(fileName.split(".").pop().toLowerCase())){let e=new FormData;e.append("dropFile",document.getElementById("dropMedia").files[0]);var t=new XMLHttpRequest;t.onload=(()=>{mde.codemirror.replaceSelection(t.responseText),loader.remove()}),t.open("POST",location.href+"&_action=uplMedia"),t.send(e)}else alert(rcmail.gettext("note_inv_format","primitivenotes"));return!1}function sform(){fileName=this.value;let e=fileName.split(".").pop().toLowerCase();if(rcmail.env.aformat.includes(e)){let e=new FormData(document.getElementById("upl_form"));const t=new XMLHttpRequest;t.onload=(()=>{document.getElementById("pnlist").remove();const e=(new DOMParser).parseFromString(t.response,"text/html").getElementById("pnlist");document.getElementById("notes-list").appendChild(e),loader.remove(),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),cContextMenu()}),t.open("POST",location.href+"&_action=uplNote"),t.send(e)}else alert(rcmail.gettext("note_inv_format","primitivenotes"));return!1}var mde,tagify,filelist=[],loader=document.createElement("div"),ldr=document.createElement("div");ldr.classList.add("db-spinner"),loader.classList.add("lbg"),loader.appendChild(ldr),window.rcmail&&rcmail.addEventListener("init",function(e){"notes"===new URLSearchParams(window.location.search).get("_task")?document.querySelector(".task-menu-button")&&document.querySelector(".task-menu-button").classList.add("notes"):document.querySelector(".task-menu-button")&&document.querySelector(".task-menu-button").classList.remove("notes"),document.getElementById("headerTitle").placeholder=rcmail.gettext("note_title","primitivenotes"),document.querySelector(".back-list-button")&&(document.getElementById("headerTitle").style.width="block"==window.getComputedStyle(document.querySelector(".back-list-button"),null).display?document.getElementById("headerTitle").style.width="calc(100% - 30px)":document.getElementById("headerTitle").style.width="calc(100% - 10px)"),mde=new EasyMDE({element:document.getElementById("editor1"),autoDownloadFontAwesome:!1,autofocus:!0,previewImagesInEditor:!1,spellChecker:!1,promptURLs:!0,inputStyle:"contenteditable",nativeSpellcheck:!0,forceSync:!1,sideBySideFullscreen:!1,iconsSet:"material",toolbar:[{name:"save",action:saveFile,title:"Save",className:"fa fa-floppy-disk"},"|","bold","italic","heading","clean-block","|","quote","code","unordered-list","ordered-list","|","link",{name:"media",action:uplMedia,title:"Insert Media",className:"fa fa-image"},"table","|",{name:"preview",action:tPreview,title:"Toggle Preview",className:"preview fa fa-eye no-disable"},"side-by-side",{name:"meta",action:togglemData,className:"fa fa-question-circle no-disable",title:"Metadata"},{name:"toc",action:toggleTOC,className:"fa fa-list-alt",title:"TOC",attributes:{disabled:"",id:"test"}}],shortcuts:{save:"Ctrl-S",preview:"Ctrl-P"},renderingConfig:{codeSyntaxHighlighting:!0,sanitizerFunction:function(e){let t=e.replaceAll(rcmail.env.mfolder+"/","?_task=notes&_action=blink&_file=");return t=t.replaceAll('a href="?_task','a class="intlink" href="?_task'),t=t.replaceAll("
    ",'
    '),t}}});let t=JSON.parse(rcmail.env.taglist);if(tagify=new Tagify(document.getElementById("ntags"),{whitelist:t,dropdown:{classname:"color-blue",trim:!0,enabled:0,maxItems:t.length,position:"text",closeOnSelect:!1,highlightFirst:!0},trim:!0,duplicates:!1,enforceWhitelist:!1,delimiters:",|;| "}),document.getElementById("notessearchform").addEventListener("keyup",searchList,!1),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),rcmail.addEventListener("plugin.loadNote",loadNote),rcmail.addEventListener("plugin.savedNote",savedNote),rcmail.addEventListener("plugin.getNote",downloadNote),cContextMenu(),rcmail.register_command("cCommand",cCommand,!0),rcmail.register_command("addnote",add_note,!0),rcmail.register_command("newnote",new_note,!0),rcmail.register_command("pnoptions",pnoptions,!0),document.getElementById("upl")&&document.getElementById("upl").addEventListener("change",sform,!1),document.getElementById("dropMedia")&&document.getElementById("dropMedia").addEventListener("change",mform,!1),"#pnotes"==window.location.hash&&rcmail.sections_list.select_row("primitivenotes"),document.getElementById("notes-list")){var n=!1;document.getElementById("notes-list").addEventListener("dragenter",function(e){e.preventDefault(),e.stopPropagation(),n=!0,setTimeout(function(){n=!1},1),document.getElementById("notes-list").classList.add("highlight")}),document.getElementById("notes-list").addEventListener("dragleave",function(e){e.preventDefault(),e.stopPropagation(),!1===n&&document.getElementById("notes-list").classList.remove("highlight")}),document.getElementById("notes-list").addEventListener("dragover",function(e){e.preventDefault(),e.stopPropagation()}),document.getElementById("notes-list").addEventListener("drop",function(e){e.preventDefault(),e.stopPropagation(),document.getElementById("notes-list").classList.remove("highlight"),manageDropUpload(e.dataTransfer.files)})}document.addEventListener("keyup",e=>{"Escape"==e.key&&(!1===mde.isPreviewActive()&&document.getElementById("notessearchform")!==document.activeElement&&""!==mde.value()&&tPreview("show"),document.getElementById("notessearchform")===document.activeElement&&(document.getElementById("notessearchform").value="",document.getElementById("notessearchform").dispatchEvent(new KeyboardEvent("keyup",{key:""})))),"KeyF"==e.code&&(e.ctrlKey||e.metaKey)&&document.getElementById("notessearchform").focus()}),document.getElementById("source").addEventListener("click",osource,!0),document.querySelector(".EasyMDEContainer").addEventListener("paste",pasteParse,!0);let o=new URLSearchParams(document.location.search).get("note");if(o){let e=null;document.querySelectorAll("#pnlist li").forEach((t,n,l)=>{t.dataset.name==o&&(e=t.id,l.length=n+1)});let t={_name:o,_id:e,_mode:"show"};rcmail.http_post("displayNote",t,!1)}});
    \ No newline at end of file
    +function uplMedia(){document.getElementById("dropMedia").click()}function osource(){let e=document.getElementById("source");e.readOnly&&e.value.length>1&&window.open(e.value,"_blank").focus()}function pasteParse(e){function t(e,t,n){let o=new XMLHttpRequest;o.onload=function(){if(200==o.status)mde.codemirror.replaceSelection(o.responseText),loader.remove();else{let e="Server Error! Upload failed. Can not connect to server";console.error(e),rcmail.display_message(e,"error")}},o.onerror=function(){let e="Server Error! Upload failed. Can not connect to server";console.error(e),rcmail.display_message(e,"error")};let l=new FormData;l.append("dropFile",e),o.open("POST",location.href+"&_action=uplMedia"),o.send(l)}e.preventDefault(),e.stopPropagation();const n=e.clipboardData.getData("text/html")||e.clipboardData.getData("text/plain");console.log(n);for(var o=0;o=0){let e=o.indexOf('alt="')+5,t=o.indexOf('"',e);var l=o.substr(e,t-e)}else l="";if(o.indexOf('title="')>=0){let e=o.indexOf('title="')+7,t=o.indexOf('"',e);var a=o.substr(e,t-e)}else a="";return document.getElementById("main_area").appendChild(loader),t(n.getAsFile(),l,a),!1}}let d={headingStyle:"atx",hr:"-",bulletListMarker:"-",codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",collapseMultipleWhitespaces:!0,preformattedCode:!0},i=new window.TurndownService(d);i.addRule("kbd",{filter:["kbd"],replacement:function(e){return""+e+""}});let r=n.startsWith("<")?i.turndown(n):n;if(r.startsWith("---")){let e=r.split("\n"),t=r.indexOf("---",4)+3;for(let t=1;t<10&&"---"!=e[t];t++){let n=e[t].split(":");"tags"==n[0]&&tagify.addTags(n[1]),"author"==n[0]&&(document.getElementById("author").value=n[1].trim()),"date"==n[0]&&(document.getElementById("date").value=n.slice(1).join(":").trim()),"updated"==n[0]&&(document.getElementById("updated").value=n.slice(1).join(":").trim()),"source"==n[0]&&(document.getElementById("source").value=n.slice(1).join(":").trim())}r=r.substr(t).trim()}mde.codemirror.replaceSelection(r)}function manageDropUpload(e){document.getElementById("main_area").appendChild(loader);for(let t of e)if(rcmail.env.aformat.includes(t.name.split(".").slice(-1)[0]))filelist.push(t);else{let e="File '"+t.name+"' not allowed";console.error(e),rcmail.display_message(e,"error")}doDropUpload()}function doDropUpload(){if(filelist.length>0){let e=new FormData,t=filelist[0];filelist.shift(),e.append("dropFile",t);const n=new XMLHttpRequest;n.onload=(()=>{document.getElementById("pnlist").remove();const e=(new DOMParser).parseFromString(n.response,"text/html").getElementById("pnlist");document.getElementById("notes-list").appendChild(e),loader.remove(),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),cContextMenu()}),n.open("POST",location.href+"&_action=uplNote"),n.send(e)}}function cContextMenu(){if(rcmail.env.contextmenu){let e=rcmail.contextmenu.init({menu_name:"mymenu",menu_source:["#mymenu",{label:rcmail.gettext("note_show","primitivenotes"),command:"cCommand",props:"show",classes:"extwin"},{label:rcmail.gettext("note_edit","primitivenotes"),command:"cCommand",props:"edit",classes:"edit"},{label:rcmail.gettext("note_send","primitivenotes"),command:"cCommand",props:"send",classes:"send"},{label:rcmail.gettext("note_download","primitivenotes"),command:"cCommand",props:"download",classes:"download"},{label:rcmail.gettext("note_del","primitivenotes"),command:"cCommand",props:"delete",classes:"delete"}]},{beforeactivate:function(e){document.querySelectorAll("#pnlist li").forEach(function(e){e.classList.remove("lselected")}),e.source.classList.add("lselected")}});$("#pnlist li").each(function(){$(this).on("contextmenu",function(t){rcmail.contextmenu.show_one(t,this,this.id,e)})})}}function cCommand(e){let t=document.querySelector(".context-source"),n=null;switch(e){case"show":showNote(t.id,"show");break;case"edit":showNote(t.id,"edit");break;case"send":file=t.dataset.name,send_note({message:"done",name:file,type:file.slice(-3),note:""});break;case"download":downloadNote(t.dataset.name);break;case"delete":let o=document.getElementById("note_"+t.id).title;n={_file:t.dataset.name,_name:o},confirm(rcmail.gettext("note_del_note","primitivenotes").replace("%note%",o))&&rcmail.http_post("delNote",n,!1);break;default:return!1}}function downloadNote(e){let t=new XMLHttpRequest;t.onload=function(){if(200==t.status){let l=new Blob([t.response],{type:t.getResponseHeader("content-type")}),a=URL.createObjectURL(l),d=document.createElement("a");var e=t.getResponseHeader("Content-Disposition"),n=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/,o=n.exec(e);null!=o&&o[1]&&(filename=o[1].replace(/['"]/g,"")),d.href=a,d.download=filename,d.click(),setTimeout(function(){window.URL.revokeObjectURL(a)},100),loader.remove()}else{let e="Server Error! Download failed. Can't connect to server";console.error(e),rcmail.display_message(e,"error")}},t.onerror=function(){let e="Server Error! Download failed. Can't connect to server";console.error(e),rcmail.display_message(e,"error")},t.responseType="blob",t.open("GET",location.href+"&_action=getNote&_name="+e),t.send()}function tPreview(e=""){"show"===e||"edit"===e||(e=mde.isPreviewActive()?"edit":"show"),mde.isPreviewActive()?"edit"==e&&mde.togglePreview():"show"==e&&mde.togglePreview(),setTimeout(()=>{"show"==e?(document.querySelector(".preview").classList.add("active"),document.getElementById("headerTitle").classList.add("readOnly"),tagify.setReadonly(!0),document.querySelector(".tagify").classList.remove("taedit"),document.getElementById("author").readOnly=!0,document.getElementById("source").readOnly=!0,document.querySelector(".toc").classList.add("no-disable"),document.querySelector(".toc").removeAttribute("disabled")):(document.querySelector(".preview").classList.remove("active"),document.getElementById("headerTitle").classList.remove("readOnly"),tagify.setReadonly(!1),document.querySelector(".tagify").classList.add("taedit"),document.getElementById("author").readOnly=!1,document.getElementById("source").readOnly=!1,document.querySelector(".toc").classList.remove("no-disable"),document.querySelector(".toc").setAttribute("disabled",!0),document.getElementById("tocdiv")&&document.getElementById("tocdiv").classList.remove("tocShow"))},50)}function saveFile(){document.getElementById("main_area").appendChild(loader);let e=tagify.value,t=[];for(let n in e)t.push(e[n].value);const n={_oname:document.getElementById("fname").value,_content:mde.value(),_title:document.getElementById("headerTitle").value,_author:document.getElementById("author").value,_date:document.getElementById("date").dataset.tstamp,_updated:document.getElementById("updated").value,_source:document.getElementById("source").value,_tags:t};rcmail.http_post("saveNote",n,!1)}function togglemData(){document.getElementById("ndata").classList.toggle("mtoggle")}function loadNote(e){let t=window.location.protocol+"//"+window.location.host+window.location.pathname+"?_task=notes¬e="+e.note.filename;if(window.history.pushState({path:t},"",t),loader.remove(),screen.width<=480&&(document.getElementById("layout-list").classList.toggle("hidden"),document.getElementById("layout-content").classList.toggle("hidden")),document.getElementById("tocdiv")&&document.getElementById("tocdiv").remove(),document.getElementById("binobj")&&document.getElementById("binobj").remove(),tagify.removeAllTags(),document.getElementById("headerTitle").value=e.note.name,document.getElementById("ntags").value=e.note.tags,document.getElementById("author").value=e.note.author,document.getElementById("date").value=e.note.date,document.getElementById("date").dataset.tstamp=e.note.tstamp,document.getElementById("updated").value=e.note.updated,document.getElementById("source").value=e.note.source,document.getElementById("source").title=e.note.source,document.getElementById("fname").value=e.note.filename,document.querySelectorAll("#pnlist li").forEach(function(e){e.classList.remove("lselected")}),document.getElementById(e.note.id).classList.add("lselected"),0===e.note.mime_type.indexOf("text"))mde.value(e.note.content),document.querySelector(".EasyMDEContainer").classList.remove("mdeHide"),setTimeout(()=>{let e=document.querySelector(".CodeMirror").querySelectorAll("h1, h2, h3, h4, h5, h6"),t=document.querySelector(".toc");if(e.length>0){t.classList.add("no-disable");let n=document.createElement("div");n.id="tocdiv";let o=0,l=0,a="c%";e.forEach(function(e){l=e.tagName.substr(1,1),a=o
  • '+e.innerText+"
  • c%"):a.replace("c%",'
  • "):o>l?a.replace("c%",'
  • '+e.innerText+"
  • c%"):a.replace("c%",'
  • '+e.innerText+"
  • c%"),o=l}),a=a.replace("c%",""),n.innerHTML="

    "+rcmail.gettext("note_toc","primitivenotes")+"

    "+a+"
    ",document.querySelector(".EasyMDEContainer").appendChild(n),document.querySelectorAll("#tocdiv a").forEach(function(e){e.addEventListener("click",function(e){n.classList.toggle("tocShow")})})}else t.classList.remove("no-disable")},50),tagify.addTags(e.note.tags);else{document.querySelector(".EasyMDEContainer").classList.add("mdeHide");let t=document.createElement("div"),n=document.createElement("object");t.id="binobj",n.type=e.note.mime_type,n.data=e.note.content,n.classList.add("objcont"),t.classList.add("objdiv"),t.appendChild(n),document.getElementById("main_area").appendChild(t)}tPreview(e.mode),document.querySelectorAll(".hljs").forEach(function(e){e.addEventListener("click",function(){let e=this;navigator.clipboard.writeText(e.innerText).then(function(){let t=document.createElement("span");t.classList.add("success"),t.innerText="copied",e.appendChild(t),setTimeout(function(){t.remove()},1e3)},function(){console.error("Clipboard error")})})});let n=document.querySelectorAll(".editor-preview a.intlink");n.forEach(function(e){e.addEventListener("click",function(e){if(screen.width>480){e.preventDefault(),document.querySelector(".EasyMDEContainer").classList.add("mdeHide");let t=document.createElement("div"),n=document.createElement("object");t.id="binobj",n.data=e.target.attributes.href.nodeValue,n.classList.add("objcont"),t.classList.add("objdiv"),t.appendChild(n),document.getElementById("main_area").appendChild(t)}})})}function savedNote(e){document.getElementById("ndata").classList.remove("mtoggle"),loader.remove(),document.getElementById("notes-list").appendChild(loader);let t=["done","saved"];if(t.includes(e.message)){document.getElementById("pnlist").remove();const t=(new DOMParser).parseFromString(e.list,"text/html");document.getElementById("notes-list").appendChild(t.body.children[0])}document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),e.mfiles?confirm(e.mfiles.message)&&rcmail.http_post("delMedia","_media="+e.mfiles.files,!1):"saved"==e.message&&tPreview(),cContextMenu(),loader.remove()}function searchList(){var e,t,n,o,l;for(e=document.getElementById("notessearchform"),t=e.value.toUpperCase(),n=document.getElementById("pnlist"),o=n.getElementsByTagName("li"),l=0;l-1?o[l].style.display="":o[l].style.display="none"}function toggleTOC(){let e=document.getElementById("tocdiv");e&&e.classList.toggle("tocShow")}function showNote(e,t="show"){let n;document.getElementById("ndata").classList.remove("mtoggle");let o=["md","txt","html","jpg"],l=document.getElementById(e).dataset.format;screen.width>480||-1!=o.indexOf(l)?(document.getElementById("main_area").appendChild(loader),n={_name:document.getElementById(e).dataset.name,_id:e,_mode:t},rcmail.http_post("displayNote",n,!1)):downloadNote(document.getElementById(e).dataset.name)}function pnoptions(){location.href=window.location.origin+window.location.pathname+"?_task=settings&_action=preferences#pnotes"}function send_note(e){rcmail.goto_url("mail/compose",{_note_filename:e.name},!0)}function new_note(e){screen.width<=480&&(document.getElementById("layout-list").classList.toggle("hidden"),document.getElementById("layout-content").classList.toggle("hidden")),document.title=rcmail.env.nnote;let t=window.location.protocol+"//"+window.location.host+window.location.pathname+"?_task=notes";window.history.pushState({path:t},"",t),document.getElementById("headerTitle").placeholder=rcmail.gettext("note_title","primitivenotes"),document.querySelector(".tagify__input").dataset.placeholder="Tags",format=e||rcmail.env.dformat,mde.value(""),tPreview("edit"),document.getElementById("headerTitle").value="",document.getElementById("headerTitle").classList.remove("readOnly"),tagify.removeAllTags(),tagify.setReadonly(!1),document.querySelector(".tagify").classList.add("taedit"),document.getElementById("author").readOnly=!1,document.getElementById("author").value="",document.getElementById("source").readOnly=!1,document.getElementById("source").value="",document.getElementById("date").value="",document.getElementById("updated").value="",document.getElementById("fname").value="",document.querySelector(".toc").classList.remove("no-disable"),document.querySelector(".toc").setAttribute("disabled",!0),document.getElementById("tocdiv")&&document.getElementById("tocdiv").classList.remove("tocShow")}function add_note(){document.getElementById("upl").click()}function mform(){document.getElementById("main_area").appendChild(loader),fileName=this.value;let e=["pdf","jpg","jpeg","png"];if(e.includes(fileName.split(".").pop().toLowerCase())){let e=new FormData;e.append("dropFile",document.getElementById("dropMedia").files[0]);var t=new XMLHttpRequest;t.onload=(()=>{mde.codemirror.replaceSelection(t.responseText),loader.remove()}),t.open("POST",location.href+"&_action=uplMedia"),t.send(e)}else alert(rcmail.gettext("note_inv_format","primitivenotes"));return!1}function sform(){fileName=this.value;let e=fileName.split(".").pop().toLowerCase();if(rcmail.env.aformat.includes(e)){let e=new FormData(document.getElementById("upl_form"));const t=new XMLHttpRequest;t.onload=(()=>{document.getElementById("pnlist").remove();const e=(new DOMParser).parseFromString(t.response,"text/html").getElementById("pnlist");document.getElementById("notes-list").appendChild(e),loader.remove(),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),cContextMenu()}),t.open("POST",location.href+"&_action=uplNote"),t.send(e)}else alert(rcmail.gettext("note_inv_format","primitivenotes"));return!1}var mde,tagify,filelist=[],loader=document.createElement("div"),ldr=document.createElement("div");ldr.classList.add("db-spinner"),loader.classList.add("lbg"),loader.appendChild(ldr),window.rcmail&&rcmail.addEventListener("init",function(e){"notes"===new URLSearchParams(window.location.search).get("_task")?document.querySelector(".task-menu-button")&&document.querySelector(".task-menu-button").classList.add("notes"):document.querySelector(".task-menu-button")&&document.querySelector(".task-menu-button").classList.remove("notes"),document.getElementById("headerTitle").placeholder=rcmail.gettext("note_title","primitivenotes"),document.querySelector(".back-list-button")&&(document.getElementById("headerTitle").style.width="block"==window.getComputedStyle(document.querySelector(".back-list-button"),null).display?document.getElementById("headerTitle").style.width="calc(100% - 30px)":document.getElementById("headerTitle").style.width="calc(100% - 10px)"),mde=new EasyMDE({element:document.getElementById("editor1"),autoDownloadFontAwesome:!1,autofocus:!0,previewImagesInEditor:!1,spellChecker:!1,promptURLs:!0,inputStyle:"contenteditable",nativeSpellcheck:!0,forceSync:!1,sideBySideFullscreen:!1,iconsSet:"material",toolbar:[{name:"save",action:saveFile,title:"Save",className:"fa fa-floppy-disk"},"|","bold","italic","heading","clean-block","|","quote","code","unordered-list","ordered-list","|","link",{name:"media",action:uplMedia,title:"Insert Media",className:"fa fa-image"},"table","|",{name:"preview",action:tPreview,title:"Toggle Preview",className:"preview fa fa-eye no-disable"},"side-by-side",{name:"meta",action:togglemData,className:"fa fa-question-circle no-disable",title:"Metadata"},{name:"toc",action:toggleTOC,className:"fa fa-list-alt",title:"TOC",attributes:{disabled:"",id:"test"}}],shortcuts:{save:"Ctrl-S",preview:"Ctrl-P"},renderingConfig:{codeSyntaxHighlighting:!0,sanitizerFunction:function(e){let t=e.replaceAll(rcmail.env.mfolder+"/","?_task=notes&_action=blink&_file=");return t=t.replaceAll('a href="?_task','a class="intlink" href="?_task'),t=t.replaceAll("
    ",'
    '),t}}});let t=JSON.parse(rcmail.env.taglist);if(tagify=new Tagify(document.getElementById("ntags"),{whitelist:t,dropdown:{classname:"color-blue",trim:!0,enabled:0,maxItems:t.length,position:"text",closeOnSelect:!1,highlightFirst:!0},trim:!0,duplicates:!1,enforceWhitelist:!1,delimiters:",|;| "}),document.getElementById("notessearchform").addEventListener("keyup",searchList,!1),document.querySelectorAll("#pnlist li a").forEach(function(e){e.addEventListener("click",function(){showNote(e.parentElement.id,"show")})}),rcmail.addEventListener("plugin.loadNote",loadNote),rcmail.addEventListener("plugin.savedNote",savedNote),rcmail.addEventListener("plugin.getNote",downloadNote),cContextMenu(),rcmail.register_command("cCommand",cCommand,!0),rcmail.register_command("addnote",add_note,!0),rcmail.register_command("newnote",new_note,!0),rcmail.register_command("pnoptions",pnoptions,!0),document.getElementById("upl")&&document.getElementById("upl").addEventListener("change",sform,!1),document.getElementById("dropMedia")&&document.getElementById("dropMedia").addEventListener("change",mform,!1),"#pnotes"==window.location.hash&&rcmail.sections_list.select_row("primitivenotes"),document.getElementById("notes-list")){var n=!1;document.getElementById("notes-list").addEventListener("dragenter",function(e){e.preventDefault(),e.stopPropagation(),n=!0,setTimeout(function(){n=!1},1),document.getElementById("notes-list").classList.add("highlight")}),document.getElementById("notes-list").addEventListener("dragleave",function(e){e.preventDefault(),e.stopPropagation(),!1===n&&document.getElementById("notes-list").classList.remove("highlight")}),document.getElementById("notes-list").addEventListener("dragover",function(e){e.preventDefault(),e.stopPropagation()}),document.getElementById("notes-list").addEventListener("drop",function(e){e.preventDefault(),e.stopPropagation(),document.getElementById("notes-list").classList.remove("highlight"),manageDropUpload(e.dataTransfer.files)})}document.addEventListener("keyup",e=>{"Escape"==e.key&&(!1===mde.isPreviewActive()&&document.getElementById("notessearchform")!==document.activeElement&&""!==mde.value()&&tPreview("show"),document.getElementById("notessearchform")===document.activeElement&&(document.getElementById("notessearchform").value="",document.getElementById("notessearchform").dispatchEvent(new KeyboardEvent("keyup",{key:""})))),"KeyF"==e.code&&(e.ctrlKey||e.metaKey)&&document.getElementById("notessearchform").focus()}),document.getElementById("source").addEventListener("click",osource,!0),document.querySelector(".EasyMDEContainer").addEventListener("paste",pasteParse,!0);let o=new URLSearchParams(document.location.search).get("note");if(o){let e=null;document.querySelectorAll("#pnlist li").forEach((t,n,l)=>{t.dataset.name==o&&(e=t.id,l.length=n+1)});let t={_name:o,_id:e,_mode:"show"};rcmail.http_post("displayNote",t,!1)}});
    \ No newline at end of file
    diff --git a/primitivenotes.php b/primitivenotes.php
    index 152cf7e..5f28b14 100755
    --- a/primitivenotes.php
    +++ b/primitivenotes.php
    @@ -2,9 +2,9 @@
     /**
      * Roundcube Notes Plugin
      *
    - * @version 2.1.0
    + * @version 2.1.1
      * @author Offerel
    - * @copyright Copyright (c) 2021, Offerel
    + * @copyright Copyright (c) 2022, Offerel
      * @license GNU General Public License, version 3
      */
     class primitivenotes extends rcube_plugin{