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
|
||||
* 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`
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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 = '<pre id="pv-txt-text" class="highlighted"/>';
|
||||
const tplMarkdown = '<div id="pv-txt-text" class="markdown"/>';
|
||||
|
@ -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('<code/>').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('<code/>').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));
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -25,6 +25,3 @@
|
|||
assert('xhr', isFn(win.XMLHttpRequest));
|
||||
}(this));
|
||||
/* eslint-enable */
|
||||
|
||||
|
||||
// @include "vendor/*.js"
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue