markdown-maker 1.10.1 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,114 +0,0 @@
1
- const util = require("./tester.test.js");
2
-
3
- describe("Use of markdown hooks for SSR", () => {
4
- it("should allow a simple hook to be used", () => {
5
- util.put("#mdhook<test>", "sample1.md");
6
-
7
- const parser = new util.Parser("test/test-files/sample1.md");
8
- parser.add_hook("test", () => "hello");
9
- const output = parser.get();
10
-
11
- util.assert.strictEqual(output, "hello\n\n");
12
- });
13
- it("should allow advanced hooks to be used", () => {
14
- util.put(
15
- "#mdadvhook<test>\n<b>Bold</b>\n<p>Paragraph</p>\n#mdendhook",
16
- "sample1.md"
17
- );
18
-
19
- const replacer = (arg) => {
20
- const elem = new util.html.HTMLElement("p", {});
21
- elem.set_content("complete");
22
- return elem;
23
- };
24
-
25
- const parser = new util.Parser("test/test-files/sample1.md");
26
- parser.opts.allow_undefined = true;
27
- parser.add_adv_hook("test", replacer);
28
- const output = parser.get();
29
-
30
- util.assert.strictEqual(output, "<p>complete</p>\n\n");
31
- });
32
- it("should allow for hooks to be used in HTML", () => {
33
- util.put("<html><body>#mdhook<test></body></html>", "sample1.html");
34
-
35
- const parser = new util.Parser("test/test-files/sample1.html");
36
- parser.opts.allow_undefined = true;
37
- parser.add_hook("test", () => "hello");
38
- const output = parser.get();
39
-
40
- util.assert.strictEqual(output, "<html><body>hello</body></html>\n\n");
41
- });
42
- it("should allow for hooks to be used in HTML with advanced hooks", () => {
43
- util.put(
44
- "<html><body>#mdadvhook<test>\n<b>Bold</b>\n<p>Paragraph</p>\n#mdendhook</body></html>",
45
- "sample1.html"
46
- );
47
-
48
- const replacer = (arg) => {
49
- const elem = new util.html.HTMLElement("p", {});
50
- elem.set_content("complete");
51
- return elem;
52
- };
53
-
54
- const parser = new util.Parser("test/test-files/sample1.html");
55
- parser.opts.allow_undefined = true;
56
- parser.add_adv_hook("test", replacer);
57
- const output = parser.get();
58
-
59
- util.assert.strictEqual(
60
- output,
61
- "<html><body><p>complete</p></body></html>\n\n"
62
- );
63
- });
64
- it("should allow for extracting a node from the document as a template manually with ids", () => {
65
- util.put(
66
- `<html><body>#mdadvhook<template><name id="b"></name><class id="p"></class>#mdendhook</body></html>`,
67
- "sample1.html"
68
- );
69
-
70
- const replacer = (elem) => {
71
- const nameElem = elem.getElementsByTagName("name")[0];
72
- nameElem.tagName = nameElem.id;
73
- nameElem.removeAttribute("id");
74
- nameElem.set_content("bold");
75
- const classElem = elem.getElementsByTagName("class")[0];
76
- classElem.tagName = classElem.id;
77
- classElem.removeAttribute("id");
78
- classElem.set_content("paragraph");
79
- return elem;
80
- };
81
-
82
- const parser = new util.Parser("test/test-files/sample1.html");
83
- parser.opts.allow_undefined = true;
84
- parser.add_adv_hook("template", replacer);
85
- const output = parser.get();
86
-
87
- util.assert.strictEqual(
88
- output,
89
- "<html><body><b>bold</b><p>paragraph</p></body></html>\n\n"
90
- );
91
- });
92
- it("should allow for extracting a node from the document as a template using map and data-tags", () => {
93
- util.put(
94
- `<html><body>#mdadvhook<template><name data-tag="b"></name><class data-tag="p"></class>#mdendhook</body></html>`,
95
- "sample1.html"
96
- );
97
-
98
- const replacer = (elem, map) => {
99
- map["name"].set_content("bold");
100
- map["class"].set_content("paragraph");
101
- return elem;
102
- };
103
-
104
- const parser = new util.Parser("test/test-files/sample1.html");
105
- parser.opts.allow_undefined = true;
106
- parser.add_adv_hook("template", replacer);
107
- const output = parser.get();
108
-
109
- util.assert.strictEqual(
110
- output,
111
- "<html><body><b>bold</b><p>paragraph</p></body></html>\n\n"
112
- );
113
- });
114
- });
package/test/html.test.js DELETED
@@ -1,37 +0,0 @@
1
- const util = require("./tester.test.js");
2
-
3
- describe("HTML Emitting", () => {
4
- it("should emit an html file", (done) => {
5
- const parser = new util.Parser("# sum title\nand a paragraph");
6
- parser.opts.html = true;
7
- parser.opts.quiet = true;
8
-
9
- parser.to("test/test-files/dist/bundle.md", () => {
10
- util.assert.strictEqual(
11
- util.fs.existsSync("test/test-files/dist/bundle.html"),
12
- true
13
- );
14
- done();
15
- });
16
- });
17
- it("should generate valid html", () => {
18
- const parser = new util.Parser("# cool title\nwith a cool paragraph");
19
- parser.opts.html = true;
20
-
21
- const output = parser.html();
22
-
23
- util.assert.strictEqual(
24
- output,
25
- '<h1 id="cool-title">cool title</h1>\n<p>with a cool paragraph</p>\n'
26
- );
27
- });
28
- it("should be able to include html documents, and not parse", () => {
29
- util.put("#mdinclude<sample2.html>", "sample1.md");
30
- util.put("#mdvar<lul>", "sample2.html");
31
-
32
- const parser = new util.Parser("test/test-files/sample1.md");
33
- const output = parser.get();
34
-
35
- util.assert.strictEqual(output, "#mdvar<lul>\n\n");
36
- });
37
- });
package/test/line.test.js DELETED
@@ -1,21 +0,0 @@
1
- const util = require("./tester.test");
2
-
3
- describe("Managing blank lines", () => {
4
- it("should always end with 2 blank lines, even with no input", () => {
5
- const output = new util.Parser("").get();
6
- util.assert.strictEqual(output, "\n\n");
7
- });
8
-
9
- it("should reduce blank lines to 2", () => {
10
- const output1 = new util.Parser("\n\n\n\n").get();
11
- util.assert.strictEqual(output1, "\n\n");
12
-
13
- const output2 = new util.Parser("\n\n\n\nHello!").get();
14
- util.assert.strictEqual(output2, "\n\nHello!\n\n");
15
- });
16
-
17
- it("should allow words when removing blank lines", () => {
18
- const output = new util.Parser("hii\n\n\n").get();
19
- util.assert.strictEqual(output, "hii\n\n");
20
- });
21
- });
@@ -1,43 +0,0 @@
1
- const util = require("./tester.test.js");
2
-
3
- describe("Marked extentions", () => {
4
- it("should add a single class to blockquotes", () => {
5
- const parser = new util.Parser("> hello {.one}", {
6
- use_underscore: true,
7
- html: true,
8
- });
9
-
10
- const output = parser.html();
11
-
12
- util.assert.strictEqual(
13
- output,
14
- '<blockquote class="one" >\n<p>hello </p></blockquote>'
15
- );
16
- });
17
- it("should add multiple class to blockquotes", () => {
18
- const parser = new util.Parser("> hello {.one .two}", {
19
- use_underscore: true,
20
- html: true,
21
- });
22
-
23
- const output = parser.html();
24
-
25
- util.assert.strictEqual(
26
- output,
27
- '<blockquote class="one two" >\n<p>hello </p></blockquote>'
28
- );
29
- });
30
- it("should add a single class and id to blockquotes", () => {
31
- const parser = new util.Parser("> hello {.one #myid}", {
32
- use_underscore: true,
33
- html: true,
34
- });
35
-
36
- const output = parser.html();
37
-
38
- util.assert.strictEqual(
39
- output,
40
- '<blockquote class="one" id="myid">\n<p>hello </p></blockquote>'
41
- );
42
- });
43
- });
@@ -1,43 +0,0 @@
1
- const util = require("./tester.test.js");
2
-
3
- describe("Target specific functionality", () => {
4
- describe("HTML", () => {
5
- it("Should include `#mdlabel` command, when compiling HTML", () => {
6
- const parser = new util.Parser("#mdlabel<0,Cool!>");
7
- const html = parser.get(util.TargetType.HTML);
8
-
9
- util.assert.strictEqual(html, '<span id="cool"></span>\n\n');
10
- });
11
-
12
- it("Should link to sections with #mdref", () => {
13
- const parser = new util.Parser(
14
- "#mdlabel<0,Cool!>\n#mdlabel<1,coolzz>\n#mdref<Cool!>"
15
- );
16
- const html = parser.get(util.TargetType.HTML);
17
-
18
- util.assert.strictEqual(
19
- html,
20
- '<span id="cool"></span>\n<span id="coolzz"></span>\n<a href="#cool">Cool!</a>\n\n'
21
- );
22
- });
23
- });
24
-
25
- describe("Markdown", () => {
26
- it("Should not include `#mdlabel` command, when compiling Markdown", () => {
27
- const parser = new util.Parser("#mdlabel<0,Cool!>");
28
-
29
- const md = parser.get(util.TargetType.MARKDOWN);
30
- util.assert.strictEqual(md, "\n\n");
31
- });
32
- it("Should include #mdref to title elements in markdown", () => {
33
- const output = new util.Parser(
34
- "# Some Title!\n#mdref<Some Title!>"
35
- ).get();
36
-
37
- util.assert.strictEqual(
38
- output,
39
- "# Some Title!\n[Some Title!](#some-title)\n\n"
40
- );
41
- });
42
- });
43
- });
@@ -1,41 +0,0 @@
1
- const fs = require("fs");
2
- const assert = require("assert");
3
- const Parser = require("../build/parse");
4
- const path = require("path");
5
- const html = require("node-html-parser");
6
-
7
- /* make folder for temporary files, if it doesn't exist */
8
- if (
9
- !fs.existsSync("test/test-files") ||
10
- !fs.lstatSync("test/test-files").isDirectory()
11
- ) {
12
- fs.mkdirSync("test/test-files");
13
- }
14
-
15
- /**
16
- * Create a new file under `test/test-files` with the given content.
17
- * @param {string} text
18
- * @param {string} file
19
- */
20
- function put(text, file) {
21
- fs.writeFileSync(path.join("test", "test-files", file), text);
22
- }
23
- function putDir(name) {
24
- fs.mkdirSync(path.join("test", "test-files", name));
25
- }
26
-
27
- const TargetType = {
28
- HTML: 0,
29
- MARKDOWN: 1,
30
- };
31
-
32
- module.exports = {
33
- assert,
34
- fs,
35
- html,
36
- path,
37
- Parser,
38
- put,
39
- putDir,
40
- TargetType,
41
- };
package/test/vars.test.js DELETED
@@ -1,49 +0,0 @@
1
- const util = require("./tester.test.js");
2
-
3
- describe("Use variables", () => {
4
- it("should replace var with the value", () => {
5
- const output = new util.Parser("#mddef<hi=yo>\n#mdvar<hi>").get();
6
-
7
- util.assert.strictEqual(output, "\nyo\n\n");
8
- });
9
- it("should use variable shorthand", () => {
10
- const output = new util.Parser("#mddef<hi=yo>\n<hi>").get();
11
-
12
- util.assert.strictEqual(output, "\nyo\n\n");
13
- });
14
- it("should use variables across files", () => {
15
- util.put("#mddef<hi=yo>\n#mdinclude<sample2.md>", "sample1.md");
16
- util.put("<hi>", "sample2.md");
17
-
18
- const output = new util.Parser("test/test-files/sample1.md").get();
19
-
20
- util.assert.strictEqual(output, "\nyo\n\n");
21
- });
22
- it("should throw if undefined variable", () => {
23
- const parser = new util.Parser("<yo>");
24
-
25
- let e;
26
- /* should throw an error */
27
- util.assert.throws(() => {
28
- try {
29
- parser.get();
30
- } catch (_e) {
31
- e = _e;
32
- throw _e;
33
- }
34
- });
35
- });
36
-
37
- it("should preserve whatever comes after", () => {
38
- const output = new util.Parser("#mddef<hi=yo>\n<hi>,").get();
39
- util.assert.strictEqual(output, "\nyo,\n\n");
40
- });
41
-
42
- it("should replace underscore with space", () => {
43
- const output = new util.Parser(
44
- "#mddef<name=Mr_Sir>\n#mdvar<name>"
45
- ).get();
46
-
47
- util.assert.strictEqual(output, "\nMr Sir\n\n");
48
- });
49
- });