This commit is contained in:
undefined committed 2021-05-05 13:01:03 +08:00
1 parent 455f0dc274
commit a5e3cf2c9b
5 files changed
+15 -65

No files matched your search

@@ -24,8 +24,6 @@ const Anchor = require('markdown-it-anchor');
const Media = require('./markdown-it-media');
const Katex = require('./markdown-it-katex');
require('prismjs/components/index');
class Markdown extends MarkdownIt {
constructor() {
super({
@@ -23,11 +23,11 @@ const highlighterPage = new AutoloadPage('highlighterPage', async () => {
const $output = $container.find(`pre.language-output${id}`);
if ($output.length) {
const $c = $(document.createElement('div')).addClass('row');
$root.clone(true).prepend($(tpl`<h2>${i18n('Sample Input')} ${id}</h2>`))
$root.after($c);
$root.prepend($(tpl`<h2>${i18n('Sample Input')} ${id}</h2>`))
.addClass('medium-6 columns sample').appendTo($c);
$output.parent().prepend($(tpl`<h2>${i18n('Sample Output')} ${id}</h2>`))
.addClass('medium-6 columns sample').appendTo($c);
$root.replaceWith($c);
}
}
}
@@ -33,23 +33,19 @@ languageMeta.forEach((meta) => {
});
// Copy to Clipboard
try {
Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
const linkCopy = document.createElement('a');
linkCopy.href = 'javascript:;'; // eslint-disable-line no-script-url
linkCopy.textContent = 'Copy';
const clip = new Clipboard(linkCopy, { text: () => env.code });
clip.on('success', () => {
Notification.success(i18n('Content copied to clipboard!'), 1000);
});
clip.on('error', () => {
Notification.error(i18n('Copy failed :('));
});
return linkCopy;
Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
const linkCopy = document.createElement('a');
linkCopy.href = 'javascript:;'; // eslint-disable-line no-script-url
linkCopy.textContent = 'Copy';
const clip = new Clipboard(linkCopy, { text: () => env.code });
clip.on('success', () => {
Notification.success(i18n('Content copied to clipboard!'), 1000);
});
} catch (e) {
// snowpack
}
clip.on('error', () => {
Notification.error(i18n('Copy failed :('));
});
return linkCopy;
});
const invisibles = {
tab: /\t/,
@@ -90,7 +86,6 @@ function handlerInvisiblesToken(tokens, name) {
}
Prism.hooks.add('before-highlight', (env) => {
console.log(UserContext.showInvisibleChar);
if (UserContext.showInvisibleChar) addInvisibles(env.grammar);
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.6.30",
"version": "4.6.31",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
-43
View File
@@ -1,43 +0,0 @@
const httpProxy = require('http-proxy');
const fs = require('fs');
const reactRefreshLoc = require.resolve('react-refresh/cjs/react-refresh-runtime.development.js');
const reactRefreshCode = `
function d(e,t){let u;return()=>{clearTimeout(u),u=setTimeout(e,t)}};
{ const exports = {};
exports.performReactRefresh=d(exports.performReactRefresh,30);\
${fs.readFileSync(reactRefreshLoc, { encoding: 'utf-8' })
.replace('process.env.NODE_ENV', JSON.stringify('development'))}
window.$RefreshRuntime$=exports;\
window.$RefreshRuntime$.injectIntoGlobalHook(window);\
window.$RefreshReg$=()=>{};\
window.$RefreshSig$=()=>t=>t; }`;
const proxy = httpProxy.createServer({ target: 'http://localhost:2333' });
const dest = (req, res) => proxy.web(req, res, undefined, (e) => console.error(e.message));
const refresh = (req, res) => {
res.write(reactRefreshCode);
res.end();
};
const hmr = async (req, res) => {
// eslint-disable-next-line no-multi-str
req.headers.hmr = Buffer.from('<script src="/react-refresh.js"></script>').toString('base64');
proxy.web(req, res, undefined, (e) => console.error(e.message));
};
module.exports = {
entry: 'hydro.js',
env: process.env,
plugins: [
['./build/plugins/require-context.snowpack', { input: ['misc/PageLoader.js'] }],
'./build/plugins/provide.snowpack',
'@snowpack/plugin-react-refresh',
],
alias: { vj: __dirname },
routes: [
['/.*', 'routes', hmr],
['/react-refresh\\.js', 'all', refresh],
['.+\\.(png|css|json|woff2|woff|ttf)', 'all'],
['(/ui-constants\\.js|/locale/.*)', 'all'],
].map(([src, match, handle]) => ({ src, match, dest: handle || dest })),
};