├── README.md └── plugins ├── Calculate.js ├── Custom page margin.js ├── Custom search scope.js ├── Custom table style.js ├── Edit with fillable form.js ├── Export records to CSV file.js ├── Insert checkbox.js ├── Insert quick text.js ├── Markdown2html.js ├── Markdownattach.js ├── Open folder location.js ├── README.md ├── Recover database.js ├── Save2QuickText.js ├── SetBackgroundColor.js ├── SetBackgroundImg.js ├── SetFontSize.js ├── Syntax highlight.js └── WordCount.js /README.md: -------------------------------------------------------------------------------- 1 | # myBase Plugins 2 | 3 | The .js files are **for myBase 7.x only**. 4 | 5 | > More information about myBase 7.x can be found in the following website: [http://www.wjjsoft.com/mybase.html](http://www.wjjsoft.com/mybase.html "myBase Website"). 6 | 7 | 8 | **Usage:** 9 | 1. Close the software 10 | 2. Copy the .js file to .\plugins sub folder. 11 | 3. Run the software again. 12 | 4. Based on the setting of the plugins, you can find the new functions from different menu. 13 | 5. More details can be found in myBase website: [http://www.wjjsoft.com/mybase_jsapi.html#install](http://www.wjjsoft.com/mybase_jsapi.html#install) 14 | 15 | **Note:** 16 | 1. There are self-developed plugins and the plugins developed by wjj. 17 | 2. Use the plugins **at your own risks**. 18 | 3. Please **fully test** before using to your productive data file. 19 | 4. Any question or problem, please raise an issue. 20 | 21 | -------------------------------------------------------------------------------- /plugins/Calculate.js: -------------------------------------------------------------------------------- 1 | 2 | //sValidation=nyfjs 3 | //sCaption=Calculate 4 | //sHint=Calculate 02072015 5 | //sCategory=MainMenu.TxtUtils 6 | //sPosition=XZ-255 7 | //sCondition=CURDB; DBRW; CURINFOITEM; HTMLEDIT; HTMLSELECTED 8 | //sID=p.gzhaha.Calculate 9 | //sAppVerMin=7.0 10 | //sShortcutKey= 11 | //sAuthor=Xia Zhang 12 | 13 | ///////////////////////////////////////////////////////////////////// 14 | // Extension scripts for myBase Desktop v7.x 15 | // Copyright 2015 Xia Zhang (MIT Licensed) 16 | ///////////////////////////////////////////////////////////////////// 17 | 18 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);}; 19 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);}; 20 | 21 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');}; 22 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');}; 23 | 24 | try{ 25 | var xNyf=new CNyfDb(-1); 26 | if(xNyf.isOpen()){ 27 | if(!xNyf.isReadonly()){ 28 | if(plugin.isContentEditable()){ 29 | 30 | 31 | //load math.js 32 | var xFn=new CLocalFile(plugin.getScriptFile()); 33 | var sDir=xFn.getDirectory(); 34 | xFn=new CLocalFile(sDir, 'math.js'); 35 | sCode=xFn.loadText(); 36 | 37 | if (sCode){ 38 | //get selected text from info item edit area 39 | var sCon = plugin.getSelectedText(-1, false); 40 | eval.call(null, sCode); 41 | 42 | //Calculate 43 | try{ 44 | //remove all space 45 | sCon1 = sCon.replace(/\s/g, '') 46 | 47 | //Rounding for four digits 48 | //var cResult = math.round(math.eval(sCon1)*10000)/10000; 49 | //11.01.2016 change to "toFixed", 4 is used to restrict the number digits 50 | var cResult = math.eval(sCon1).toFixed(4); 51 | var cFinal = sCon + " = " + cResult + ' '; 52 | plugin.replaceSelectedText(-1, cFinal, false); 53 | } 54 | catch(e){ 55 | alert(e); 56 | } 57 | }else{ 58 | alert('Component script file missing.'+'\n\n'+'math.js'); 59 | } 60 | }else{ 61 | alert(_lc('Prompt.Warn.ReadonlyContent', 'Cannot modify the content opened as Readonly.')); 62 | } 63 | }else{ 64 | alert(_lc('Prompt.Warn.ReadonlyDb', 'Cannot modify the database opened as Readonly.')); 65 | } 66 | }else{ 67 | alert(_lc('Prompt.Warn.NoDbOpened', 'No database is currently opened.')); 68 | } 69 | }catch(e){ 70 | alert(e); 71 | } 72 | -------------------------------------------------------------------------------- /plugins/Custom page margin.js: -------------------------------------------------------------------------------- 1 | 2 | //sValidation=nyfjs 3 | //sCaption=Custom page margin ... 4 | //sHint=Set the margin attributes for
of the page 5 | //sCategory=MainMenu.Paragraph 6 | //sPosition= 7 | //sCondition=CURDB; DBRW; CURINFOITEM; HTMLEDIT 8 | //sID=p.CustomPageMargins 9 | //sAppVerMin=7.0 10 | //sAuthor=wjjsoft 11 | 12 | ///////////////////////////////////////////////////////////////////// 13 | // Extension scripts for myBase Desktop v7.x 14 | // Copyright 2015 Wjj Software. All rights Reserved. 15 | // Website: www.wjjsoft.com Contact: info@wjjsoft.com 16 | ///////////////////////////////////////////////////////////////////// 17 | // This code is property of Wjj Software (WJJSOFT). You may not use it 18 | // for any commercial purpose without preceding consent from authors. 19 | ///////////////////////////////////////////////////////////////////// 20 | 21 | //11:20 9/24/2015 initial commit by wjj; 22 | //This plugin is used to set margin-left/right for element of the current HTML content; 23 | 24 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);}; 25 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);}; 26 | 27 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');}; 28 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');}; 29 | 30 | try{ 31 | var xNyf=new CNyfDb(-1); 32 | 33 | if(xNyf.isOpen()){ 34 | 35 | if(!xNyf.isReadonly()){ 36 | 37 | if(plugin.isContentEditable()){ 38 | 39 | var _unit_of=function(s){ 40 | //return (s||'').replace(/^([e\d\s]+)(?=em|px|pt|%$)/i, ''); 41 | return (s||'').replace(/^([e\d\s]+)(?=[a-z%]{0,2}$)/i, ''); 42 | }; 43 | 44 | var sCfgKey1='CustomPageMargins.Left', sCfgKey2='CustomPageMargins.Right'; 45 | 46 | var vVals=[ 47 | '|'+_lc('p.Common.Initial', 'Initial') 48 | , '0.2em', '0.4em', '0.6em', '0.8em', '1em', '1.2em', '1.4em', '1.6em', '1.8em', '2em', '2.5em', '3em', '4em', '5em' 49 | , '5px', '10px', '15px', '20px', '25px', '30px', '35px', '40px', '45px', '50px' 50 | ]; 51 | 52 | var sLeft0=''; 53 | { 54 | var sCode='cssUtil(document.body, "margin-left");'; 55 | sLeft0=plugin.runDomScript(-1, sCode); 56 | } 57 | 58 | var sRight0=''; 59 | { 60 | var sCode='cssUtil(document.body, "margin-right");'; 61 | sRight0=plugin.runDomScript(-1, sCode); 62 | } 63 | 64 | var vFields = [ 65 | {sField: "comboedit", sLabel: _lc2('Left', 'Left margin of page'), vItems: vVals, sInit: sLeft0||localStorage.getItem(sCfgKey1)||'', bReq: false} 66 | , {sField: "comboedit", sLabel: _lc2('Right', 'Right margin of page'), vItems: vVals, sInit: sRight0||localStorage.getItem(sCfgKey2)||'', bReq: false} 67 | ]; 68 | 69 | var vRes = input(plugin.getScriptTitle(), vFields, {nMinSize: 400, vMargins: [8, 0, 30, 0]}); 70 | if(vRes && vRes.length==2){ 71 | 72 | var sLeft=vRes[0], sRight=vRes[1]; 73 | 74 | localStorage.setItem(sCfgKey1, sLeft); 75 | localStorage.setItem(sCfgKey2, sRight); 76 | 77 | if(sLeft != '' && _unit_of(sLeft)=='') sLeft+='px'; 78 | if(sRight != '' && _unit_of(sRight)=='') sRight+='px'; 79 | 80 | var sCode='\n'+'g_xUndoStack.beginMacro("body margin");' 81 | + 'cssUtil(document.body, [{key: "margin-left", val: "%LEFT%"}, {key: "margin-right", val: "%RIGHT%"}]);' 82 | .replace(/%LEFT%/g, sLeft).replace(/%RIGHT%/g, sRight) 83 | + 'g_xUndoStack.endMacro();' 84 | ; 85 | if(plugin.runDomScript(-1, sCode)){ 86 | //done; 87 | } 88 | } 89 | 90 | }else{ 91 | alert(_lc('Prompt.Warn.ReadonlyContent', 'Cannot modify the content opened as Readonly.')); 92 | } 93 | 94 | }else{ 95 | alert(_lc('Prompt.Warn.ReadonlyDb', 'Cannot modify the database opened as Readonly.')); 96 | } 97 | 98 | }else{ 99 | alert(_lc('Prompt.Warn.NoDbOpened', 'No database is currently opened.')); 100 | } 101 | }catch(e){ 102 | alert(e); 103 | } 104 | -------------------------------------------------------------------------------- /plugins/Custom search scope.js: -------------------------------------------------------------------------------- 1 | 2 | //sValidation=nyfjs 3 | //sCaption=Custom search scope ... 4 | //sHint=Search for words or RegExp within a specified scope 5 | //sCategory=MainMenu.Search 6 | //sPosition= 7 | //sCondition=CURDB 8 | //sID=p.CustomSearch 9 | //sAppVerMin=7.0 10 | //sAuthor=wjjsoft 11 | 12 | ///////////////////////////////////////////////////////////////////// 13 | // Extension scripts for myBase Desktop v7.x 14 | // Copyright 2015 Wjj Software. All rights Reserved. 15 | // Website: www.wjjsoft.com Contact: info@wjjsoft.com 16 | ///////////////////////////////////////////////////////////////////// 17 | // This code is property of Wjj Software (WJJSOFT). You may not use it 18 | // for any commercial purpose without preceding consent from authors. 19 | ///////////////////////////////////////////////////////////////////// 20 | 21 | //17:28 9/24/2015 initial commit by wjj; 22 | //This plugin is used to run searches for words or RegExp with in a specified scope; 23 | //To search for RegExp, make sure to add a pair of slashes surrouding the find phrase, like this: /pattern/i 24 | 25 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);}; 26 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);}; 27 | 28 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');}; 29 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');}; 30 | 31 | var _scale_file_size=function(n){ 32 | var nKilo=1024; 33 | var nMega=nKilo*nKilo; 34 | var nGiga=nKilo*nKilo*nKilo; 35 | var s=''; 36 | if(n>=nGiga){ 37 | s=''+Math.floor(n/nGiga*10)/10+' GiB'; 38 | }else if(n>=nMega){ 39 | s=''+Math.floor(n/nMega*10)/10+' MiB'; 40 | }else if(n>=nKilo){ 41 | s=''+Math.floor(n/nKilo*10)/10+' KiB'; 42 | }else{ 43 | s=''+n+' B'; 44 | } 45 | return s; 46 | }; 47 | 48 | try{ 49 | 50 | var xNyf=new CNyfDb(-1); 51 | if(xNyf.isOpen()){ 52 | 53 | var sCfgKey1='CustomSearch.sPhrase', sCfgKey2='CustomSearch.iRange', sCfgKey3='CustomSearch.bTitles', sCfgKey4='CustomSearch.bContents', sCfgKey5='CustomSearch.bAttachments', sCfgKey6='CustomSearch.bAllDbs'; 54 | 55 | var vRange=[ 56 | _lc('p.Common.CurBranch', 'Current branch') 57 | , _lc('p.Common.CurDB', 'Current database') 58 | ]; 59 | 60 | var vScope=[ 61 | localStorage.getItem(sCfgKey3)+'|'+'Item titles' 62 | , localStorage.getItem(sCfgKey4)+'|'+'HTML contents' 63 | , localStorage.getItem(sCfgKey5)+'|'+'Attachments' 64 | ]; 65 | 66 | var vFields = [ 67 | {sField: "lineedit", sLabel: _lc2('Phrase', 'Search for words or RegExp (eg. /pattern/i ):'), sInit: localStorage.getItem(sCfgKey1)||'', bReq: true} 68 | , {sField: 'check', sLabel: 'Data scope:', vItems: vScope} 69 | , {sField: "combolist", sLabel: _lc2('Range', 'Outline scope:'), vItems: vRange, nInit: localStorage.getItem(sCfgKey2)||'', bReq: false} 70 | , {sField: 'check', sLabel: '', vItems: [localStorage.getItem(sCfgKey6)+'|'+'With all opened databases']} 71 | ]; 72 | 73 | var vRes = input(plugin.getScriptTitle(), vFields, {nMinSize: 540, vMargins: [8, 0, 30, 0], bVert: true}); 74 | if(vRes && vRes.length>=4){ 75 | 76 | var sFor=vRes[0], vChk=vRes[1], iRng=vRes[2], bAllDbs=vRes[3][0]; 77 | var bTitles=vChk[0], bContents=vChk[1], bAttachments=vChk[2]; 78 | 79 | sFor=_trim(sFor); 80 | 81 | localStorage.setItem(sCfgKey1, sFor); 82 | localStorage.setItem(sCfgKey2, iRng); 83 | localStorage.setItem(sCfgKey3, bTitles); 84 | localStorage.setItem(sCfgKey4, bContents); 85 | localStorage.setItem(sCfgKey5, bAttachments); 86 | localStorage.setItem(sCfgKey6, bAllDbs); 87 | 88 | if(bTitles || bContents || bAttachments){ 89 | 90 | plugin.initProgressRange(plugin.getScriptTitle(), 0); 91 | 92 | var mToScan={}; 93 | var sDefNoteFn=plugin.getDefNoteFn(); 94 | 95 | var nCountOfEntries=0; 96 | 97 | //2013.12.12 users reported the 'runtime error' that possibly came from Array.push(); 98 | //We encountered the similar problem within the epub making scripts; 99 | //Workaround: use the key-val map to substitute the Array; 100 | 101 | var _push=function(i, p, n){ 102 | var v=mToScan[i]; 103 | if(!v) v=mToScan[i]=[]; 104 | v[v.length]={sSsgPath: p, sSsgName: n}; 105 | nCountOfEntries++; 106 | }; 107 | 108 | var _load_entries=function(iDbPos){ 109 | var bBranch=(iRng==0), sCurItem=bBranch ? plugin.getCurInfoItem(iDbPos) : plugin.getDefRootContainer(); 110 | if(!sCurItem){ 111 | sCurItem=plugin.getDefRootContainer(); 112 | bBranch=false; 113 | } 114 | var xDb=new CNyfDb(iDbPos); 115 | xDb.traverseOutline(sCurItem, bBranch, function(sSsgPath, iLevel){ 116 | 117 | var sTitle=xDb.getFolderHint(sSsgPath); if(!sTitle) sTitle='Untitled'; 118 | 119 | var bContinue=plugin.ctrlProgressBar(sTitle+' ['+nCountOfEntries+']', 1, true); 120 | if(!bContinue){mToScan={}; return true;} 121 | 122 | if(bTitles){ 123 | _push(iDbPos, sSsgPath, ''); 124 | } 125 | 126 | if(bContents||bAttachments){ 127 | var vFiles=xDb.listFiles(sSsgPath); 128 | for(var i in vFiles){ 129 | var sSsgName=vFiles[i]; 130 | if(sSsgName==sDefNoteFn){ 131 | if(bContents) _push(iDbPos, sSsgPath, sSsgName); 132 | }else{ 133 | if(bAttachments) _push(iDbPos, sSsgPath, sSsgName); 134 | } 135 | } 136 | } 137 | }); 138 | }; 139 | 140 | if(bAllDbs){ 141 | var n=plugin.getDbCount(); 142 | while( n-- > 0 ) _load_entries(n); 143 | 144 | }else{ 145 | _load_entries(plugin.getCurDbIndex()); 146 | } 147 | 148 | var xRE=undefined; 149 | { 150 | //construct the xRE; 151 | var v=sFor.match(/^\/(.*)\/([igm]*)$/); 152 | if(v && v.length>1){ 153 | var sRE=v[1], sOpt=v[2]; 154 | if(sRE){ 155 | xRE=new RegExp(sRE, sOpt.replace(/g/gi, '')); //remove the redundant 'g'. 156 | } 157 | } 158 | } 159 | 160 | var _match_boolean=function(s){ 161 | var bOK=false; 162 | //To-do ... ?????????? 163 | return bOK; 164 | }; 165 | 166 | var _match=function(s){ 167 | var bOK=false, s=s.replace(/[\r\n]/g, ' '); 168 | if(xRE!=undefined){ 169 | bOK=s.match(xRE); 170 | } 171 | if(!bOK){ 172 | bOK=_match_boolean(s); 173 | } 174 | if(!bOK){ 175 | bOK=s.toLowerCase().indexOf(sFor.toLowerCase())>=0; 176 | } 177 | return bOK; 178 | }; 179 | 180 | var _findstr_to_hilite=function(s){ 181 | s=s||''; 182 | if(xRE!=undefined){ 183 | //2012.2.7 consider the regexp control words, like: /\bmain\b/i, that is to highlight 'main', rather than 'b' or 'i'; 184 | s=s.replace(/\\\w/g, ''); 185 | s=s.replace(/\/[igm]*$/g, ''); 186 | } 187 | s=s.replace(/[`~\!@#\$%\^&\*\(\)_\+\-=\[\]\\\{\}\|;\'\:\"\,\.\/<>\?\Z\A]/g, ' ').replace(/\s{2,}/g, ' '); 188 | return _trim(s); 189 | }; 190 | 191 | //2011.9.4 this is used for highlighting the search words; 192 | var sFindStr=_findstr_to_hilite(sFor); 193 | 194 | //plugin.runQuery({bListOut: true}); //make sure the Query-results window is open and cleared; 195 | 196 | plugin.initProgressRange(plugin.getScriptTitle(), nCountOfEntries); 197 | 198 | plugin.showResultsPane(true, true); 199 | plugin.setResultsPaneTitle(plugin.getScriptTitle()+' ['+sFor+']'); 200 | 201 | var nFound=0; 202 | for(var iDbPos in mToScan){ 203 | 204 | var vII=mToScan[iDbPos]; 205 | if(vII.length>0){ 206 | 207 | var xDb=new CNyfDb(parseInt(iDbPos)), sDbFn=xDb.getDbFile(); 208 | for(var i in vII){ 209 | 210 | var xII=vII[i]; 211 | var sSsgPath=xII.sSsgPath, sSsgName=xII.sSsgName, xSsgFn=new CLocalFile(sSsgPath, sSsgName); 212 | var sTitle=xDb.getFolderHint(sSsgPath)||''; 213 | var bDefNote=(sSsgName==sDefNoteFn); 214 | 215 | var nSize=xDb.getFileSize(xSsgFn, false); 216 | 217 | var bContinue=plugin.ctrlProgressBar( ((bDefNote?'':sSsgName)||sTitle||'Untitled')+' ['+_scale_file_size(nSize)+']', 1, true); 218 | if(!bContinue) break; 219 | 220 | var sTxt=''; 221 | if(sSsgName){ 222 | 223 | var sTxt=xDb.parseFile(sSsgPath, sSsgName, false); 224 | 225 | if(bDefNote){ 226 | //if(sTitle) sTxt=sTitle+'\n'+sTxt; 227 | }else{ 228 | //2013.10.21 take a look at filenames as well for attachments. 229 | sTxt=sSsgName+'\n'+sTxt; 230 | } 231 | 232 | var sHint=xDb.getFileHint(xSsgFn); 233 | if(sHint) sTxt+='\n'+sHint; 234 | }else{ 235 | //To scan item titles only; 236 | sTxt=sTitle; 237 | } 238 | 239 | if(sTxt && _match(sTxt)){ 240 | nFound++; 241 | plugin.appendToResults(sDbFn, sSsgPath, sSsgName, sFindStr); 242 | } 243 | } 244 | } 245 | } 246 | 247 | plugin.setResultsPaneTitle(plugin.getScriptTitle()+' ['+sFor+'] '+_lc('p.Common.Found', 'Found: (%nFound%)').replace(/%nFound%/g, ''+nFound)); 248 | } 249 | } 250 | 251 | }else{ 252 | alert(_lc('Prompt.Warn.NoDbOpened', 'No database is currently opened.')); 253 | } 254 | 255 | }catch(e){ 256 | alert(e); 257 | } 258 | -------------------------------------------------------------------------------- /plugins/Custom table style.js: -------------------------------------------------------------------------------- 1 | 2 | //sValidation=nyfjs 3 | //sCaption=Custom table style ... 4 | //sHint=Custom CSS properties for the current table 5 | //sCategory=MainMenu.Table; 6 | //sPosition=TBL-03-ATTR-03 7 | //sCondition=CURDB; DBRW; CURINFOITEM; HTMLEDIT; TABLE 8 | //sID=p.Table.CustomStyle 9 | //sAppVerMin=7.0 10 | //sShortcutKey= 11 | //sAuthor=wjjsoft 12 | 13 | ///////////////////////////////////////////////////////////////////// 14 | // Extension scripts for myBase Desktop v7.x 15 | // Copyright 2015 Wjj Software. All rights Reserved. 16 | // Website: www.wjjsoft.com Contact: info@wjjsoft.com 17 | ///////////////////////////////////////////////////////////////////// 18 | // This code is property of Wjj Software (WJJSOFT). You may not use it 19 | // for any commercial purpose without preceding consent from authors. 20 | ///////////////////////////////////////////////////////////////////// 21 | 22 | //17:11 8/6/2015 Initial commit by wjj; 23 | //This plugin is intended for sophisticated (IT) users to edit CSS properties for the current table with in a fillable form. 24 | //For a full list of CSS properties, see: http://www.w3.org/TR/CSS21/propidx.html 25 | 26 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);}; 27 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);}; 28 | 29 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');}; 30 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');}; 31 | 32 | try{ 33 | var xNyf=new CNyfDb(-1); 34 | 35 | if(xNyf.isOpen()){ 36 | 37 | if(!xNyf.isReadonly()){ 38 | 39 | if(plugin.isContentEditable()){ 40 | 41 | var _unserialize_style=function(sCss){ 42 | var v2=sCss.split(';'), xCss={}; 43 | for(var i in v2){ 44 | var a=_trim(v2[i]||''); 45 | var p=a.indexOf(':'); 46 | if(p>0){ 47 | var key=_trim(a.substr(0, p)), val=_trim(a.substr(p+1)); 48 | if(key){ 49 | xCss[key]=val; 50 | } 51 | } 52 | } 53 | return xCss; 54 | }; 55 | 56 | var _add_prop=function(vCss, k, v){ 57 | if(vCss && vCss.length!=undefined && k){ 58 | var bFound=false; 59 | for(var i in vCss){ 60 | if(vCss[i].sKey==k){ 61 | vCss[i].sVal=v; 62 | bFound=true; 63 | } 64 | } 65 | if(!bFound) vCss.push({sKey: k, sVal: v}); 66 | } 67 | }; 68 | 69 | var vWidths=[ 70 | '|'+_lc('p.Common.Default', 'Default') 71 | , '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%' 72 | , '100%|'+'100% (Full)' 73 | , '10pt', '20pt', '30pt', '40pt', '50pt', '60pt', '70pt', '80pt', '90pt' 74 | , '100pt', '150pt', '200pt', '250pt', '300pt', '350pt', '400pt', '450pt' 75 | , '500pt', '550pt', '600pt', '650pt', '700pt', '750pt', '800pt', '850pt' 76 | , '900pt', '950pt', '1000pt' 77 | , '10px', '20px', '30px', '40px', '50px', '60px', '70px', '80px', '90px' 78 | , '100px', '150px', '200px', '250px', '300px', '350px', '400px', '450px' 79 | , '500px', '550px', '600px', '650px', '700px', '750px', '800px', '850px' 80 | , '900px', '950px', '1000px' 81 | ]; 82 | 83 | var sCode='var xTbl=curTable(); cssUtil(xTbl)||"";'; 84 | var sCss=plugin.runDomScript(-1, sCode)||''; 85 | 86 | var vFields=[], vCss=[]; 87 | 88 | var xCss=_unserialize_style(sCss); 89 | for(var k in xCss){ 90 | var v=k ? xCss[k] : ''; 91 | if(k && v){ 92 | var f={sField: 'lineedit', sLabel: k, sInit: v||'', bReq: false}; 93 | if(k=='width'){ 94 | f.sField='comboedit'; 95 | f.vItems=vWidths; 96 | }else if(k.indexOf('-color')>0){ 97 | f.sField='color'; 98 | } 99 | vFields.push(f); 100 | _add_prop(vCss, k, v); 101 | } 102 | } 103 | 104 | vFields.push({sField: 'lineedit', sLabel: _lc2('AddProp', '* Add CSS properties *'), sInit: '', bReq: false}); 105 | 106 | var vRes = input(plugin.getScriptTitle(), vFields, {nMinSize: 500, vMargins: [8, 0, 30, 0]}); 107 | if(vRes && vRes.length>1){ 108 | 109 | for(var i=0; i, ) in source code
35 |
36 | //17:47 6/7/2015
37 | //bugfix with < > operators in source code
38 |
39 | //2015.6.8 by gzhaha
40 | //added Delphi, Pig Latin, Bash
41 |
42 | //11:41 6/9/2015
43 | //added Cpp/Qt
44 | //deal with HTML entities in source code ( , &, , ...)
45 |
46 | //12:24 6/10/2015
47 | //removed the 'HTMLSELECTED' requirement, so it can handle all content in HTML editor without having to first select all lines;
48 |
49 | //2015.6.11 by gzhaha
50 | //add js+myBase
51 |
52 | //2015.6.12 by gzhaha
53 | //add: substitute for $ character, the issue is related to parse '$' in source code
54 | //add: substitute for the \ character, the issue is related to parse \\ in source code.
55 |
56 | //2015.6.14 by gzhaha
57 | //add: Pascal
58 |
59 | //2015.6.15 by gzhaha
60 | //add: support multi sets of symbols for block comment.
61 |
62 | //16:46 6/15/2015
63 | //updates: added the data structure {start: '', end: ''} to store pairs of block-level remark tags;
64 |
65 | //18:28 6/16/2015
66 | //support of objc & RegExp for reversed tags;
67 |
68 | //12:00 6/18/2015
69 | //added Apple Swift;
70 |
71 | //17:34 6/29/2015
72 | //custom font-family/size for ;
73 |
74 | //17:25 8/17/2015
75 | //bugfix: The '<' operator not working in remark blocks;
76 | //added a safe method to generate the special tags for '<>&...', in case that they could appear in source code, e.g. the script itself;
77 |
78 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);};
79 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);};
80 |
81 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');};
82 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');};
83 |
84 | try{
85 | var xNyf=new CNyfDb(-1);
86 |
87 | if(xNyf.isOpen()){
88 |
89 | if(!xNyf.isReadonly() && plugin.isContentEditable()){
90 |
91 | var c_sFontSize='10pt';
92 | var c_sFontName='Lucida Console, Courier New';
93 |
94 | var c_sColorNormal='#000000';
95 | var c_sColorRemarks='#008000';
96 | var c_sColorStrings='#800080';
97 | var c_sColorNumbers='#ff0000';
98 |
99 | var c_sColorKeywords='#0000ff';
100 |
101 | var c_sColorReservedTags1='#8000ff';
102 | var c_sColorReservedTags2='#004080';
103 | var c_sColorReservedTags3='#ff8000';
104 | var c_sColorReservedTags4='#0080c0';
105 | var c_sColorReservedTags5='#ff007f';
106 | var c_sColorReservedTags6='#ff5500';
107 | var c_sColorReservedTags7='#ff557f';
108 |
109 | var sTags_Cpp=
110 | //for C++ Macros
111 | 'include,defined,define,ifdef,endif,elif,pragma,null'
112 |
113 | //for C (ISO/ANSI C90)
114 | + ',auto,break,case,char,const,continue,default,do,double,else,enum,extern'
115 | + ',float,for,goto,if,inline,int,long,register,restrict,return'
116 | + ',short,signed,sizeof,static,struct,switch,typedef'
117 | + ',union,unsigned,void,volatile,while'
118 |
119 | //for C (ISO/ANSI C99 appendix)
120 | + ',_Bool,_Complex,_Imaginary'
121 |
122 | //for C++
123 | + ',and,and_eq,asm,bitand,bitor,bool,catch,class,compl'
124 | + ',const_cast,delete,dynamic_cast,explicit,export,false,friend'
125 | + ',mutable,namespace,new,not,not_eq,operator,or,or_eq'
126 | + ',private,protected,public,reinterpret_cast,static_cast'
127 | + ',template,this,throw,true,try,typeid,typename,using'
128 | + ',wchar_t,virtual,xor,xor_eq'
129 |
130 | //for C++0x
131 | + ',alignof,char16_t,char32_t,constexpr,decltype,noexcept,nullptr'
132 | + ',static_assert,thread_local'
133 | ;
134 |
135 | var sTags_Stl=
136 | 'std,exception'
137 | + ',string,list,vector,stack,pair,map,set,multimap,multiset,queue,deque'
138 | + ',priority_queue,bitset,valarray'
139 | + ',cin,cout,cerr,clog,wcin,wcout,wcerr,wclog'
140 | + ',ios,fstream,wfstream,ifstream,wifstream,ofstream,wofstream'
141 | + ',istream,wistream,ostream,wostream,streambuf,wstreambuf'
142 | + ',stringstream,wstringstream,istringstream,wistringstream,ostringstream,wostringstream'
143 | + ',strstream,istrstream,wistrstream,ostrstream,wostrstream'
144 | + ',iterator,const_iterator,reverse_iterator,const_reverse_iterator'
145 | + ',back_insert_iterator,front_insert_iterator,insert_iterator'
146 | + ',istream_iterator,ostream_iterator,istreambuf_iterator,ostreambuf_iterator'
147 | ;
148 |
149 | var sTags_Qt=
150 | + 'qint8|qint16|qint32|qint64|qlonglong|qptrdiff|qreal|quint8|quint16|quint32|quint64|quintptr|qulonglong|uchar|uint|ulong|ushort'
151 | + '|QT_\\w\+|Q_\\w\+' //global Macros
152 | + '|q[A-Z]\\w\+|qgetenv|qputenv|qrand|qsrand|qtTrId' //gloabl Functions
153 | + '|Q\\w\+' //Qt widgets/classes
154 | ;
155 |
156 | var sTags_Java=
157 | 'abstract,boolean,break,byte,case,catch,char,class,continue,default'
158 | + ',do,double,else,enum,extends,false,final,finally,float,for'
159 | + ',if,implements,import,instanceof,int,interface,long,native,new,null'
160 | + ',package,private,protected,public,return,short,static,strictfp,super,switch'
161 | + ',synchronized,this,throw,throws,transient,true,try,void,volatile,while'
162 | + ',const,goto'
163 | ;
164 |
165 | var sTags_CSharp=
166 | 'abstract,event,new,struct,as,explicit,null,switch,base,extern,object,this'
167 | + ',bool,false,operator,throw,break,finally,out,true,byte,fixed,override,try'
168 | + ',case,float,params,typeof,catch,for,private,uint,char,foreach,protected,ulong'
169 | + ',class,if,readonly,unsafe,const,implicit,ref,ushort,continue,in,return,using'
170 | + ',decimal,int,sbyte,virtual,default,interface,sealed,volatile,delegate,internal,short,void'
171 | + ',do,is,sizeof,while,double,lock,stackalloc,else,long,static,enum,namespace,string'
172 | ;
173 |
174 | var sTags_JS=
175 | //js keywords
176 | 'break,case,catch,continue,default,delete,do,else,finally,for,function'
177 | + ',if,in,instanceof,new,return,switch,this,throw,try,typeof,var,void,while,with'
178 |
179 | //js reserved
180 | + ',abstract,boolean,byte,char,class,const,debugger,double,enum,export'
181 | + ',extends,final,float,goto,implements,import,int,interface,long,native'
182 | + ',package,private,protected,public,short,static,super,synchronized'
183 | + ',throws,transient,volatile'
184 |
185 | //js classes
186 | + ',Array,Boolean,Date,Math,Number,String,RegExp,Functions,Events'
187 | ;
188 |
189 | var sTags_JSConst=
190 | //JS window constants
191 | 'null,undefined,NaN,E,PI,SQRT2,SQRT1_2,LN2,LN10,LOG2E,LOG10E'
192 |
193 | var sTags_JSDom=
194 | //JS DOM objects
195 | 'window,self,document,navigator,screen,history,location,alert,confirm,prompt,Infinity,java,Packages'
196 |
197 | var sTags_JSEvent=
198 | //JS DOM events
199 | 'onabort,onblur,onchange,onclick,ondblclick,onerror,onfocus,onkeydown,onkeypress,onkeyup,onload'
200 | + ',onmousedown,onmousemove,onmouseout,onmouseover,onmouseup,onreset,onresize,onselect,onsubmit,onunload'
201 |
202 | var sTags_HTML=
203 | '!DOCTYPE,a,abbr,acronym,address,applet,area,b,base,basefont,bdo,big'
204 | + ',blockquote,body,br,button,caption,center,cite,code,col,colgroup,dd,del'
205 | + ',dir,div,dfn,dl,em,fieldset,font,form,frame,frameset,h1,h2,h3,h4,h5,h6,h7,h8'
206 | + ',head,hr,html,i,iframe,img,input,ins,isindex,kbd,label,legend,li,link,map'
207 | + ',menu,meta,noframes,noscript,object,ol,optgroup,option,p,param,pre,q,s'
208 | + ',samp,script,select,small,span,strike,strong,style,sub,sup,table,tbody'
209 | + ',td,textarea,tfoot,th,thead,title,tr,tt,u,ul,var,xmp'
210 | ;
211 |
212 | var sTags_Sql=
213 | 'add,exit,primary'
214 | + ',all,fetch,print'
215 | + ',alter,file,privileges'
216 | + ',and,fillfactor,proc'
217 | + ',any,floppy,procedure'
218 | + ',as,for,processexit'
219 | + ',asc,foreign,public'
220 | + ',authorization,freetext,raiserror'
221 | + ',avg,freetexttable,read'
222 | + ',backup,from,readtext'
223 | + ',begin,full,reconfigure'
224 | + ',between,goto,references'
225 | + ',break,grant,repeatable'
226 | + ',browse,group,replication'
227 | + ',bulk,having,restore'
228 | + ',by,holdlock,restrict'
229 | + ',cascade,identity,return'
230 | + ',case,identity_insert,revoke'
231 | + ',check,identitycol,right'
232 | + ',checkpoint,if,rollback'
233 | + ',close,in,rowcount'
234 | + ',clustered,index,rowguidcol'
235 | + ',coalesce,inner,rule'
236 | + ',column,insert,save'
237 | + ',commit,intersect,schema'
238 | + ',committed,into,select'
239 | + ',compute,is,serializable'
240 | + ',confirm,isolation,session_user'
241 | + ',constraint,join,set'
242 | + ',contains,key,setuser'
243 | + ',containstable,kill,shutdown'
244 | + ',continue,left,some'
245 | + ',controlrow,level,statistics'
246 | + ',convert,like,sum'
247 | + ',count,lineno,system_user'
248 | + ',create,load,table'
249 | + ',cross,max,tape'
250 | + ',current,min,temp'
251 | + ',current_date,mirrorexit,temporary'
252 | + ',current_time,national,textsize'
253 | + ',current_timestamp,nocheck,then'
254 | + ',current_user,nonclustered,to'
255 | + ',cursor,not,top'
256 | + ',database,null,tran'
257 | + ',dbcc,nullif,transaction'
258 | + ',deallocate,of,trigger'
259 | + ',declare,off,truncate'
260 | + ',default,offsets,tsequal'
261 | + ',delete,on,uncommitted'
262 | + ',deny,once,union'
263 | + ',desc,only,unique'
264 | + ',disk,open,update'
265 | + ',distinct,opendatasource,updatetext'
266 | + ',distributed,openquery,use'
267 | + ',double,openrowset,user'
268 | + ',drop,option,values'
269 | + ',dummy,or,varying'
270 | + ',dump,order,view'
271 | + ',else,outer,waitfor'
272 | + ',end,over,when'
273 | + ',errlvl,percent,where'
274 | + ',errorexit,perm,while'
275 | + ',escape,permanent,with'
276 | + ',except,pipe,work'
277 | + ',exec,plan,writetext'
278 | + ',execute,precision'
279 | + ',exists,prepare'
280 | ;
281 |
282 | var sTags_Php=
283 | 'and,or,xor,__FILE__,exception'
284 | + ',__LINE__,array,as,break,case'
285 | + ',class,const,continue,declare,default'
286 | + ',die,do,echo,else,elseif'
287 | + ',empty,enddeclar,endfor,endforeach,endif'
288 | + ',endswitch,endwhile,eval,exit,extends'
289 | + ',for,foreach,function,global,if'
290 | + ',include,include_once,isset,list,new'
291 | + ',print,require,require_once,return,static'
292 | + ',switch,unset,use,var,while'
293 | + ',__FUNCTION__,__CLASS__,__METHOD__,final,php_user_filter'
294 | + ',interface,implements,extends,public,private'
295 | + ',protected,abstract,clone,try,catch'
296 | + ',throw,cfunction,this'
297 | ;
298 |
299 | //2012.7.19 added for R-language;
300 | //2015.6.7 add more keywords by gzhaha
301 | var sTags_R=
302 | 'break,else,for,function,if,TRUE,in'
303 | + ',next,repeat,return,while,FALSE,switch'
304 | + ',NULL,NA,NaN,NA_integer_,NA_real_,NA_complex_,NA_character_'
305 | ;
306 |
307 | //2012.7.19 added for Google GO
308 | //https://golang-china.googlecode.com/svn/trunk/Chinese/golang.org/index.html
309 | var sTags_Go=
310 | 'package,import,func,const,var,for'
311 | + ',if,else,switch,case,default,select,return,break,continue'
312 | + ',range,map,type,struct,interface,new,go,defer'
313 | + ',byte,int,string,uint32,uint64,float32,float64'
314 | + ',nil,true,false'
315 | ;
316 |
317 | //2012.7.27 added for Visual Basic;
318 | //http://msdn.microsoft.com/en-us/library/ksh7h19t%28v=vs.80%29.aspx
319 | var sTags_VB_Reserved=
320 | 'AddHandler,AddressOf,Alias,And,AndAlso,As,Boolean,ByRef,Byte,ByVal'
321 | + ',Call,Case,Catch,CBool,CByte,CChar,CDate,CDec,CDbl,Char,CInt,Class'
322 | + ',CLng,CObj,Const,Continue,CSByte,CShort,CSng,CStr,CType,CUInt,CULng'
323 | + ',CUShort,Date,Decimal,Declare,Default,Delegate,Dim,DirectCast,Do'
324 | + ',Double,Each,Else,ElseIf,End,EndIf,Enum,Erase,Error,Event,Exit,False'
325 | + ',Finally,For,Friend,Function,Get,GetType,Global,GoSub,GoTo,Handles,If'
326 | + ',Implements,Imports,In,Inherits,Integer,Interface,Is,IsNot,Let,Lib,Like'
327 | + ',Long,Loop,Me,Mod,Module,MustInherit,MustOverride,MyBase,MyClass,Namespace'
328 | + ',Narrowing,New,Next,Not,Nothing,NotInheritable,NotOverridable,Object,Of,On'
329 | + ',Operator,Option,Optional,Or,OrElse,Overloads,Overridable,Overrides,ParamArray'
330 | + ',Partial,Private,Property,Protected,Public,RaiseEvent,ReadOnly,ReDim,REM,RemoveHandler'
331 | + ',Resume,Return,SByte,Select,Set,Shadows,Shared,Short,Single,Static,Step,Stop'
332 | + ',String,Structure,Sub,SyncLock,Then,Throw,To,True,Try,TryCast,TypeOf,Variant'
333 | + ',Wend,UInteger,ULong,UShort,Using,When,While,Widening,With,WithEvents,WriteOnly'
334 | + ',Xor,#Const,#Else,#ElseIf,#End,#If'
335 | ;
336 |
337 | var sTags_VB_Unreserved=
338 | 'Ansi,Assembly,Auto,Binary,Compare,Custom,Explicit,IsFalse,IsTrue,Mid,Off'
339 | + ',Preserve,Strict,Text,Unicode,Until,#ExternalSource,#Region'
340 | ;
341 |
342 | //2015.6.6 added for Python by gzhaha;
343 | //https://docs.python.org/2/library/functions.html
344 | var sTags_Python=
345 | 'abs,all,any,apply,basestring,bin,bool,buffer,callable'
346 | + ',chr,classmethod,cmp,coerce,compile,complex,delattr,dict,dir'
347 | + ',divmod,enumerate,eval,execfile,file,filter,float,format,frozenset'
348 | + ',getattr,globals,hasattr,hash,help,hex,id,input,int,intern'
349 | + ',isinstance,issubclass,iter,len,list,locals,long,map,max,min,next'
350 | + ',object,oct,open,ord,pow,print,property,range,raw_input,reduce'
351 | + ',reload,repr,reversed,round,set,setattr,slice,sorted,staticmethod'
352 | + ',str,sum,super,tuple,type,type,unichr,unicode,vars,xrange,zip,__import__'
353 | ;
354 |
355 | //2015.6.6 added for Python by gzhaha;
356 | var sTags_Pythonkw=
357 | 'and,as,assert,break,class,continue,def,del,elif,else'
358 | + ',except,exec,finally,for,from,global,if,import,in,is'
359 | + ',lambda,not,or,pass,print,raise,return,try,while,with,yield'
360 | ;
361 |
362 | //2015.6.6 added for Perl by gzhaha;
363 | //http://perldoc.perl.org/index-functions.html
364 | var sTags_Perl=
365 | 'abs,accept,alarm,atan2,bind,binmode,chdir,chmod,chomp,chop,chown,chr'
366 | + ',chroot,close,closedir,connect,cos,crypt,defined,delete,each,endgrent'
367 | + ',endhostent,endnetent,endprotoent,endpwent,endservent,eof,exec,exists'
368 | + ',exp,fcntl,fileno,flock,fork,format,formline,getc,getgrent,getgrgid'
369 | + ',getgrnam,gethostbyaddr,gethostbyname,gethostent,getlogin,getnetbyaddr'
370 | + ',getnetbyname,getnetent,getpeername,getpgrp,getppid,getpriority'
371 | + ',getprotobyname,getprotobynumber,getprotoent,getpwent,getpwnam,getpwuid'
372 | + ',getservbyname,getservbyport,getservent,getsockname,getsockopt,glob'
373 | + ',gmtime,grep,hex,index,int,ioctl,join,keys,kill,lc,lcfirst,length,link'
374 | + ',listen,localtime,lock,log,lstat,map,mkdir,msgctl,msgget,msgrcv,msgsnd'
375 | + ',oct,open,opendir,ord,pack,pipe,pop,pos,print,printf,prototype,push'
376 | + ',quotemeta,rand,read,readdir,readline,readlink,readpipe,recv,rename'
377 | + ',reset,reverse,rewinddir,rindex,rmdir,scalar,seek,seekdir,select,semctl'
378 | + ',semget,semop,send,setgrent,sethostent,setnetent,setpgrp,setpriority'
379 | + ',setprotoent,setpwent,setservent,setsockopt,shift,shmctl,shmget,shmread'
380 | + ',shmwrite,shutdown,sin,sleep,socket,socketpair,sort,splice,split,sprintf'
381 | + ',sqrt,srand,stat,study,substr,symlink,syscall,sysopen,sysread,sysseek'
382 | + ',system,syswrite,tell,telldir,time,times,tr,truncate,uc,ucfirst,umask'
383 | + ',undef,unlink,unpack,unshift,utime,values,vec,wait,waitpid,warn,write'
384 | ;
385 |
386 | var sTags_Perlkw=
387 | 'bless,caller,continue,dbmclose,dbmopen,die,do,dump,else,elsif,eval,exit'
388 | + ',for,foreach,goto,if,import,last,local,my,next,no,our,package,redo,ref'
389 | + ',require,return,sub,tie,tied,unless,untie,until,use,wantarray,while'
390 | ;
391 |
392 | //2015.6.7 added for ActionScript by gzhaha;
393 | //http://help.adobe.com/zh_CN/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9b.html
394 | var sTags_ActionScript=
395 | 'as,break,case,catch,class,const,default,delete,do,else,extends,finally'
396 | + ',for,function,if,implements,import,in,instanceof,interface,internal,is'
397 | + ',native,new,null,package,private,protected,public,return,super,switch,this'
398 | + ',throw,try,typeof,use,var,void,while,with,dynamic,each,final,get,include'
399 | + ',namespace,native,override,set,static'
400 | ;
401 |
402 | //2015.6.7 added for Ruby by gzhaha;
403 | var sTags_Ruby=
404 | 'alias,and,BEGIN,begin,break,case,class,def,define_method,defined,do,each,else,elsif'
405 | + ',END,end,ensure,false,for,if,in,module,new,next,nil,not,or,raise,redo,rescue,retry,return'
406 | + ',self,super,then,throw,true,undef,unless,until,when,while,yield'
407 | ;
408 |
409 | var sTags_RubyBI=
410 | 'Array,Bignum,Binding,Class,Continuation,Dir,Exception,FalseClass,File::Stat,File,Fixnum,Fload'
411 | +',Hash,Integer,IO,MatchData,Method,Module,NilClass,Numeric,Object,Proc,Range,Regexp,String,Struct::TMS,Symbol'
412 | +',ThreadGroup,Thread,Time,TrueClass'
413 | ;
414 |
415 | //2015.6.8 added for Delphi by gzhaha;
416 | var sTags_Delphi=
417 | 'abs,addr,and,ansichar,ansistring,array,as,asm,begin,boolean,byte,cardinal'
418 | +',case,char,class,comp,const,constructor,currency,destructor,div,do,double'
419 | +',downto,else,end,except,exports,extended,false,file,finalization,finally'
420 | +',for,function,goto,if,implementation,in,inherited,int64,initialization'
421 | +',integer,interface,is,label,library,longint,longword,mod,nil,not,object'
422 | +',of,on,or,packed,pansichar,pansistring,pchar,pcurrency,pdatetime,pextended'
423 | +',pint64,pointer,private,procedure,program,property,pshortstring,pstring'
424 | +',pvariant,pwidechar,pwidestring,protected,public,published,raise,real,real48'
425 | +',record,repeat,set,shl,shortint,shortstring,shr,single,smallint,string,then'
426 | +',threadvar,to,true,try,type,unit,until,uses,val,var,varirnt,while,widechar'
427 | +',widestring,with,word,write,writeln,xor'
428 | ;
429 |
430 | //2015.6.8 added for Pig Latin by gzhaha;
431 | var sTags_PigLatin=
432 | 'ABS,ACOS,ARITY,ASIN,ATAN,AVG,BAGSIZE,BINSTORAGE,BLOOM,BUILDBLOOM,CBRT,CEIL'
433 | + ',CONCAT,COR,COS,COSH,COUNT,COUNT_STAR,COV,CONSTANTSIZE,CUBEDIMENSIONS,DIFF,DISTINCT,DOUBLEABS'
434 | + ',DOUBLEAVG,DOUBLEBASE,DOUBLEMAX,DOUBLEMIN,DOUBLEROUND,DOUBLESUM,EXP,FLOOR,FLOATABS,FLOATAVG'
435 | + ',FLOATMAX,FLOATMIN,FLOATROUND,FLOATSUM,GENERICINVOKER,INDEXOF,INTABS,INTAVG,INTMAX,INTMIN'
436 | + ',INTSUM,INVOKEFORDOUBLE,INVOKEFORFLOAT,INVOKEFORINT,INVOKEFORLONG,INVOKEFORSTRING,INVOKER'
437 | + ',ISEMPTY,JSONLOADER,JSONMETADATA,JSONSTORAGE,LAST_INDEX_OF,LCFIRST,LOG,LOG10,LOWER,LONGABS'
438 | + ',LONGAVG,LONGMAX,LONGMIN,LONGSUM,MAX,MIN,MAPSIZE,MONITOREDUDF,NONDETERMINISTIC,OUTPUTSCHEMA'
439 | + ',PIGSTORAGE,PIGSTREAMING,RANDOM,REGEX_EXTRACT,REGEX_EXTRACT_ALL,REPLACE,ROUND,SIN,SINH,SIZE'
440 | + ',SQRT,STRSPLIT,SUBSTRING,SUM,STRINGCONCAT,STRINGMAX,STRINGMIN,STRINGSIZE,TAN,TANH,TOBAG'
441 | + ',TOKENIZE,TOMAP,TOP,TOTUPLE,TRIM,TEXTLOADER,TUPLESIZE,UCFIRST,UPPER,UTF8STORAGECONVERTER'
442 | ;
443 |
444 | var sTags_PigLatinKW=
445 | 'VOID,IMPORT,RETURNS,DEFINE,LOAD,FILTER,FOREACH,ORDER,CUBE,DISTINCT,COGROUP'
446 | + ',JOIN,CROSS,UNION,SPLIT,INTO,IF,OTHERWISE,ALL,AS,BY,USING,INNER,OUTER,ONSCHEMA,PARALLEL'
447 | + ',PARTITION,GROUP,AND,OR,NOT,GENERATE,FLATTEN,ASC,DESC,IS,STREAM,THROUGH,STORE,MAPREDUCE'
448 | + ',SHIP,CACHE,INPUT,OUTPUT,STDERROR,STDIN,STDOUT,LIMIT,SAMPLE,LEFT,RIGHT,FULL,EQ,GT,LT,GTE,LTE'
449 | + ',NEQ,MATCHES,TRUE,FALSE,DUMP'
450 | ;
451 |
452 | //2015.6.8 added for Bash by gzhaha;
453 | var sTags_BASH=
454 | 'if,fi,then,elif,else,for,do,done,until,while,break,continue,case,function,return,in,eq,ne,ge,le'
455 | ;
456 |
457 | var sTags_BASHBI=
458 | 'alias,apropos,awk,basename,bash,bc,bg,builtin,bzip2,cal,cat,cd,cfdisk,chgrp,chmod,chown,chroot'
459 | +',cksum,clear,cmp,comm,command,cp,cron,crontab,csplit,cut,date,dc,dd,ddrescue,declare,df'
460 | +',diff,diff3,dig,dir,dircolors,dirname,dirs,du,echo,egrep,eject,enable,env,ethtool,eval'
461 | +',exec,exit,expand,export,expr,false,fdformat,fdisk,fg,fgrep,file,find,fmt,fold,format'
462 | +',free,fsck,ftp,gawk,getopts,grep,groups,gzip,hash,head,history,hostname,id,ifconfig'
463 | +',import,install,join,kill,less,let,ln,local,locate,logname,logout,look,lpc,lpr,lprint'
464 | +',lprintd,lprintq,lprm,ls,lsof,make,man,mkdir,mkfifo,mkisofs,mknod,more,mount,mtools'
465 | +',mv,netstat,nice,nl,nohup,nslookup,open,op,passwd,paste,pathchk,ping,popd,pr,printcap'
466 | +',printenv,printf,ps,pushd,pwd,quota,quotacheck,quotactl,ram,rcp,read,readonly,renice'
467 | +',remsync,rm,rmdir,rsync,screen,scp,sdiff,sed,select,seq,set,sftp,shift,shopt,shutdown'
468 | +',sleep,sort,source,split,ssh,strace,su,sudo,sum,symlink,sync,tail,tar,tee,test,time'
469 | +',times,touch,top,traceroute,trap,tr,true,tsort,tty,type,ulimit,umask,umount,unalias'
470 | +',uname,unexpand,uniq,units,unset,unshar,useradd,usermod,users,uuencode,uudecode,v,vdir'
471 | +',vi,watch,wc,whereis,which,who,whoami,Wget,xargs,yes'
472 | ;
473 |
474 | //2015.6.11 added for myBase by gzhaha;
475 | var sTags_myBase=
476 | 'about|alert|confirm|prompt|dropdown|textbox|input|beep|sleep|_gc'
477 |
478 | //+ '|platform.getOpenFileName|platform.getOpenFileNames|platform.getSaveFileName|platform.browseForFolder'
479 | //+ '|platform.getTempFile|platform.getTempPath|platform.getHomePath|platform.getCurrentPath|platform.deferDeleteFile'
480 | //+ '|platform.extractTextFromRtf|platform.extractTextFromHtml|platform.parseFile|platform.tokenizeText'
481 | //+ '|plugin.getAppWorkingDir|plugin.getAppExeFile|plugin.getPluginID|plugin.getScriptFile|plugin.getScriptTitle'
482 | //+ '|plugin.getShortcutFile|plugin.getLanguageFile|plugin.getPathToLangFiles|plugin.getDefRootContainer'
483 | //+ '|plugin.getDefNoteFn|plugin.refreshDocViews|plugin.refreshOutline|plugin.refreshLabelTree|plugin.refreshCalendar'
484 | //+ '|plugin.refreshOverview|plugin.getLocaleMsg|plugin.getDbCount|plugin.getDbIndex|plugin.getCurDbIndex'
485 | //+ '|plugin.getCurNavigationTab|plugin.getCurDocFile|plugin.getCurDocPath|plugin.getCurInfoItem|plugin.getCurLabelItem'
486 | //+ '|plugin.getSelectedInfoItems|plugin.getSelectedText|plugin.getTextContent|plugin.setTextContent'
487 | //+ '|plugin.replaceSelectedText|plugin.getQueryResults|plugin.runQuery|plugin.appendToResults'
488 | //+ '|plugin.setResultsPaneTitle|plugin.showResultsPane|plugin.initProgressRange|plugin.showProgressMsg'
489 | //+ '|plugin.ctrlProgressBar|plugin.destroyProgressBar|plugin.commitCurrentChanges|plugin.isContentEditable'
490 | //+ '|plugin.runDomScript|plugin.setDomDirty|plugin.setDomReadonly|plugin.getItemIDByPath|plugin.getPathByItemID'
491 | //+ '|localStorage.getItem|localStorage.setItem|localStorage.removeItem|localStorage.clear'
492 |
493 | //2015.6.12 @gzhaha :) Nice to have an item for mybase jsapi in the language list;
494 | //Revised by wjj;
495 | //The API lists may vary in future releases; so RegExp patterns are recommended for better flexibility;
496 | //It is somewhat easy to highlight the global objects/functions and classes by the hard-coded names;
497 | //however; it seemed hard to recognize member functions of objects created from the classes (eg. xNyf.isOpen(...);)
498 |
499 | + '|plugin\.\\w+' //or use '|plugin(?=\.)' for global objects only; without memeber functions highlighted;
500 | + '|platform\.\\w+'
501 | + '|localStorage\.\\w+'
502 | + '|CNyfDb|CDbItem|CLocalFile|CLocalDir|CByteArray'
503 | + '|CXmlDocument|CAppWord|CAppExcel|CAppOutlook'
504 | ;
505 |
506 | //2015.6.14 added for Pascal by gzhaha;
507 | var sTags_Pascal=
508 | 'absolute,abstract,and,array,as,asm,assembler,at,automated,begin,case,cdecl,class,const,constructor,contains'
509 | + ',default,destructor,dispid,dispinterface,div,do,downto,dynamic,else,end,except,export,exports,external,far'
510 | + ',file,finalization,finally,for,forward,function,goto,if,implementation,implements,in,index,inherited'
511 | + ',initialization,inline,interface,is,label,library,message,mod,name,near,nil,nodefault,not,object,of,on,or'
512 | + ',out,overload,override,package,packed,pascal,private,procedure,program,property,protected,public,published'
513 | + ',raise,read,readonly,record,register,reintroduce,repeat,requires,resident,resourcestring,safecall,set,shl'
514 | + ',shr,stdcall,stored,string,then,threadvar,to,try,type,unit,until,uses,var,virtual,while,with,write,writeonly,xor'
515 | ;
516 |
517 | //2015.6.16 added for Objective-C by wjj;
518 | //http://www.binpress.com/tutorial/objective-c-reserved-keywords/43
519 | //http://www.learn-cocos2d.com/2011/10/complete-list-objectivec-20-compiler-directives/
520 | var sTags_ObjC=
521 | 'auto,break,case,char,const,continue,default,do,double,else,enum,extern,float,for,goto,if,inline,int,long,register'
522 | + ',restrict,return,short,signed,sizeof,static,struct,switch,typedef,union,unsinged,void,volatile,while,__Bool,__Complex'
523 | + ',BOOL,Class,bycopy,byref,id,IMP,in,inout,nil,NO,NULL,oneway,out,Protocol,SEL,self,super,YES'
524 | + ',@interface,@end,@implementation,@protocol,@class,@public,@protected,@private,@property,@try,@throw,@catch,@finally,@synthesize,@dynamic,@selector,atomic,nonatomic,retain'
525 | + ',@defs,@required,@optional,@end,@package,@end,@synchronized,@autoreleasepool,@selector,@encode,@compatibility_alias'
526 | ;
527 |
528 | //https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/ObjC_classic/index.html
529 | var sTags_ObjC_Cocoa=
530 | 'NS[A-Z][a-zA-Z]{2,64}'
531 | ;
532 |
533 | //2015.6.18 added for Swift by wjj;
534 | https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html
535 | var sTags_Swift=
536 | 'class,deinit,enum,extension,func,import,init,internal,let,operator,private,protocol,public,static,struct,subscript,typealias,var'
537 | + ',break,case,continue,default,do,else,fallthrough,for,if,in,return,switch,where,while'
538 | + ',as,dynamicType,false,is,nil,self,Self,super,true,__COLUMN__,__FILE__,__FUNCTION__,__LINE__'
539 | + ',associativity,convenience,dynamic,didSet,final,get,infix,inout,lazy,left,mutating,none,nonmutating,optional,override,postfix,precedence,prefix,Protocol,required,right,set,Type,unowned,weak,willSet'
540 | ;
541 |
542 | //https://developer.apple.com/library/ios/navigation/
543 | var sTags_Swift_Lib=
544 | 'NS[A-Z][a-zA-Z]{2,64}'
545 | + '|UI[A-Z][a-zA-Z]{2,64}'
546 | + '|CI[A-Z][a-zA-Z]{2,64}'
547 | + '|CK[A-Z][a-zA-Z]{2,64}'
548 | + '|CF[A-Z][a-zA-Z]{2,64}'
549 | + '|AV[A-Z][a-zA-Z]{2,64}'
550 | + '|AU[A-Z][a-zA-Z]{2,64}'
551 | + '|MK[A-Z][a-zA-Z]{2,64}'
552 | + '|MT[A-Z][a-zA-Z]{2,64}'
553 | + '|SC[A-Z][a-zA-Z]{2,64}'
554 | + '|GC[A-Z][a-zA-Z]{2,64}'
555 | //...
556 | ;
557 |
558 | //Array objects to save strings/remarks substituted with internal tags;
559 | var vRem=[]; //for remarks (blocks & lines);
560 | var vStr=[]; //for Strings;
561 | var nRefID=0; //ID of remarks/strings;
562 |
563 | //2012.1.31 The tags are used to temporarily substitute for strings/remarks;
564 | //The ref-tags must be absolutely strange to any programming languages;
565 | var sRefTag1='!`', sRefTag2='`!';
566 |
567 | var _ref_tag=function(){return sRefTag1+(nRefID++)+sRefTag2;};
568 |
569 | var _parse_remark_blocks=function(sSrc, vRemBlockTag){
570 |
571 | //2015.6.18 Apple Swift supports nested comments, but for now not supported by this plugin;
572 | //https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html
573 | //To-do: trace into the multiline comments and track the nested comment tags by counting deepness or running a recursive function;
574 |
575 | //To substitute internal tags for /*...*/ remark blocks;
576 | if(vRemBlockTag.constructor === Array){
577 |
578 | //2015.6.15 Pascal has three ways to perform comment, //XXXX, (*XXXX*) and {XXXX};
579 | //added codes to deal with multiple set of the symbols for block comment;
580 |
581 | for(var i in vRemBlockTag){
582 | var sRemBlockStart=vRemBlockTag[i].start, sRemBlockEnd=vRemBlockTag[i].end;
583 | var s2=sSrc; sSrc='';
584 | while(s2){
585 | var p1=s2.indexOf(sRemBlockStart);
586 | if(p1>=0){
587 | var p2=s2.indexOf(sRemBlockEnd, p1+sRemBlockStart.length);
588 | if(p2<0) p2=s2.length; else p2+=sRemBlockEnd.length;
589 | //if(p2>0)
590 | {
591 | var left=s2.substr(0, p1), sRem=s2.substring(p1, p2), right=s2.substr(p2);
592 | var sTag=_ref_tag();
593 | sSrc+=(left+sTag);
594 | s2=right;
595 | vRem[vRem.length]={sTag: sTag, sVal: sRem};
596 | }
597 | }else{
598 | sSrc+=s2;
599 | s2='';
600 | }
601 | }
602 | }
603 | }
604 |
605 | return sSrc;
606 | };
607 |
608 | var _parse_remark_line=function(sLine, vRemLineTag){
609 |
610 | var _replace=function(sLine, sRemLineTag){
611 | if(sLine && sRemLineTag){
612 | //2015.6.7 efforts on dealing with # symbol within quotation marks: '...#...' or "...#..."
613 | //2015.6.12 no need for this changes now.
614 | //if (sLine.search(/\".*\#.*\"/) < 0 && sLine.search(/\'.*\#.*\'/) <0){
615 |
616 | var xRE=new RegExp(sRemLineTag+'(.*)$', '');
617 | sLine=sLine.replace(xRE, function(w){
618 | var sTag=_ref_tag();
619 | vRem[vRem.length]={sTag: sTag, sVal: w};
620 | return sTag;
621 | });
622 |
623 | //}
624 | }
625 | return sLine;
626 | };
627 |
628 | //substitute internal tags for the remark lines;
629 | for(var i in vRemLineTag){
630 | sLine=_replace(sLine, vRemLineTag[i]);
631 | }
632 | return sLine;
633 | };
634 |
635 | var _parse_strings=function(sLine, sQuotationMark){
636 |
637 | //substitute for constants of C-string/HTML-value, like "...";
638 | //substitute for constants of JS-string/HTML-value/C-char, like '...';
639 |
640 | var _pos_of_quotationmark=function(s, iStart){
641 | var p;
642 | while( (p=s.indexOf(sQuotationMark, iStart)) >0 ){
643 | if(s.charAt(p-1)=='\\'){
644 | iStart=p+sQuotationMark.length;
645 | }else{
646 | break;
647 | }
648 | }
649 | return p;
650 | };
651 |
652 | var s=sLine; sLine='';
653 | while(s){
654 | var p1=_pos_of_quotationmark(s, 0);
655 | if(p1>=0){
656 | var p2=_pos_of_quotationmark(s, p1+sQuotationMark.length);
657 | if(p2<0) p2=s.length; else p2+=sQuotationMark.length;
658 | //if(p2>0)
659 | {
660 | var left=s.substr(0, p1), sStr=s.substring(p1, p2), right=s.substr(p2);
661 | var sTag=_ref_tag();
662 | sLine+=(left+sTag);
663 | s=right;
664 | vStr[vStr.length]={sTag: sTag, sVal: sStr};
665 | }
666 | }else{
667 | sLine+=s;
668 | s='';
669 | }
670 | }
671 | return sLine;
672 | };
673 |
674 | var _restore_strings=function(s){
675 | //restore String contants;
676 | for(var j=vStr.length-1; j>=0; --j){
677 | var sTag=vStr[j].sTag, sVal=vStr[j].sVal;
678 | var r=''.replace(/%COLOR%/g, c_sColorStrings)+sVal+'';
679 | s=s.replace(sTag, r);
680 | }
681 | return s;
682 | };
683 |
684 | var _restore_remarks=function(s){
685 | //restore remark blocks and lines;
686 | for(var j=vRem.length-1; j>=0; --j){
687 | var sTag=vRem[j].sTag, sVal=vRem[j].sVal;
688 | var v=sVal.split('\n'), r='';
689 | for(var i in v){
690 | if(r) r+='\n';
691 | r+=''.replace(/%COLOR%/g, c_sColorRemarks)+v[i]+'';
692 | }
693 | s=s.replace(sTag, r);
694 | }
695 | return s;
696 | };
697 |
698 | var _syntax_cpplike=function(s, vTags, vRemBlockTag, vRemLineTag){
699 |
700 | s=s.replace(/\r\n/g, '\n')
701 | .replace(/\r/g, '\n')
702 | //.replace(/\\/g, '\\\\')
703 | ;
704 |
705 | var _highlight_numbers=function(sLine, sColor){
706 | if(sLine){
707 | var sFmt=''.replace(/%COLOR%/g, sColor);
708 |
709 | //Hexadecimal, Decimal/Float;
710 | var xRE=new RegExp( '(\\W+)((?:0x[0-9a-f]+)|(?:[0-9.]+))(?=\\W?)', 'ig');
711 | sLine=sLine.replace(xRE, function(w, s1, s2){
712 | //first check to see if it is a tag for strings/remarks;
713 | var p=s1.indexOf(sRefTag1);
714 | if(p>=0 && p==s1.length-sRefTag1.length){
715 | return w; //avoid replacing temporary tags of strings/remarks;
716 | }else{
717 | return s1+sFmt+s2+'';
718 | }
719 | });
720 | }
721 | return sLine;
722 | };
723 |
724 | var _highlight_tags=function(sLine, sTags, bRegExp, bNoCase, sColor){
725 |
726 | if(!bRegExp) sTags=sTags.replace(/,/g, '|').replace(/\s/g, ''); //make into RegExp pattern;
727 |
728 | if(sLine && sTags){
729 |
730 | var sFmt=''.replace(/%COLOR%/g, sColor);
731 |
732 | //This RegExp tests but not save/consume trailing characters;
733 | var xRE=new RegExp( '(\\W+|^)(' + sTags + ')(?=\\W|$)', 'g'+(bNoCase?'i':''));
734 | sLine=sLine.replace(xRE, function(w, s1, s2){
735 | return s1+sFmt+s2+'';
736 | });
737 | }
738 | return sLine;
739 | };
740 |
741 |
742 | //2015.6.7 the operators (<, &, >) in source code may cause confusion to webkit on parsing them as HTML without pre-transformation;
743 | //tried a solution of precedingly transforming < and > operators into HTML entities,
744 | //and assumed that 'lt,gt' are not listed as keywords for any languages;
745 | //s=s.replace(//g, '>');
746 | //Unfortunately, both lt and gt could be in use as keywords in some languages e.g. Perl, Bash;
747 | //Another solution: substitute special tags for < and > operators before syntax highlighting,
748 | //and finally replace the tags with the appropriate HTML entities after all done;
749 | //2015.6.9 also need to substitute for the & character, so HTML entities can be preserved in resulting HTML.
750 | //2015.6.12 also need to substitute for the $ character, the issue is related to parse '$' in source code.
751 | //2015.6.12 also need to substitute for the \ character, the issue is related to parse \\ in source code.
752 |
753 | //2015.8.17 a safe method to generate the special tags for '<>&...', in case that they could appear in source code, e.g. the script itself;
754 | var _make_special=function(s){
755 | if(s){
756 | var r='';
757 | for(var i=0; i /g, sTagGT).replace(/&/g, sTagAND).replace(/\$/g, sTagDL).replace(/\\/g, sTagBS);
769 |
770 | //2015.8.17 Remark blocks may contain the above special characters such as < >;
771 | s=_parse_remark_blocks(s, vRemBlockTag);
772 |
773 | var vLines=s.split('\n');
774 |
775 | plugin.initProgressRange(plugin.getScriptTitle(), vLines.length);
776 |
777 | for(var k in vLines){
778 |
779 | //2015.6.7 the opertotors < and > in source code may cause confusion to webkit without transformation;
780 | //tried to precedingly transform < and > operators into HTML entities;
781 | //and assumed that 'lt,gt' are not listed as keywords for any languages;
782 | //var sLine=vLines[k].replace(//g, '>');
783 |
784 | //Unfortunately, both lt and gt are used as keywords in Perl;
785 | //Workaround: substitute special tags for < and > operators, and restore them after all done;
786 | var sLine=vLines[k];
787 |
788 | var sTitle=_trim(sLine), nMaxLen=32; if(sTitle.length>nMaxLen) sTitle=sTitle.substr(0,nMaxLen);
789 | var bContinue=plugin.ctrlProgressBar(sTitle, 1, true);
790 | if(!bContinue) return '';
791 |
792 | sLine=_parse_remark_line(sLine, vRemLineTag); //cpp-like comment lines;
793 | sLine=_parse_strings(sLine, '\''); //js-like strings;
794 | sLine=_parse_strings(sLine, '\"'); //cpp-like strings;
795 |
796 | sLine=_highlight_numbers(sLine, c_sColorNumbers);
797 |
798 | for(var j in vTags){
799 | var d=vTags[j];
800 | var sTags=d.sTags, sColor=d.sColor, bNoCase=d.bNoCase, bRegExp=d.bRegExp;
801 | sLine=_highlight_tags(sLine, sTags, bRegExp, bNoCase, sColor);
802 | }
803 |
804 | vLines[k]=sLine;
805 | }
806 |
807 | s='';
808 | for(var j in vLines){
809 | if(s) s+='\n';
810 | s+=vLines[j];
811 | }
812 |
813 | s=_restore_strings(s);
814 | s=_restore_remarks(s);
815 |
816 | s=s.replace(xReLT, '<').replace(xReGT, '>').replace(xReAND, '&').replace(xReDL, '$').replace(xReBS, '\\');
817 |
818 | return s;
819 | };
820 |
821 | var sSrc=plugin.getSelectedText(-1, false), bWhole=false;
822 | if(!sSrc){
823 | bWhole=true;
824 | sSrc=plugin.getTextContent(-1, false);
825 | }
826 |
827 | if(sSrc){
828 |
829 | var xLang={
830 | 'cpp': 'C/C++'
831 | , 'cppstl': 'C/C++ with STL'
832 | , 'cppstlqt': 'C/C++ with STL/Qt'
833 | , 'java': 'Java'
834 | , 'cs': 'C#'
835 | , 'js': 'Javascript'
836 | , 'jsmybase': 'Javascript with myBase Plugin APIs'
837 | , 'sql': 'T-SQL'
838 | , 'php': 'PHP'
839 | , 'go': 'Google GO'
840 | , 'gnur': 'GNU/R Language'
841 | , 'vb': 'Visual Basic'
842 | , 'py': 'Python'
843 | , 'pl': 'Perl'
844 | , 'as': 'ActionScript'
845 | , 'ruby': 'Ruby'
846 | , 'delphi': 'Delphi'
847 | , 'pigla': 'Pig Latin'
848 | , 'bash': 'Bash'
849 | , 'pascal': 'Pascal'
850 | , 'objc': 'Objective-C'
851 | , 'swift': 'Swift'
852 | };
853 |
854 | var vIDs=[], vLangs=[];
855 | for(var i in xLang){
856 | vIDs[vIDs.length]=i;
857 | vLangs[vLangs.length]=xLang[i];
858 | }
859 |
860 | //2015.6.29 a list of fixed fonts;
861 | //http://stackoverflow.com/questions/3995022/pre-tag-and-css-font-family
862 | //http://www.w3schools.com/cssref/css_websafe_fonts.asp
863 | var vFonts=[
864 | '|'+_lc('p.Common.Default', 'Default')
865 | , 'Lucida Console', 'Courier New', 'Consolas', 'serif'
866 | , 'Menlo', 'Monaco', 'monospace', 'Liberation Mono'
867 | , 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono'
868 | ];
869 |
870 | var vSizes=['|'+_lc('p.Common.Default', 'Default')];
871 | for(var i=8; i<=72; ++i){
872 | vSizes.push(i+'pt');
873 | if(i>=20) i+=3;
874 | }
875 |
876 | var sCfgKey0='SyntaxHighlight.nUses', nUses=parseInt(localStorage.getItem(sCfgKey0)||'');
877 | var sCfgKey1='SyntaxHighlight.iLang', sCfgKey2='SyntaxHighlight.sFontName', sCfgKey3='SyntaxHighlight.sFontSize';
878 | var vFields = [
879 | {sField: 'combolist', sLabel: _lc2('Language', 'Language'), vItems: vLangs, sInit: localStorage.getItem(sCfgKey1)||''}
880 | , {sField: 'comboedit', sLabel: _lc2('FontName', 'Font name'), vItems: vFonts, sInit: localStorage.getItem(sCfgKey2)||(nUses==0 ? c_sFontName : ''), bReq: false}
881 | , {sField: 'comboedit', sLabel: _lc2('FontSize', 'Font size'), vItems: vSizes, sInit: localStorage.getItem(sCfgKey3)||(nUses==0 ? c_sFontSizee : ''), bReq: false}
882 | ];
883 | var vRes=input(plugin.getScriptTitle(), vFields, {nMinSize: 450, vMargins: [6, 0, 30, 0], bVert: false});
884 | if(vRes && vRes.length==3){
885 |
886 | var iLang=vRes[0], sFontName=vRes[1], sFontSize=vRes[2];
887 |
888 | localStorage.setItem(sCfgKey0, ++nUses);
889 | localStorage.setItem(sCfgKey1, iLang);
890 | localStorage.setItem(sCfgKey2, sFontName);
891 | localStorage.setItem(sCfgKey3, sFontSize);
892 |
893 | //sSrc='\n'+sSrc;
894 |
895 | var sID=vIDs[iLang];
896 |
897 | //2015.6.15 For more info about comments in programming languages;
898 | //http://www.gavilan.edu/csis/languages/comments.html
899 | //http://stackoverflow.com/questions/3842443/comments-in-pascal
900 |
901 | var vTags=[], vRemBlockTag=[{start: '/*', end: '*/'}], vRemLineTag=['//'], sGenre='cpp';
902 | switch(sID){
903 | case 'cpp':
904 | vTags=[{sTags: sTags_Cpp, sColor: c_sColorKeywords}];
905 | break;
906 | case 'cppstl':
907 | vTags=[
908 | {sTags: sTags_Cpp, sColor: c_sColorKeywords}
909 | , {sTags: sTags_Stl, sColor: c_sColorReservedTags1}
910 | ];
911 | break;
912 | case 'cppstlqt':
913 | vTags=[
914 | {sTags: sTags_Cpp, sColor: c_sColorKeywords}
915 | , {sTags: sTags_Stl, sColor: c_sColorReservedTags1}
916 | , {sTags: sTags_Qt, sColor: c_sColorReservedTags5, bNoCase: false, bRegExp: true}
917 | ];
918 | break;
919 | case 'java':
920 | vTags=[{sTags: sTags_Java, sColor: c_sColorKeywords}];
921 | break;
922 | case 'cs':
923 | vTags=[{sTags: sTags_CSharp, sColor: c_sColorKeywords}];
924 | break;
925 | case 'js':
926 | vTags=[
927 | {sTags: sTags_JS, sColor: c_sColorKeywords}
928 | , {sTags: sTags_JSConst, sColor: c_sColorNumbers}
929 | , {sTags: sTags_JSDom, sColor: c_sColorReservedTags1}
930 | , {sTags: sTags_JSEvent, sColor: c_sColorReservedTags3}
931 | ];
932 | break;
933 | case 'jsmybase':
934 | vTags=[
935 | {sTags: sTags_JS, sColor: c_sColorKeywords}
936 | , {sTags: sTags_JSConst, sColor: c_sColorNumbers}
937 | //, {sTags: sTags_JSDom, sColor: c_sColorReservedTags1}
938 | //, {sTags: sTags_JSEvent, sColor: c_sColorReservedTags3}
939 | , {sTags: sTags_myBase, sColor: c_sColorReservedTags6, bRegExp: true}
940 | ];
941 | break;
942 | case 'sql':
943 | vTags=[{sTags: sTags_Sql, sColor: c_sColorKeywords, bNoCase: true}];
944 | vRemLineTag=['--'];
945 | break;
946 | case 'php':
947 | vTags=[{sTags: sTags_Php, sColor: c_sColorKeywords}];
948 | break;
949 | case 'gnur':
950 | vTags=[{sTags: sTags_R, sColor: c_sColorKeywords}];
951 | vRemBlockTag=[];
952 | vRemLineTag=['#'];
953 | break;
954 | case 'go':
955 | vTags=[{sTags: sTags_Go, sColor: c_sColorKeywords}];
956 | break;
957 | case 'vb':
958 | vTags=[
959 | {sTags: sTags_VB_Reserved, sColor: c_sColorKeywords, bNoCase: true}
960 | , {sTags: sTags_VB_Unreserved, sColor: c_sColorReservedTags1, bNoCase: true}
961 | ];
962 | vRemBlockTag=[];
963 | vRemLineTag=['REM', '\''];
964 | break;
965 | case 'py':
966 | vTags=[
967 | {sTags: sTags_Pythonkw, sColor: c_sColorKeywords}
968 | , {sTags: sTags_Python, sColor: c_sColorReservedTags3}
969 | ];
970 | vRemBlockTag=[{start: "'''", end: "'''"}];
971 | vRemLineTag=['#'];
972 | break;
973 | case 'pl':
974 | vTags=[
975 | {sTags: sTags_Perlkw, sColor: c_sColorKeywords}
976 | , {sTags: sTags_Perl, sColor: c_sColorReservedTags3}
977 | ];
978 | vRemBlockTag=[{start: '=pod', end: '=cut'}];
979 | vRemLineTag=['#'];
980 | break;
981 | case 'as':
982 | vTags=[
983 | {sTags: sTags_ActionScript, sColor: c_sColorKeywords}
984 | ];
985 | break;
986 | case 'ruby':
987 | vTags=[
988 | {sTags: sTags_Ruby, sColor: c_sColorKeywords}
989 | , {sTags: sTags_RubyBI, sColor: c_sColorReservedTags3}
990 | ];
991 | vRemBlockTag=[{start: '=begin', end: '=end'}];
992 | vRemLineTag=['#'];
993 | break;
994 | case 'pigla':
995 | vTags=[
996 | {sTags: sTags_PigLatinKW, sColor: c_sColorKeywords}
997 | , {sTags: sTags_PigLatin, sColor: c_sColorReservedTags3}
998 | ];
999 | vRemLineTag=['--'];
1000 | break;
1001 | case 'bash':
1002 | vTags=[
1003 | {sTags: sTags_BASH, sColor: c_sColorKeywords}
1004 | , {sTags: sTags_BASHBI, sColor: c_sColorReservedTags3}
1005 | ];
1006 | vRemBlockTag=[];
1007 | vRemLineTag=['#'];
1008 | break;
1009 | case 'delphi':
1010 | vTags=[
1011 | {sTags: sTags_Delphi, sColor: c_sColorKeywords}
1012 | ];
1013 | //vRemBlockTag=[{start: '{', end: '}'}];
1014 | vRemBlockTag=[{start: '(*', end: '*)'}, {start: '{', end: '}'}];
1015 | break;
1016 | case 'pascal':
1017 | vTags=[
1018 | {sTags: sTags_Pascal, sColor: c_sColorKeywords}
1019 | ];
1020 | //2015.6.15 Pascal has three ways to perform comment, //XXXX, (*XXXX*) and {XXXX};
1021 | //Below two lines using array to define two sets of the start and end symbols;
1022 | vRemBlockTag=[{start: '(*', end: '*)'}, {start: '{', end: '}'}];
1023 | break;
1024 | case 'objc':
1025 | vTags=[
1026 | {sTags: sTags_ObjC, sColor: c_sColorKeywords}
1027 | , {sTags: sTags_ObjC_Cocoa, sColor: c_sColorReservedTags3, bRegExp: true}
1028 | ];
1029 | break;
1030 | case 'swift':
1031 | vTags=[
1032 | {sTags: sTags_Swift, sColor: c_sColorKeywords}
1033 | , {sTags: sTags_Swift_Lib, sColor: c_sColorReservedTags3, bRegExp: true}
1034 | ];
1035 | break;
1036 | }
1037 |
1038 | var sHtml;
1039 | {
1040 | if(sGenre=='cpp'){
1041 | sHtml=_syntax_cpplike(sSrc, vTags, vRemBlockTag, vRemLineTag);
1042 | }else if(sGenre=='html'){
1043 | //todo ......
1044 | }
1045 |
1046 | //2015.6.16 "word-wrap: normal" for source code;
1047 | //http://www.w3schools.com/cssref/pr_text_white-space.asp
1048 | //http://www.w3schools.com/cssref/css3_pr_word-wrap.asp
1049 |
1050 | var s='';
1051 | {
1052 | if(sFontName){
1053 | if(s) s+=' ';
1054 | s+='font-family: '+sFontName+'; ';
1055 | }
1056 | if(sFontSize){
1057 | if(s) s+=' ';
1058 | s+='font-size: '+sFontSize+'; ';
1059 | }
1060 | }
1061 |
1062 | sHtml=''.replace(/%FONTATTR%/g, s)
1063 | + sHtml
1064 | + '
'
1065 | ;
1066 | }
1067 |
1068 | if(sHtml){
1069 | if(bWhole){
1070 |
1071 | if(plugin.selectAllText){ //2015.6.10 requires latest build b-20;
1072 |
1073 | plugin.selectAllText();
1074 | plugin.replaceSelectedText(-1, sHtml, true);
1075 |
1076 | }else{
1077 |
1078 | //2015.6.10 setHTML clears the entire DOM including UNDO stack, so it needs to first save if any changes as a history revision for Undoable;
1079 | if(plugin.isContentEditable()) plugin.commitCurrentChanges();
1080 |
1081 | plugin.setTextContent(-1, sHtml, true);
1082 | plugin.setDomDirty(-1, true);
1083 |
1084 | }
1085 |
1086 | }else{
1087 |
1088 | plugin.replaceSelectedText(-1, sHtml, true);
1089 |
1090 | }
1091 | }
1092 | }
1093 |
1094 | }else{
1095 | alert(_lc('Prompt.Warn.NoTextSelected', 'No text is currently selected.'));
1096 | }
1097 |
1098 | }else{
1099 | alert(_lc('Prompt.Warn.ReadonlyDb', 'Cannot modify the database opened as Readonly.'));
1100 | }
1101 |
1102 | }else{
1103 | alert(_lc('Prompt.Warn.NoDbOpened', 'No database is currently opened.'));
1104 | }
1105 | }catch(e){
1106 | alert(e);
1107 | }
1108 |
--------------------------------------------------------------------------------
/plugins/WordCount.js:
--------------------------------------------------------------------------------
1 |
2 | //sValidation=nyfjs
3 | //sCaption=Word Count
4 | //sHint=Word Count 02062015
5 | //sCategory=MainMenu.TxtUtils
6 | //sPosition=XZ-255
7 | //sCondition=CURDB; DBRW; CURINFOITEM; HTMLEDIT; HTMLSELECTED
8 | //sID=p.gzhaha.WordCount
9 | //sAppVerMin=7.0
10 | //sShortcutKey=
11 | //sAuthor=Xia Zhang
12 |
13 | /////////////////////////////////////////////////////////////////////
14 | // Extension scripts for myBase Desktop v7.x
15 | // Copyright 2015 Xia Zhang (MIT Licensed)
16 | /////////////////////////////////////////////////////////////////////
17 |
18 | var _lc=function(sTag, sDef){return plugin.getLocaleMsg(sTag, sDef);};
19 | var _lc2=function(sTag, sDef){return _lc(plugin.getLocaleID()+'.'+sTag, sDef);};
20 |
21 | var _trim=function(s){return (s||'').replace(/^\s+|\s+$/g, '');};
22 | var _trim_cr=function(s){return (s||'').replace(/\r+$/g, '');};
23 |
24 | try{
25 | var xNyf=new CNyfDb(-1);
26 | if(xNyf.isOpen()){
27 | if(!xNyf.isReadonly()){
28 | if(plugin.isContentEditable()){
29 | //get selected text
30 | var sCon = plugin.getSelectedText(-1, false);
31 |
32 | //run function
33 | var html = fnWordCount(sCon);
34 |
35 | alert('Words Count:' + html + ' words')
36 | }else{
37 | alert(_lc('Prompt.Warn.ReadonlyContent', 'Cannot modify the content opened as Readonly.'));
38 | }
39 | }else{
40 | alert(_lc('Prompt.Warn.ReadonlyDb', 'Cannot modify the database opened as Readonly.'));
41 | }
42 | }else{
43 | alert(_lc('Prompt.Warn.NoDbOpened', 'No database is currently opened.'));
44 | }
45 | }catch(e){
46 | alert(e);
47 | }
48 |
49 | //Words Count:
50 | //http://blog.csdn.net/gavid0124/article/details/38117381
51 | function fnWordCount(str){
52 | sLen = 0;
53 | try{
54 | str = str.replace(/(\r\n+|\s+| +)/g,"龘");
55 | str = str.replace(/[\x00-\xff]/g,"m");
56 | str = str.replace(/m+/g,"*");
57 | str = str.replace(/龘+/g,"");
58 | sLen = str.length;
59 | }catch(e){
60 |
61 | }
62 | return sLen;
63 | }
64 |
--------------------------------------------------------------------------------