diff --git a/CHANGELOG.md b/CHANGELOG.md index c09fd0a6..16db81b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,9 @@ * adds `rust` type and icon * removes *Install* section from `README.md`, caused to much trouble * updates build process to use `node 6.0+`, no need for babel now -* updates `normalize.css` to 4.2.0 -* replaces `jquery-qrcode` with `kjua` 0.1.1 -* updates `prism` to 2016-07-01 -* move deps `normalize.css`, `kjua` and `marked` to `package.json` +* replaces `jquery-qrcode` with `kjua` +* replaces `prism` with `lolight` +* move deps `normalize.css`, `kjua`, `lolight` and `marked` to `package.json` * removes `jQuery` * removes `lodash` * removes `modulejs` diff --git a/package.json b/package.json index 1f8192cf..fc31f9e5 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "eslint": "3.1.1", "ghu": "0.7.0", "kjua": "0.1.1", + "lolight": "0.3.0", "marked": "0.3.5", "normalize.css": "4.2.0", "scar": "0.14.0" diff --git a/src/_h5ai/private/conf/options.json b/src/_h5ai/private/conf/options.json index 483901c6..fa2d4ced 100644 --- a/src/_h5ai/private/conf/options.json +++ b/src/_h5ai/private/conf/options.json @@ -237,43 +237,42 @@ /* Show text file preview on click. - "types" maps file types to http://prismjs.com languages. - Currently included: markup+css+clike+javascript+bash+ruby+go+json+python+rust - Additional type are: - - "markdown" to render Markdown text - - "none" for floating text - - "fixed" for fixed width text + Available styles are: + 0: floating text + 1: fixed width text + 2: markdown + 3: syntax highlighting - - types: dict string to string, maps types to languages + - styles: dict string to int, maps types to styles */ "preview-txt": { "enabled": true, - "types": { - "txt": "fixed", - "txt-authors": "fixed", - "txt-c": "clike", - "txt-cpp": "clike", - "txt-css": "css", - "txt-diff": "fixed", - "txt-go": "go", - "txt-h": "clike", - "txt-hpp": "clike", - "txt-install": "fixed", - "txt-js": "javascript", - "txt-json": "javascript", - "txt-less": "css", - "txt-license": "fixed", - "txt-log": "fixed", - "txt-makefile": "fixed", - "txt-md": "markdown", - "txt-py": "python", - "txt-rb": "ruby", - "txt-readme": "fixed", - "txt-rtf": "fixed", - "txt-rust": "rust", - "txt-script": "bash", - "txt-xml": "fixed" + "styles": { + "txt": 1, + "txt-authors": 1, + "txt-c": 3, + "txt-cpp": 3, + "txt-css": 3, + "txt-diff": 1, + "txt-go": 3, + "txt-h": 3, + "txt-hpp": 3, + "txt-install": 1, + "txt-js": 3, + "txt-json": 3, + "txt-less": 3, + "txt-license": 1, + "txt-log": 1, + "txt-makefile": 1, + "txt-md": 2, + "txt-py": 3, + "txt-rb": 3, + "txt-readme": 1, + "txt-rtf": 1, + "txt-rust": 3, + "txt-script": 3, + "txt-xml": 1 } }, diff --git a/src/_h5ai/public/js/lib/ext/preview/preview-txt.js b/src/_h5ai/public/js/lib/ext/preview/preview-txt.js index c7c1ebef..ee869ca6 100644 --- a/src/_h5ai/public/js/lib/ext/preview/preview-txt.js +++ b/src/_h5ai/public/js/lib/ext/preview/preview-txt.js @@ -1,6 +1,7 @@ +const lolight = require('lolight'); const marked = require('marked'); const {each, keys, includes, compact, dom} = require('../../util'); -const {win, prism} = require('../../globals'); +const {win} = require('../../globals'); const event = require('../../core/event'); const allsettings = require('../../core/settings'); const preview = require('./preview'); @@ -9,7 +10,7 @@ const preview = require('./preview'); const XHR = win.XMLHttpRequest; const settings = Object.assign({ enabled: false, - types: {} + styles: {} }, allsettings['preview-txt']); const tplText = '
'; const tplMarkdown = ''; @@ -86,28 +87,21 @@ const onIdxChange = rel => { return; } - const type = settings.types[currentItem.type]; + const style = settings.styles[currentItem.type]; let $text; - let $code; - if (type === 'none') { - $text = dom(tplMarkdown).text(textContent); - } else if (type === 'fixed') { + if (style === 1) { $text = dom(tplText).text(textContent); - } else if (type === 'markdown') { + } else if (style === 2) { $text = dom(tplMarkdown).html(marked(textContent)); - } else { + } else if (style === 3) { $text = dom(tplText); - $code = dom('
').appTo($text);
-
- if (textContent.length < 20000) {
- $code.clr().html(prism.highlight(textContent, prism.languages[type]));
- } else {
- $code.clr().text(textContent);
- win.setTimeout(() => {
- $code.clr().html(prism.highlight(textContent, prism.languages[type]));
- }, 300);
- }
+ const $code = dom('
').text(textContent).appTo($text);
+ win.setTimeout(() => {
+ lolight.el($code[0]);
+ }, textContent.length < 20000 ? 0 : 500);
+ } else {
+ $text = dom(tplMarkdown).text(textContent);
}
win.clearTimeout(spinnerTimeoutId);
@@ -131,13 +125,13 @@ const onEnter = (items, idx) => {
};
const initItem = item => {
- if (item.$view && includes(keys(settings.types), item.type)) {
+ if (item.$view && includes(keys(settings.styles), item.type)) {
item.$view.find('a').on('click', ev => {
ev.preventDefault();
const matchedItems = compact(dom('#items .item').map(el => {
const matchedItem = el._item;
- return includes(keys(settings.types), matchedItem.type) ? matchedItem : null;
+ return includes(keys(settings.styles), matchedItem.type) ? matchedItem : null;
}));
onEnter(matchedItems, matchedItems.indexOf(item));
diff --git a/src/_h5ai/public/js/lib/globals.js b/src/_h5ai/public/js/lib/globals.js
index 0ec76895..13f020d5 100644
--- a/src/_h5ai/public/js/lib/globals.js
+++ b/src/_h5ai/public/js/lib/globals.js
@@ -1,11 +1,3 @@
-const globals = module.exports = {};
-
-const add = (id, as) => {
- if (!global[id]) {
- throw new Error(`no-global: ${id}`);
- }
- globals[as] = global[id];
+module.exports = {
+ win: global.window
};
-
-add('window', 'win');
-add('Prism', 'prism');
diff --git a/src/_h5ai/public/js/pre.js b/src/_h5ai/public/js/pre.js
index d7d76020..5638fe53 100644
--- a/src/_h5ai/public/js/pre.js
+++ b/src/_h5ai/public/js/pre.js
@@ -25,6 +25,3 @@
assert('xhr', isFn(win.XMLHttpRequest));
}(this));
/* eslint-enable */
-
-
-// @include "vendor/*.js"
diff --git a/src/_h5ai/public/js/vendor/prism-2016-07-01.min.js b/src/_h5ai/public/js/vendor/prism-2016-07-01.min.js
deleted file mode 100644
index 6c8a891d..00000000
--- a/src/_h5ai/public/js/vendor/prism-2016-07-01.min.js
+++ /dev/null
@@ -1,12 +0,0 @@
-/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+bash+ruby+go+json+python+rust */
-var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(){var e=/\blang(?:uage)?-(\w+)\b/i,t=0,n=_self.Prism={util:{encode:function(e){return e instanceof a?new a(e.type,n.util.encode(e.content),e.alias):"Array"===n.util.type(e)?e.map(n.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(v instanceof a)){u.lastIndex=0;var b=u.exec(v),k=1;if(!b&&h&&m!=r.length-1){if(u.lastIndex=y,b=u.exec(e),!b)break;for(var w=b.index+(g?b[1].length:0),_=b.index+b[0].length,S=m,P=y,A=r.length;A>S&&_>P;++S)P+=(r[S].matchedStr||r[S]).length,w>=P&&(++m,y=P);if(r[m]instanceof a||r[S-1].greedy)continue;k=S-m,v=e.slice(y,P),b.index-=y}if(b){g&&(f=b[1].length);var w=b.index+f,b=b[0].slice(f),_=w+b.length,x=v.slice(0,w),O=v.slice(_),j=[m,k];x&&j.push(x);var N=new a(i,c?n.tokenize(b,c):b,d,b,h);j.push(N),O&&j.push(O),Array.prototype.splice.apply(r,j)}}}}}return r},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var r,l=0;r=a[l++];)r(t)}}},a=n.Token=function(e,t,n,a,r){this.type=e,this.content=t,this.alias=n,this.matchedStr=a||null,this.greedy=!!r};if(a.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===n.util.type(e))return e.map(function(n){return a.stringify(n,t,e)}).join("");var l={type:e.type,content:a.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if("comment"==l.type&&(l.attributes.spellcheck="true"),e.alias){var i="Array"===n.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(l.classes,i)}n.hooks.run("wrap",l);var o="";for(var s in l.attributes)o+=(o?" ":"")+s+'="'+(l.attributes[s]||"")+'"';return"<"+l.tag+' class="'+l.classes.join(" ")+'" '+o+">"+l.content+""+l.tag+">"},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var t=JSON.parse(e.data),a=t.language,r=t.code,l=t.immediateClose;_self.postMessage(n.highlight(r,n.languages[a],a)),l&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(n.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&("loading"!==document.readyState?requestAnimationFrame(n.highlightAll,0):document.addEventListener("DOMContentLoaded",n.highlightAll))),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism);
-Prism.languages.markup={comment://,prolog:/<\?[\w\W]+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?(?!\d)[^\s>\/=.$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/[=>"']/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Prism.languages.xml=Prism.languages.markup,Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup;
-Prism.languages.css={comment:/\/\*[\w\W]*?\*\//,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^\{\}\s][^\{\};]*?(?=\s*\{)/,string:/("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,property:/(\b|\B)[\w-]+(?=\s*:)/i,important:/\B!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:]/},Prism.languages.css.atrule.inside.rest=Prism.util.clone(Prism.languages.css),Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/(