Replace prism with lolight.
This commit is contained in:
parent
18dfa1e09f
commit
9e0b1698fc
7 changed files with 52 additions and 82 deletions
|
@ -12,10 +12,9 @@
|
||||||
* adds `rust` type and icon
|
* adds `rust` type and icon
|
||||||
* removes *Install* section from `README.md`, caused to much trouble
|
* removes *Install* section from `README.md`, caused to much trouble
|
||||||
* updates build process to use `node 6.0+`, no need for babel now
|
* 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`
|
||||||
* replaces `jquery-qrcode` with `kjua` 0.1.1
|
* replaces `prism` with `lolight`
|
||||||
* updates `prism` to 2016-07-01
|
* move deps `normalize.css`, `kjua`, `lolight` and `marked` to `package.json`
|
||||||
* move deps `normalize.css`, `kjua` and `marked` to `package.json`
|
|
||||||
* removes `jQuery`
|
* removes `jQuery`
|
||||||
* removes `lodash`
|
* removes `lodash`
|
||||||
* removes `modulejs`
|
* removes `modulejs`
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"eslint": "3.1.1",
|
"eslint": "3.1.1",
|
||||||
"ghu": "0.7.0",
|
"ghu": "0.7.0",
|
||||||
"kjua": "0.1.1",
|
"kjua": "0.1.1",
|
||||||
|
"lolight": "0.3.0",
|
||||||
"marked": "0.3.5",
|
"marked": "0.3.5",
|
||||||
"normalize.css": "4.2.0",
|
"normalize.css": "4.2.0",
|
||||||
"scar": "0.14.0"
|
"scar": "0.14.0"
|
||||||
|
|
|
@ -237,43 +237,42 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Show text file preview on click.
|
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:
|
Available styles are:
|
||||||
- "markdown" to render Markdown text
|
0: floating text
|
||||||
- "none" for floating text
|
1: fixed width text
|
||||||
- "fixed" for 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": {
|
"preview-txt": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"types": {
|
"styles": {
|
||||||
"txt": "fixed",
|
"txt": 1,
|
||||||
"txt-authors": "fixed",
|
"txt-authors": 1,
|
||||||
"txt-c": "clike",
|
"txt-c": 3,
|
||||||
"txt-cpp": "clike",
|
"txt-cpp": 3,
|
||||||
"txt-css": "css",
|
"txt-css": 3,
|
||||||
"txt-diff": "fixed",
|
"txt-diff": 1,
|
||||||
"txt-go": "go",
|
"txt-go": 3,
|
||||||
"txt-h": "clike",
|
"txt-h": 3,
|
||||||
"txt-hpp": "clike",
|
"txt-hpp": 3,
|
||||||
"txt-install": "fixed",
|
"txt-install": 1,
|
||||||
"txt-js": "javascript",
|
"txt-js": 3,
|
||||||
"txt-json": "javascript",
|
"txt-json": 3,
|
||||||
"txt-less": "css",
|
"txt-less": 3,
|
||||||
"txt-license": "fixed",
|
"txt-license": 1,
|
||||||
"txt-log": "fixed",
|
"txt-log": 1,
|
||||||
"txt-makefile": "fixed",
|
"txt-makefile": 1,
|
||||||
"txt-md": "markdown",
|
"txt-md": 2,
|
||||||
"txt-py": "python",
|
"txt-py": 3,
|
||||||
"txt-rb": "ruby",
|
"txt-rb": 3,
|
||||||
"txt-readme": "fixed",
|
"txt-readme": 1,
|
||||||
"txt-rtf": "fixed",
|
"txt-rtf": 1,
|
||||||
"txt-rust": "rust",
|
"txt-rust": 3,
|
||||||
"txt-script": "bash",
|
"txt-script": 3,
|
||||||
"txt-xml": "fixed"
|
"txt-xml": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
const lolight = require('lolight');
|
||||||
const marked = require('marked');
|
const marked = require('marked');
|
||||||
const {each, keys, includes, compact, dom} = require('../../util');
|
const {each, keys, includes, compact, dom} = require('../../util');
|
||||||
const {win, prism} = require('../../globals');
|
const {win} = require('../../globals');
|
||||||
const event = require('../../core/event');
|
const event = require('../../core/event');
|
||||||
const allsettings = require('../../core/settings');
|
const allsettings = require('../../core/settings');
|
||||||
const preview = require('./preview');
|
const preview = require('./preview');
|
||||||
|
@ -9,7 +10,7 @@ const preview = require('./preview');
|
||||||
const XHR = win.XMLHttpRequest;
|
const XHR = win.XMLHttpRequest;
|
||||||
const settings = Object.assign({
|
const settings = Object.assign({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
types: {}
|
styles: {}
|
||||||
}, allsettings['preview-txt']);
|
}, allsettings['preview-txt']);
|
||||||
const tplText = '<pre id="pv-txt-text" class="highlighted"/>';
|
const tplText = '<pre id="pv-txt-text" class="highlighted"/>';
|
||||||
const tplMarkdown = '<div id="pv-txt-text" class="markdown"/>';
|
const tplMarkdown = '<div id="pv-txt-text" class="markdown"/>';
|
||||||
|
@ -86,28 +87,21 @@ const onIdxChange = rel => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = settings.types[currentItem.type];
|
const style = settings.styles[currentItem.type];
|
||||||
let $text;
|
let $text;
|
||||||
let $code;
|
|
||||||
|
|
||||||
if (type === 'none') {
|
if (style === 1) {
|
||||||
$text = dom(tplMarkdown).text(textContent);
|
|
||||||
} else if (type === 'fixed') {
|
|
||||||
$text = dom(tplText).text(textContent);
|
$text = dom(tplText).text(textContent);
|
||||||
} else if (type === 'markdown') {
|
} else if (style === 2) {
|
||||||
$text = dom(tplMarkdown).html(marked(textContent));
|
$text = dom(tplMarkdown).html(marked(textContent));
|
||||||
} else {
|
} else if (style === 3) {
|
||||||
$text = dom(tplText);
|
$text = dom(tplText);
|
||||||
$code = dom('<code/>').appTo($text);
|
const $code = dom('<code/>').text(textContent).appTo($text);
|
||||||
|
win.setTimeout(() => {
|
||||||
if (textContent.length < 20000) {
|
lolight.el($code[0]);
|
||||||
$code.clr().html(prism.highlight(textContent, prism.languages[type]));
|
}, textContent.length < 20000 ? 0 : 500);
|
||||||
} else {
|
} else {
|
||||||
$code.clr().text(textContent);
|
$text = dom(tplMarkdown).text(textContent);
|
||||||
win.setTimeout(() => {
|
|
||||||
$code.clr().html(prism.highlight(textContent, prism.languages[type]));
|
|
||||||
}, 300);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
win.clearTimeout(spinnerTimeoutId);
|
win.clearTimeout(spinnerTimeoutId);
|
||||||
|
@ -131,13 +125,13 @@ const onEnter = (items, idx) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const initItem = item => {
|
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 => {
|
item.$view.find('a').on('click', ev => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
const matchedItems = compact(dom('#items .item').map(el => {
|
const matchedItems = compact(dom('#items .item').map(el => {
|
||||||
const matchedItem = el._item;
|
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));
|
onEnter(matchedItems, matchedItems.indexOf(item));
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
const globals = module.exports = {};
|
module.exports = {
|
||||||
|
win: global.window
|
||||||
const add = (id, as) => {
|
|
||||||
if (!global[id]) {
|
|
||||||
throw new Error(`no-global: ${id}`);
|
|
||||||
}
|
|
||||||
globals[as] = global[id];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
add('window', 'win');
|
|
||||||
add('Prism', 'prism');
|
|
||||||
|
|
|
@ -25,6 +25,3 @@
|
||||||
assert('xhr', isFn(win.XMLHttpRequest));
|
assert('xhr', isFn(win.XMLHttpRequest));
|
||||||
}(this));
|
}(this));
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
|
|
||||||
// @include "vendor/*.js"
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue