-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
58 lines (48 loc) · 1.27 KB
/
mod.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import help from "./help.ts";
import styles from "./styles.ts";
import showdown from "https://esm.sh/[email protected]";
const input = Deno.args[0];
const output = Deno.args[1] || "index.html";
// ~No input? Jeez~
if (!input) {
console.log(help.trim());
Deno.exit(1);
}
// Read the file
const markdown = await Deno.readTextFile(input).catch(() => {
console.error(`Seems like there is no ${input} file in there...`);
Deno.exit(1);
});
// Converter from md to html
const converter = new showdown.Converter({
ghCompatibleHeaderId: true,
openLinksInNewWindow: true,
ghMentions: true,
tables: true,
});
// Use GitHub's Flavor
showdown.setFlavor('github');
// Post beginning of HTML file
const preContent = `
<html lang="en">
<head>
<title>` + input.replace(".md", "") + `</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id='content'>
`;
// Post ending of HTML file
const postContent = `
</div>
<style>` + styles + `</style>
</body>
</html>
`;
// converter.setFlavor("github");
// Complete
const html = preContent.trim() + converter.makeHtml(markdown) + postContent.trim();
// Partial
// const html = converter.makeHtml(markdown);
// Write converted output to file
await Deno.writeTextFile(output, html);