markdown-maker 1.9.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/node.js.yml +1 -1
- package/build/cltool.d.ts +1 -0
- package/build/cltool.js +161 -0
- package/build/cltool.js.map +1 -0
- package/build/commands.d.ts +43 -0
- package/build/commands.js +223 -0
- package/build/commands.js.map +1 -0
- package/build/parse.d.ts +65 -0
- package/build/parse.js +281 -0
- package/build/parse.js.map +1 -0
- package/build/templates.d.ts +10 -0
- package/build/templates.js +20 -0
- package/build/templates.js.map +1 -0
- package/package.json +2 -2
- package/src/cltool.ts +11 -3
- package/src/commands.ts +44 -40
- package/src/parse.ts +13 -19
- package/src/templates/configTemplate.json +13 -0
- package/test/advanced.test.js +10 -8
- package/test/basic.test.js +11 -0
- package/test/errors.test.js +23 -1
- package/test/hooks.js +9 -0
- package/test/tester.test.js +12 -3
package/test/advanced.test.js
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
const util = require("./tester.test.js");
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
const putTemplate = () => {
|
4
|
+
util.put(
|
5
|
+
"module.exports = {main: (new_template, new_command) => {new_template('hi', 'hello'); new_command(/#test_cmd/, (t,p) => 'yeet', 0);}};",
|
6
|
+
"extensions.js"
|
7
|
+
);
|
8
|
+
};
|
7
9
|
|
8
10
|
describe("Use of templates", () => {
|
11
|
+
beforeEach(putTemplate);
|
9
12
|
it("should import presentation template as expected", () => {
|
13
|
+
putTemplate();
|
10
14
|
const output = new util.Parser("#mdtemplate<presentation>").get();
|
11
15
|
const template = `<style>html {width: 100vw;height: 100vh;}.slide {padding: 5%;border-radius: 25px;margin: 0;}div > .slide-num {position: absolute;top: 12.5%;right: 15%;/* font-size: 150%; */}body {margin: 5% 15%;}img {max-width: 100%;max-height: 40vh;}</style><script>document.addEventListener("DOMContentLoaded", () => {let current_slide = 0;const all_slides = document.querySelectorAll("div.slide");const num_slides = all_slides.length;all_slides.forEach((slide) => {const num_elem = document.createElement("p");num_elem.classList.add("slide-num");slide.appendChild(num_elem);});onkeydown = (ev) => {if (ev.key == "ArrowRight" && current_slide < all_slides.length - 1)update_slide(++current_slide);else if (ev.key == "ArrowLeft" && current_slide > 0)update_slide(--current_slide);};const update_slide = (index) => {all_slides.forEach((slide) => (slide.style.display = "none"));all_slides[current_slide].style.display = "block";all_slides[current_slide].lastChild.textContent = \`\${current_slide + 1} / \${num_slides}\`;};update_slide(current_slide);});</script>`;
|
12
16
|
|
@@ -14,22 +18,20 @@ describe("Use of templates", () => {
|
|
14
18
|
});
|
15
19
|
|
16
20
|
it("should use custom templates from project extensions.js file", () => {
|
21
|
+
putTemplate();
|
17
22
|
util.put("#mdtemplate<hi>", "sample1.md");
|
18
23
|
|
19
24
|
util.assert.strictEqual(
|
20
25
|
new util.Parser("test/test-files/sample1.md").get(),
|
21
26
|
"hello\n\n"
|
22
27
|
);
|
23
|
-
|
24
|
-
/* make sure to remove after, to not mess with future tests */
|
25
28
|
});
|
26
29
|
|
27
30
|
it("should use custom commands from project extensions.js file", () => {
|
31
|
+
putTemplate();
|
28
32
|
util.put("#test_cmd", "sample1.md");
|
29
33
|
|
30
34
|
const parser = new util.Parser("test/test-files/sample1.md");
|
31
35
|
util.assert.strictEqual(parser.get(), "yeet\n\n");
|
32
|
-
|
33
|
-
/* make sure to remove after, to not mess with future tests */
|
34
36
|
});
|
35
37
|
});
|
package/test/basic.test.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
const path = require("path");
|
1
2
|
const util = require("./tester.test.js");
|
2
3
|
|
3
4
|
describe("Basic features", () => {
|
@@ -54,4 +55,14 @@ describe("Basic features", () => {
|
|
54
55
|
|
55
56
|
util.assert.strictEqual(parser.get(), "### Title\n[Title](#title)\n\n");
|
56
57
|
});
|
58
|
+
it("should include file with same name as folder when including a folder", () => {
|
59
|
+
util.put("#mdinclude<sample_fld>", "sample1.md");
|
60
|
+
util.putDir("sample_fld");
|
61
|
+
util.put("hello", util.path.join("sample_fld", "sample_fld.md"));
|
62
|
+
|
63
|
+
const parser = new util.Parser("test/test-files/sample1.md");
|
64
|
+
const output = parser.get();
|
65
|
+
|
66
|
+
util.assert.strictEqual(output, "hello\n\n");
|
67
|
+
});
|
57
68
|
});
|
package/test/errors.test.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
const { Parser } = require("marked");
|
2
1
|
const util = require("./tester.test.js");
|
2
|
+
const fs = require("fs");
|
3
3
|
|
4
4
|
describe("Error handling", () => {
|
5
5
|
it("should dissallow undefined templates", () => {
|
@@ -23,4 +23,26 @@ describe("Error handling", () => {
|
|
23
23
|
|
24
24
|
util.assert.strictEqual(e.message.replace(/(\\)+/g, "/"), answer);
|
25
25
|
});
|
26
|
+
it("should dissallow loading a folder without an entry file", () => {
|
27
|
+
util.put("#mdinclude<sample_fld>", "sample1.md");
|
28
|
+
util.putDir("sample_fld");
|
29
|
+
|
30
|
+
const parser = new util.Parser("test/test-files/sample1.md");
|
31
|
+
|
32
|
+
let e;
|
33
|
+
util.assert.throws(() => {
|
34
|
+
try {
|
35
|
+
parser.get();
|
36
|
+
} catch (_e) {
|
37
|
+
e = _e;
|
38
|
+
throw _e;
|
39
|
+
}
|
40
|
+
}, Error);
|
41
|
+
|
42
|
+
let answer =
|
43
|
+
'No entry file found in folder "sample_fld". Looking for "sample_fld.md"' +
|
44
|
+
"\n...on line 1 in test/test-files/sample1.md".grey(15);
|
45
|
+
|
46
|
+
util.assert.strictEqual(e.message.replace(/(\\)+/g, "/"), answer);
|
47
|
+
});
|
26
48
|
});
|
package/test/hooks.js
ADDED
package/test/tester.test.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
const fs = require("fs");
|
2
2
|
const assert = require("assert");
|
3
3
|
const Parser = require("../build/parse");
|
4
|
-
|
5
|
-
|
4
|
+
const path = require("path");
|
6
5
|
|
7
6
|
/* make folder for temporary files, if it doesn't exist */
|
8
7
|
if (
|
@@ -12,8 +11,16 @@ if (
|
|
12
11
|
fs.mkdirSync("test/test-files");
|
13
12
|
}
|
14
13
|
|
14
|
+
/**
|
15
|
+
* Create a new file under `test/test-files` with the given content.
|
16
|
+
* @param {string} text
|
17
|
+
* @param {string} file
|
18
|
+
*/
|
15
19
|
function put(text, file) {
|
16
|
-
fs.writeFileSync("test
|
20
|
+
fs.writeFileSync(path.join("test", "test-files", file), text);
|
21
|
+
}
|
22
|
+
function putDir(name) {
|
23
|
+
fs.mkdirSync(path.join("test", "test-files", name));
|
17
24
|
}
|
18
25
|
|
19
26
|
const TargetType = {
|
@@ -24,7 +31,9 @@ const TargetType = {
|
|
24
31
|
module.exports = {
|
25
32
|
fs,
|
26
33
|
assert,
|
34
|
+
path,
|
27
35
|
Parser,
|
28
36
|
put,
|
37
|
+
putDir,
|
29
38
|
TargetType,
|
30
39
|
};
|