ui: code formatting with wastyle
parent
496ce16dce
commit
b052e2aa78
@ -1,14 +1,18 @@
|
||||
import { AutoloadPage } from 'vj/misc/Page';
|
||||
import load from 'vj/components/wastyle/index';
|
||||
import Notification from 'vj/components/notification/index';
|
||||
|
||||
const highlighterPage = new AutoloadPage('highlighterPage', () => {
|
||||
import('./prismjs').then((module) => {
|
||||
const prismjs = module.default;
|
||||
function runHighlight($container) {
|
||||
prismjs.highlightBlocks($container);
|
||||
}
|
||||
runHighlight($('body'));
|
||||
$(document).on('vjContentNew', (e) => runHighlight($(e.target)));
|
||||
});
|
||||
const highlighterPage = new AutoloadPage('highlighterPage', async () => {
|
||||
const [{ default: prismjs }, [success, format]] = await Promise.all([
|
||||
import('./prismjs'),
|
||||
load(),
|
||||
]);
|
||||
if (!success) Notification.error(`Astyle load fail: ${format}`);
|
||||
function runHighlight($container) {
|
||||
prismjs.highlightBlocks($container, success ? format : null);
|
||||
}
|
||||
runHighlight($('body'));
|
||||
$(document).on('vjContentNew', (e) => runHighlight($(e.target)));
|
||||
});
|
||||
|
||||
export default highlighterPage;
|
||||
|
@ -0,0 +1,12 @@
|
||||
import astyleBinaryUrl from 'wastyle/dist/astyle-optimize-size.wasm';
|
||||
|
||||
export default async function load() {
|
||||
const { init, format } = await import('wastyle');
|
||||
try {
|
||||
await init(astyleBinaryUrl);
|
||||
console.log('WAstyle is ready!');
|
||||
return [true, format];
|
||||
} catch (e) {
|
||||
return [false, e.message];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue