-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (34 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ASCIIDOC EDITOR
// Written by Alexander Neri 04 June 2023
// github.com/alexneri/asciiedit
const express = require('express');
const asciidoctor = require('asciidoctor')();
const TurndownService = require('turndown');
const { exec } = require('child_process');
const app = express();
const port = 3000;
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.get('/', (req, res) => {
res.render('index');
});
app.post('/preview', express.text({ type: '*/*' }), (req, res) => {
const asciidocSource = req.body;
const html = asciidoctor.convert(asciidocSource);
res.send(html);
});
app.post('/reverse', express.text({ type: '*/*' }), (req, res) => {
const html = req.body;
const turndownService = new TurndownService();
const markdown = turndownService.turndown(html);
exec(`echo "${markdown}" | pandoc -f markdown -t asciidoc`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
res.send(stdout);
});
});
app.listen(port, () => {
console.log(`Asciidoc Editor listening at http://localhost:${port}`);
});