Update dependencies
This commit is contained in:
@ -1,14 +1,22 @@
|
||||
import visit from 'unist-util-visit';
|
||||
|
||||
import hljs from 'highlight.js/lib/highlight';
|
||||
import xml from 'highlight.js/lib/languages/xml';
|
||||
import python from 'highlight.js/lib/languages/python';
|
||||
import javascript from 'highlight.js/lib/languages/javascript';
|
||||
import json from 'highlight.js/lib/languages/json';
|
||||
import java from 'highlight.js/lib/languages/java';
|
||||
import objectivec from 'highlight.js/lib/languages/objectivec';
|
||||
import swift from 'highlight.js/lib/languages/swift';
|
||||
import bash from 'highlight.js/lib/languages/bash';
|
||||
|
||||
hljs.registerLanguage('python', python);
|
||||
hljs.registerLanguage('xml', xml);
|
||||
hljs.registerLanguage('javascript', javascript);
|
||||
hljs.registerLanguage('json', json);
|
||||
hljs.registerLanguage('objc', objectivec);
|
||||
hljs.registerLanguage('swift', swift);
|
||||
hljs.registerLanguage('java', java);
|
||||
hljs.registerLanguage('bash', bash);
|
||||
|
||||
/**
|
||||
@ -17,22 +25,10 @@ hljs.registerLanguage('bash', bash);
|
||||
*/
|
||||
export default function attacher() {
|
||||
function visitor(node) {
|
||||
if (!node.lang) {
|
||||
return;
|
||||
if (node.lang) {
|
||||
node.type = 'html';
|
||||
node.value = `<pre class='hljs'>${hljs.highlightAuto(node.value, [node.lang]).value}</pre>`;
|
||||
}
|
||||
|
||||
let data = node.data;
|
||||
|
||||
if (!data) {
|
||||
node.data = data = {};
|
||||
}
|
||||
|
||||
data.htmlContent = hljs.highlightAuto(node.value, [node.lang]).value;
|
||||
data.htmlAttributes = data.htmlAttributes || {};
|
||||
data.htmlAttributes.class = [
|
||||
'hljs',
|
||||
data.htmlAttributes.class
|
||||
].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
return ast => visit(ast, 'code', visitor);
|
||||
|
Reference in New Issue
Block a user