From ab5b69f87cca37bffd53c914b66f6540a14e6dd0 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 13 Apr 2018 12:01:17 +0200 Subject: tohtml is now in a new file --- app.js | 44 +++++--------------------------------------- tohtml.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 39 deletions(-) create mode 100644 tohtml.js diff --git a/app.js b/app.js index 85687e0..2e7c8d0 100644 --- a/app.js +++ b/app.js @@ -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 = ''; -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 }${rawButton}`); 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 += ''; 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; -- cgit v1.2.3