11/**
22 * Roundcube Notes Plugin
33 *
4- * @version 2.0.1
4+ * @version 2.0.2
55 * @author Offerel
66 * @copyright Copyright (c) 2021, Offerel
77 * @license GNU General Public License, version 3
88 */
99$ ( document ) . ready ( function ( ) {
10- var tagify = new Tagify ( document . querySelector ( '#ntags' ) , {
10+ var tagify = new Tagify ( document . querySelector ( '#ntags' ) , {
1111 whitelist :[ ] ,
1212 dropdown : {
1313 classname : "color-blue" ,
@@ -40,7 +40,9 @@ $(document).ready(function(){
4040 spellChecker : false ,
4141 autofocus : true ,
4242 status : false ,
43- promptURLs : true ,
43+ promptURLs : true ,
44+ inputStyle : 'contenteditable' ,
45+ nativeSpellcheck : true ,
4446 //sideBySideFullscreen: false,
4547 renderingConfig : {
4648 codeSyntaxHighlighting : true ,
@@ -65,8 +67,7 @@ $(document).ready(function(){
6567 } ,
6668 'table' , '|' ,
6769 'preview' , 'side-by-side' , 'fullscreen' , 'guide' , '|' ] ,
68-
69- } ) ;
70+ } ) ;
7071
7172 document . querySelectorAll ( '#filelist li a' ) . forEach ( function ( note ) {
7273 note . addEventListener ( 'click' , function ( ) {
@@ -81,7 +82,7 @@ $(document).ready(function(){
8182 if ( 'ttags' in e . data && e . data . ttags == '' ) tagify . removeAllTags ( ) ;
8283 if ( 'editor' in e . data && e . data . editor == 'new' ) {
8384 if ( estate . value == 's' ) {
84- mde . togglePreview ( ) ;
85+ mde . togglePreview ( ) ;
8586 estate . value = 'e' ;
8687 }
8788 mde . value ( "" ) ;
@@ -93,6 +94,11 @@ $(document).ready(function(){
9394 document . querySelector ( '#main_area .editor-toolbar' ) . style . display = 'block' ;
9495 document . querySelector ( '.EasyMDEContainer' ) . style = 'display: block' ;
9596 mde . value ( '' ) ;
97+ editor1 . style = 'display: none;'
98+ document . getElementById ( 'author' ) . value = '' ;
99+ document . getElementById ( 'date' ) . value = '' ;
100+ document . getElementById ( 'source' ) . value = '' ;
101+ document . querySelector ( '#main_area .EasyMDEContainer' ) . addEventListener ( 'paste' , pasteParse , false ) ;
96102 } else {
97103 let toolbar = document . createElement ( 'div' ) ;
98104 toolbar . id = 'atoolbar' ;
@@ -112,7 +118,7 @@ $(document).ready(function(){
112118 }
113119 if ( 'editor' in e . data && e . data . editor == 'edit' ) {
114120 if ( estate . value == 's' ) {
115- mde . togglePreview ( ) ;
121+ mde . togglePreview ( ) ;
116122 estate . value = 'e' ;
117123 }
118124
@@ -175,6 +181,45 @@ $(document).ready(function(){
175181
176182 new rcube_splitter ( { id :'notessplitter' , p1 :'#sidebar' , p2 :'#main' , orientation :'v' , relative :true , start :400 , min :250 , size :12 } ) . init ( ) ;
177183
184+ function pasteParse ( event ) {
185+ const pastedText = event . clipboardData . getData ( 'text' ) ;
186+ const pastedHTML = event . clipboardData . getData ( 'text/html' ) ;
187+ let textArr = pastedText . split ( '\n' ) ;
188+ if ( textArr [ 0 ] == '---' ) {
189+ let cstart = pastedText . indexOf ( '---' , 4 ) + 3 ;
190+ for ( var i = 1 ; i < 10 ; i ++ ) {
191+ if ( textArr [ i ] == '---' ) break ;
192+ console . log ( textArr [ i ] ) ;
193+ let yentry = textArr [ i ] . split ( ':' ) ;
194+ if ( yentry [ 0 ] == 'title' ) document . getElementById ( 'note_name' ) . value = yentry [ 1 ] . trim ( ) ;
195+ if ( yentry [ 0 ] == 'tags' ) tagify . addTags ( yentry [ 1 ] ) ;
196+ if ( yentry [ 0 ] == 'author' ) document . getElementById ( 'author' ) . value = yentry [ 1 ] . trim ( ) ;
197+ if ( yentry [ 0 ] == 'date' ) document . getElementById ( 'date' ) . value = yentry . slice ( 1 ) . join ( ':' ) . trim ( ) ;
198+ if ( yentry [ 0 ] == 'source' ) document . getElementById ( 'source' ) . value = yentry . slice ( 1 ) . join ( ':' ) . trim ( ) ;
199+ }
200+ mde . value ( pastedText . substr ( cstart ) . trim ( ) ) ;
201+ }
202+
203+ if ( pastedHTML ) {
204+ var options = {
205+ headingStyle : 'atx' ,
206+ hr : '-' ,
207+ bulletListMarker : '-' ,
208+ codeBlockStyle : 'fenced' ,
209+ fence : '```' ,
210+ emDelimiter : '*' ,
211+ strongDelimiter : '**' ,
212+ linkStyle : 'inlined' ,
213+ linkReferenceStyle : 'full' ,
214+ collapseMultipleWhitespaces : true ,
215+ preformattedCode : true ,
216+ } ;
217+ var turndownService = new window . TurndownService ( options ) ;
218+ turndownService . keep ( [ 'kbd' , 'ins' ] ) ;
219+ mde . value ( turndownService . turndown ( pastedHTML ) ) ;
220+ }
221+ }
222+
178223 function firstNote ( ) {
179224 showNote ( document . getElementById ( 'filelist' ) . firstElementChild . classList [ 0 ] ) ;
180225 }
@@ -238,7 +283,6 @@ $(document).ready(function(){
238283 } ,
239284 success : function ( data ) {
240285 var note = JSON . parse ( data ) ;
241-
242286 if ( document . getElementById ( 'bcontent' ) ) document . getElementById ( 'bcontent' ) . remove ( ) ;
243287 document . querySelector ( '.EasyMDEContainer' ) . classList . remove ( 'EasyMDEContainerH' ) ;
244288 if ( document . getElementById ( 'tocdiv' ) ) document . getElementById ( 'tocdiv' ) . remove ( ) ;
@@ -251,6 +295,9 @@ $(document).ready(function(){
251295
252296 document . getElementById ( 'headerTitle' ) . innerText = note . notename ;
253297 document . getElementById ( 'fname' ) . value = note . filename ;
298+ document . getElementById ( 'author' ) . value = note . author ;
299+ document . getElementById ( 'date' ) . value = note . date ;
300+ document . getElementById ( 'source' ) . value = note . source ;
254301
255302 tagify . setReadonly ( true ) ;
256303 tagify . removeAllTags ( ) ;
@@ -377,6 +424,9 @@ $(document).ready(function(){
377424 ntags : tArr ,
378425 editor1 : mde . value ( ) ,
379426 ftype : fname . substr ( extb ) ,
427+ author : document . getElementById ( 'author' ) . value ,
428+ date : document . getElementById ( 'date' ) . value ,
429+ source : document . getElementById ( 'source' ) . value ,
380430 } ,
381431 success : function ( response ) {
382432 if ( response == '' ) {
0 commit comments