diff options
-rw-r--r-- | app.js | 44 | ||||
-rw-r--r-- | tohtml.js | 44 |
2 files changed, 49 insertions, 39 deletions
@@ -4,6 +4,8 @@ const fs = require('fs'); const dirTree = require('directory-tree'); const express = require('express'); +const hmd = require('./tohtml'); + const path = 'md'; const app = express(); @@ -13,46 +15,10 @@ process.on('uncaughtException', err => { const report = require('vfile-reporter'); -/* TODO : Send the result of guide : - const guide = require('remark-preset-lint-markdown-style-guide'); -*/ - -const html = require('remark-rehype'); -const kbd = require('remark-kbd'); -const math = require('remark-math'); -const highlight = require('remark-highlight.js'); -const sb = require('remark-special-box'); -const multiChoice = require('remark-multiple-choice'); -const lineInput = require('remark-line-input'); -const select = require('remark-select'); -const textInput = require('remark-text-input'); -const raw = require('rehype-raw'); -const rehypeKatex = require('rehype-katex'); -const rehypeStringify = require('rehype-stringify'); -const unified = require('unified'); -const remark = require('remark-parse'); - const useLandScript = ''; const rawButton = '<button class="raw_button" ><div><div>Raw</div></div></button></form>'; -function toHTML(data, fnc) { - unified() - .use(remark) - .use(lineInput) - .use(textInput) - .use(select) - .use(multiChoice) - .use(math) - .use(kbd) - .use(sb) - .use(highlight) - .use(html, {allowDangerousHTML: true}) - .use(rehypeKatex) - .use(raw) - .use(rehypeStringify) - - .process(data, fnc); -} + app.use(express.static('public')); @@ -96,7 +62,7 @@ app.get(`/${path}/*`, (req, res) => { console.log(inspect(a)); */ - toHTML(data, (err, file) => { + hmd.toHTML(data, (err, file) => { res.send(`${String(file) + useLandScript }<a href="${url}?raw=true" class="no-style">${rawButton}</a>`); console.error(report(err || file)); @@ -154,7 +120,7 @@ app.get('*', (req, res) => { res.status(500).send(html); return; } - toHTML(data, (err, file) => { + hmd.toHTML(data, (err, file) => { if (err) { let html = '<html>'; html += '<body>'; diff --git a/tohtml.js b/tohtml.js new file mode 100644 index 0000000..1d0ae2c --- /dev/null +++ b/tohtml.js @@ -0,0 +1,44 @@ +const path = 'md'; + +const report = require('vfile-reporter'); + +/* TODO : Send the result of guide : + const guide = require('remark-preset-lint-markdown-style-guide'); +*/ + +const html = require('remark-rehype'); +const kbd = require('remark-kbd'); +const math = require('remark-math'); +const highlight = require('remark-highlight.js'); +const sb = require('remark-special-box'); +const multiChoice = require('remark-multiple-choice'); +const lineInput = require('remark-line-input'); +const select = require('remark-select'); +const textInput = require('remark-text-input'); +const raw = require('rehype-raw'); +const rehypeKatex = require('rehype-katex'); +const rehypeStringify = require('rehype-stringify'); +const unified = require('unified'); +const remark = require('remark-parse'); + + +function toHTML(data, fnc) { + unified() + .use(remark) + .use(lineInput) + .use(textInput) + .use(select) + .use(multiChoice) + .use(math) + .use(kbd) + .use(sb) + .use(highlight) + .use(html, {allowDangerousHTML: true}) + .use(rehypeKatex) + .use(raw) + .use(rehypeStringify) + + .process(data, fnc); +} + +module.exports = toHTML; |