mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 10:58:33 +00:00
Review comment (#2459)
This commit is contained in:
54
frontend/src/utils/seafile-markdown2html.js
Normal file
54
frontend/src/utils/seafile-markdown2html.js
Normal file
@@ -0,0 +1,54 @@
|
||||
var unified = require('unified');
|
||||
var markdown = require('remark-parse');
|
||||
var slug = require('remark-slug');
|
||||
var breaks = require('remark-breaks');
|
||||
var remark2rehype = require('remark-rehype');
|
||||
var format = require('rehype-format');
|
||||
var raw = require('rehype-raw');
|
||||
var xtend = require('xtend');
|
||||
var toHTML = require('hast-util-to-html');
|
||||
var sanitize = require('hast-util-sanitize');
|
||||
var gh = require('hast-util-sanitize/lib/github');
|
||||
var deepmerge = require('deepmerge').default;
|
||||
|
||||
function stringify(config) {
|
||||
var settings = xtend(config, this.data('settings'));
|
||||
var schema = deepmerge(gh, {
|
||||
"attributes":{
|
||||
"input": [
|
||||
"type",
|
||||
],
|
||||
"li": [
|
||||
"className"
|
||||
],
|
||||
"code":[
|
||||
"className",
|
||||
],
|
||||
},
|
||||
"tagNames": [
|
||||
"input",
|
||||
"code"
|
||||
]
|
||||
});
|
||||
this.Compiler = compiler;
|
||||
|
||||
function compiler(tree) {
|
||||
var hast = sanitize(tree, schema);
|
||||
return toHTML(hast, settings);
|
||||
}
|
||||
}
|
||||
|
||||
var processor = unified()
|
||||
.use(markdown, {commonmark: true})
|
||||
.use(breaks)
|
||||
.use(slug)
|
||||
.use(remark2rehype, {allowDangerousHTML: true})
|
||||
.use(raw)
|
||||
.use(format)
|
||||
.use(stringify);
|
||||
|
||||
var processorGetAST = unified()
|
||||
.use(markdown, {commonmark: true})
|
||||
.use(slug)
|
||||
|
||||
export { processor, processorGetAST };
|
Reference in New Issue
Block a user