move docs, remove katex

This commit is contained in:
undefined committed 2020-07-20 16:03:22 +08:00
1 parent da6002278d
commit c4a13f2e27
27 files changed
+190 -550

No files matched your search

+19 -37
View File
@@ -17,21 +17,15 @@ belong to the previous footnote.
import Footnote from 'markdown-it-footnote';
// ==Highlight==
import Mark from 'markdown-it-mark';
// :::warn This page requires javascript. :::
// :::record-pass Accepted :::
import Container from 'markdown-it-container';
import TOC from 'markdown-it-table-of-contents';
import Anchor from 'markdown-it-anchor';
import katex from '../markdown/katex';
const md = MarkdownIt();
require('prismjs/components/index');
type Plugin = MarkdownIt.PluginSimple | MarkdownIt.PluginWithOptions | MarkdownIt.PluginWithParams;
class Markdown extends MarkdownIt {
constructor(safe) {
constructor() {
super({
linkify: true,
highlight(str, lang) {
@@ -42,44 +36,32 @@ class Markdown extends MarkdownIt {
}
return '';
},
html: !safe,
});
this.linkify.tlds('.py', false);
this.use(katex);
this.use(Imsize);
this.use(Footnote);
this.use(Mark);
this.use(Anchor);
this.use(TOC);
const RE_CONTAINER = /^(note|warn|record-pending|record-progress|record-fail|record-pass|record-ignored)\s+(.*?):::(.*)$/;
const CONTAINER_MAP = {
note: ['<blockquote class="note">', '</blockquote>'],
warn: ['<blockquote class="warn">', '</blockquote>'],
'record-pending': ['<span class="record-status--text pending">', '</span>'],
'record-progress': ['<span class="record-status--text progress">', '</span>'],
'record-fail': ['<span class="record-status--text fail">', '</span>'],
'record-pass': ['<span class="record-status--text pass">', '</span>'],
'record-ignored': ['<span class="record-status--text ignored">', '</span>'],
};
this.use(Container, 'blockquote', {
validate(params) {
return params.trim().match(RE_CONTAINER);
},
render(tokens, idx) {
const m = tokens[idx].info.trim().match(RE_CONTAINER);
if (!m) return '';
if (CONTAINER_MAP[m[1]]) {
return `${CONTAINER_MAP[m[1]][0]}${md.utils.escapeHtml(m[2])}\n${CONTAINER_MAP[m[1]][1]}\n${md.utils.escapeHtml(m[3])}`;
}
return `[${m[1]}]\n${md.utils.escapeHtml(m[2])}\n[/${m[1]}]\n${md.utils.escapeHtml(m[3])}`;
},
});
}
}
export const safe = new Markdown(true);
export const unsafe = new Markdown(false);
export const md = new Markdown();
export function plugin(func: Plugin, ...args: any[]) {
md.use(func, ...args);
}
export function render(text: string, html = false) {
md.set({ html: !!html });
return md.render(text);
}
export function renderInline(text: string, html = false) {
md.set({ html: !!html });
return md.renderInline(text);
}
global.Hydro.lib.markdown = {
safe, unsafe,
md, plugin, render, renderInline,
};
+1 -4
View File
@@ -35,10 +35,7 @@ class Nunjucks extends nunjucks.Environment {
this.addFilter('json', (self) => JSON.stringify(self), false);
this.addFilter('serialize', (self, ignoreFunction = true) => serialize(self, { ignoreFunction }));
this.addFilter('assign', (self, data) => Object.assign(self, data));
this.addFilter('markdown', (self, safe = true) => {
if (safe) return markdown.safe.render(self);
return markdown.unsafe.render(self);
});
this.addFilter('markdown', (self, html = false) => markdown.render(self, html));
this.addFilter('ansi', (self) => misc.ansiToHtml(self));
this.addFilter('base64_encode', (s) => Buffer.from(s).toString('base64'));
this.addFilter('bitand', (self, val) => self & val);