site: tidy code highlighting

pull/2009/head
Conduitry 6 years ago
parent 37351196b0
commit 2b1f753d72

@ -3,9 +3,8 @@ import path from 'path';
import process_markdown from '../../../utils/_process_markdown.js'; import process_markdown from '../../../utils/_process_markdown.js';
import marked from 'marked'; import marked from 'marked';
// import hljs from 'highlight.js'; import PrismJS from 'prismjs';
import prismjs from 'prismjs'; // prism-highlighter smaller footprint [hljs: 192.5k] import 'prismjs/components/prism-bash';
require('prismjs/components/prism-bash');
// map lang to prism-language-attr // map lang to prism-language-attr
const prismLang = { const prismLang = {
@ -31,10 +30,10 @@ export default function() {
const renderer = new marked.Renderer(); const renderer = new marked.Renderer();
renderer.code = (source, lang) => { renderer.code = (source, lang) => {
let plang = prismLang[lang]; const plang = prismLang[lang];
const highlighted = Prism.highlight( const highlighted = PrismJS.highlight(
source, source,
Prism.languages[plang], PrismJS.languages[plang],
lang, lang,
); );
@ -43,9 +42,7 @@ export default function() {
const html = marked( const html = marked(
content.replace(/^\t+/gm, match => match.split('\t').join(' ')), content.replace(/^\t+/gm, match => match.split('\t').join(' ')),
{ { renderer }
renderer,
},
); );
return { return {
@ -54,7 +51,5 @@ export default function() {
slug: file.replace(/^[\d-]+/, '').replace(/\.md$/, ''), slug: file.replace(/^[\d-]+/, '').replace(/\.md$/, ''),
}; };
}) })
.sort((a, b) => { .sort((a, b) => a.metadata.pubdate < b.metadata.pubdate ? 1 : -1);
return a.metadata.pubdate < b.metadata.pubdate ? 1 : -1;
});
} }

@ -4,13 +4,8 @@ import * as fleece from 'golden-fleece';
import process_markdown from '../../utils/_process_markdown.js'; import process_markdown from '../../utils/_process_markdown.js';
import marked from 'marked'; import marked from 'marked';
import Prism from 'prismjs'; // prism-highlighter smaller footprint [hljs: 192.5k] import PrismJS from 'prismjs';
require('prismjs/components/prism-bash'); import 'prismjs/components/prism-bash';
const langs = {
'hidden-data': 'json',
'html-no-repl': 'html',
};
// map lang to prism-language-attr // map lang to prism-language-attr
const prismLang = { const prismLang = {
@ -20,10 +15,6 @@ const prismLang = {
css: 'css', css: 'css',
}; };
function btoa(str) {
return new Buffer(str).toString('base64');
}
const escaped = { const escaped = {
'"': '&quot;', '"': '&quot;',
"'": '&#39;', "'": '&#39;',
@ -112,13 +103,6 @@ export default function() {
let className = 'code-block'; let className = 'code-block';
if (lang === 'html' && !group) { if (lang === 'html' && !group) {
/* prettier-ignore
-----------------------------------------------
edit vedam
don't know how to access components here
so i hardcoded icon here
-----------------------------------------------
*/
if (!meta || meta.repl !== false) { if (!meta || meta.repl !== false) {
prefix = `<a class='open-in-repl' href='repl?demo=@@${uid}' title='open in REPL'><svg class='icon'><use xlink:href='#maximize-2' /></svg></a>`; prefix = `<a class='open-in-repl' href='repl?demo=@@${uid}' title='open in REPL'><svg class='icon'><use xlink:href='#maximize-2' /></svg></a>`;
} }
@ -140,16 +124,10 @@ export default function() {
if (meta && meta.hidden) return ''; if (meta && meta.hidden) return '';
/* prettier-ignore const plang = prismLang[lang];
----------------------------------------------- const highlighted = PrismJS.highlight(
design-edit vedam
insert prism-highlighter
-----------------------------------------------
*/
let plang = prismLang[lang];
const highlighted = Prism.highlight(
source, source,
Prism.languages[plang], PrismJS.languages[plang],
lang lang
); );

Loading…
Cancel
Save