markdown-maker 1.10.2 → 1.10.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/node.js.yml +21 -26
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +8 -3
- package/.vscode/snippets.code-snippets +6 -8
- package/jest.config.js +7 -0
- package/package.json +41 -40
- package/src/cltool.ts +113 -71
- package/src/commands.ts +237 -243
- package/src/errors.ts +26 -0
- package/src/main.ts +110 -109
- package/src/parser.ts +378 -350
- package/src/templates.ts +5 -1
- package/src/types.ts +33 -0
- package/tests/_test-util.ts +44 -0
- package/tests/advanced.spec.ts +92 -0
- package/tests/basic.spec.ts +68 -0
- package/tests/clargs.spec.ts +50 -0
- package/tests/errors.spec.ts +64 -0
- package/tests/html.spec.ts +23 -0
- package/tests/line.spec.ts +21 -0
- package/tests/marked.spec.ts +40 -0
- package/tests/target.spec.ts +41 -0
- package/tests/vars.spec.ts +45 -0
- package/tsconfig.json +66 -64
- package/prettierrc.yaml +0 -4
- package/test/advanced.test.js +0 -34
- package/test/basic.test.js +0 -67
- package/test/clargs.test.js +0 -51
- package/test/errors.test.js +0 -47
- package/test/hooks.js +0 -9
- package/test/hooks.test.js +0 -114
- package/test/html.test.js +0 -37
- package/test/line.test.js +0 -21
- package/test/marked.test.js +0 -43
- package/test/target.test.js +0 -43
- package/test/tester.test.js +0 -41
- package/test/vars.test.js +0 -49
package/tsconfig.json
CHANGED
@@ -1,74 +1,76 @@
|
|
1
1
|
{
|
2
|
-
|
2
|
+
"include": ["./src/**/*"],
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
"compilerOptions": {
|
5
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
7
|
+
/* Bas1c Options */
|
8
|
+
// "incremental": true, /* Enable incremental compilation */
|
9
|
+
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
|
10
|
+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
11
|
+
"lib": [
|
12
|
+
"ES2022"
|
13
|
+
] /* Specify library files to be included in the compilation. */,
|
14
|
+
"allowJs": true /* Allow javascript files to be compiled. */,
|
15
|
+
"checkJs": true /* Report errors in .js files. */,
|
16
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
17
|
+
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
18
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
19
|
+
"sourceMap": true /* Generates corresponding '.map' file. */,
|
20
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
21
|
+
"outDir": "./bundle" /* Redirect output structure to the directory. */,
|
22
|
+
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
23
|
+
// "composite": true, /* Enable project compilation */
|
24
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
25
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
26
|
+
// "noEmit": true, /* Do not emit outputs. */
|
27
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
28
|
+
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
|
29
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
/* Strict Type-Checking Options */
|
32
|
+
// "strict": true /* Enable all strict type-checking options. */,
|
33
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
34
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
35
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
36
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
37
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
38
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
39
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
/* Additional Checks */
|
42
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
43
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
44
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
45
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
46
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
47
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
48
|
+
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
/* Module Resolution Options */
|
51
|
+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
52
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
53
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
54
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
55
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
56
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
57
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
58
|
+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
59
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
60
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
/* Source Map Options */
|
63
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
64
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
65
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
66
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
/* Experimental Options */
|
69
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
70
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
/* Advanced Options */
|
73
|
+
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
74
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
75
|
+
}
|
74
76
|
}
|
package/prettierrc.yaml
DELETED
package/test/advanced.test.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
const util = require("./tester.test.js");
|
2
|
-
|
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
|
-
};
|
9
|
-
|
10
|
-
describe("Use of templates", () => {
|
11
|
-
beforeEach(putTemplate);
|
12
|
-
it("should import presentation template as expected", () => {
|
13
|
-
const output = new util.Parser("#mdtemplate<presentation>").get();
|
14
|
-
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>`;
|
15
|
-
|
16
|
-
util.assert.strictEqual(output, template + "\n\n");
|
17
|
-
});
|
18
|
-
|
19
|
-
it("should use custom templates from project extensions.js file", () => {
|
20
|
-
util.put("#mdtemplate<hi>", "sample1.md");
|
21
|
-
|
22
|
-
util.assert.strictEqual(
|
23
|
-
new util.Parser("test/test-files/sample1.md").get(),
|
24
|
-
"hello\n\n"
|
25
|
-
);
|
26
|
-
});
|
27
|
-
|
28
|
-
it("should use custom commands from project extensions.js file", () => {
|
29
|
-
util.put("#test_cmd", "sample1.md");
|
30
|
-
|
31
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
32
|
-
util.assert.strictEqual(parser.get(), "yeet\n\n");
|
33
|
-
});
|
34
|
-
});
|
package/test/basic.test.js
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
const util = require("./tester.test.js");
|
2
|
-
|
3
|
-
describe("Basic features", () => {
|
4
|
-
it("should join two files with include", () => {
|
5
|
-
util.put("hello\n#mdinclude<sample2.md>", "sample1.md");
|
6
|
-
util.put("there", "sample2.md");
|
7
|
-
|
8
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
9
|
-
const output = parser.get();
|
10
|
-
|
11
|
-
util.assert.strictEqual(output, "hello\nthere\n\n");
|
12
|
-
});
|
13
|
-
it("should make a table of contents", () => {
|
14
|
-
const output = new util.Parser(
|
15
|
-
"# yo\n## bruh nugget\n#mdmaketoc"
|
16
|
-
).get();
|
17
|
-
|
18
|
-
util.assert.strictEqual(
|
19
|
-
output,
|
20
|
-
"# yo\n## bruh nugget\n* [yo](#yo)\n * [bruh nugget](#bruh-nugget)\n\n"
|
21
|
-
);
|
22
|
-
});
|
23
|
-
it("should allow quotation marks in titles for toc", () => {
|
24
|
-
const parser = new util.Parser("# mac's farm\n#mdmaketoc");
|
25
|
-
const markdown = parser.get();
|
26
|
-
|
27
|
-
util.assert.strictEqual(
|
28
|
-
markdown,
|
29
|
-
"# mac's farm\n* [mac's farm](#macs-farm)\n\n"
|
30
|
-
);
|
31
|
-
});
|
32
|
-
it("should allow variables in toc", () => {
|
33
|
-
const output = new util.Parser(
|
34
|
-
"#mddef<name= Foobar>\n# mr. #mdvar<name>\n#mdmaketoc<>"
|
35
|
-
).get();
|
36
|
-
|
37
|
-
util.assert.strictEqual(
|
38
|
-
output,
|
39
|
-
"\n# mr. Foobar\n* [mr. Foobar](#mr-foobar)\n\n"
|
40
|
-
);
|
41
|
-
});
|
42
|
-
it("should not exceed max include depth", () => {
|
43
|
-
util.put("#mdinclude<sample2.md>", "sample1.md");
|
44
|
-
util.put("yo.md>", "sample2.md");
|
45
|
-
|
46
|
-
util.assert.throws(() => {
|
47
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
48
|
-
parser.opts.max_depth = 0;
|
49
|
-
parser.get();
|
50
|
-
}, Error);
|
51
|
-
});
|
52
|
-
it("should be able to reference toc elements, even if they are below toc-level", () => {
|
53
|
-
const parser = new util.Parser(`### Title\n#mdref<Title>`);
|
54
|
-
|
55
|
-
util.assert.strictEqual(parser.get(), "### Title\n[Title](#title)\n\n");
|
56
|
-
});
|
57
|
-
it("should include file with same name as folder when including a folder", () => {
|
58
|
-
util.put("#mdinclude<sample_fld>", "sample1.md");
|
59
|
-
util.putDir("sample_fld");
|
60
|
-
util.put("hello", util.path.join("sample_fld", "sample_fld.md"));
|
61
|
-
|
62
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
63
|
-
const output = parser.get();
|
64
|
-
|
65
|
-
util.assert.strictEqual(output, "hello\n\n");
|
66
|
-
});
|
67
|
-
});
|
package/test/clargs.test.js
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
const util = require("./tester.test.js");
|
2
|
-
|
3
|
-
describe("Command Line Arguments", () => {
|
4
|
-
it("--use-underscore should replace '-' with '_' in toc", () => {
|
5
|
-
const output = new util.Parser("# foo bar\n#mdmaketoc", {
|
6
|
-
use_underscore: true,
|
7
|
-
}).get();
|
8
|
-
|
9
|
-
util.assert.strictEqual(output, "# foo bar\n* [foo bar](#foo_bar)\n\n");
|
10
|
-
});
|
11
|
-
it("--toc-level should exclude subsection with lower level", () => {
|
12
|
-
const output = new util.Parser("# foo bar\n### baz\n#mdmaketoc", {
|
13
|
-
toc_level: 2,
|
14
|
-
}).get();
|
15
|
-
|
16
|
-
util.assert.strictEqual(
|
17
|
-
output,
|
18
|
-
"# foo bar\n### baz\n* [foo bar](#foo-bar)\n\n"
|
19
|
-
);
|
20
|
-
});
|
21
|
-
it("--allow-undef should not throw when variable is not defined", () => {
|
22
|
-
const output = new util.Parser("#mdvar<zum>", {
|
23
|
-
allow_undefined: true,
|
24
|
-
}).get();
|
25
|
-
|
26
|
-
util.assert.strictEqual(output, "<zum>\n\n");
|
27
|
-
});
|
28
|
-
describe("Conditional imports", () => {
|
29
|
-
it("should be able to conditionally import documents", () => {
|
30
|
-
util.put("hello\n#mdinclude<sample2.md, YES>", "sample1.md");
|
31
|
-
util.put("there", "sample2.md");
|
32
|
-
|
33
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
34
|
-
parser.opts.args.push("YES");
|
35
|
-
|
36
|
-
const output = parser.get();
|
37
|
-
|
38
|
-
util.assert.strictEqual(output, "hello\nthere\n\n");
|
39
|
-
});
|
40
|
-
it("shouldn't include a document when flag is unset", () => {
|
41
|
-
util.put("hello\n#mdinclude<sample2.md,YES>", "sample1.md");
|
42
|
-
util.put("there", "sample2.md");
|
43
|
-
|
44
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
45
|
-
|
46
|
-
const output = parser.get();
|
47
|
-
|
48
|
-
util.assert.strictEqual(output, "hello\n\n");
|
49
|
-
});
|
50
|
-
});
|
51
|
-
});
|
package/test/errors.test.js
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
const util = require("./tester.test.js");
|
2
|
-
|
3
|
-
describe("Error handling", () => {
|
4
|
-
it("should dissallow undefined templates", () => {
|
5
|
-
util.put("#mdtemplate<UNDEF>", "sample1.md");
|
6
|
-
|
7
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
8
|
-
|
9
|
-
let e;
|
10
|
-
util.assert.throws(() => {
|
11
|
-
try {
|
12
|
-
parser.get();
|
13
|
-
} catch (_e) {
|
14
|
-
e = _e;
|
15
|
-
throw _e;
|
16
|
-
}
|
17
|
-
}, Error);
|
18
|
-
|
19
|
-
let answer =
|
20
|
-
'Template "UNDEF" not found!' +
|
21
|
-
"\n...on line 1 in test/test-files/sample1.md".grey(15);
|
22
|
-
|
23
|
-
util.assert.strictEqual(e.message.replace(/(\\)+/g, "/"), answer);
|
24
|
-
});
|
25
|
-
it("should dissallow loading a folder without an entry file", () => {
|
26
|
-
util.put("#mdinclude<sample_fld>", "sample1.md");
|
27
|
-
util.putDir("sample_fld");
|
28
|
-
|
29
|
-
const parser = new util.Parser("test/test-files/sample1.md");
|
30
|
-
|
31
|
-
let e;
|
32
|
-
util.assert.throws(() => {
|
33
|
-
try {
|
34
|
-
parser.get();
|
35
|
-
} catch (_e) {
|
36
|
-
e = _e;
|
37
|
-
throw _e;
|
38
|
-
}
|
39
|
-
}, Error);
|
40
|
-
|
41
|
-
let answer =
|
42
|
-
'No entry file found in folder "sample_fld". Looking for "sample_fld.md"' +
|
43
|
-
"\n...on line 1 in test/test-files/sample1.md".grey(15);
|
44
|
-
|
45
|
-
util.assert.strictEqual(e.message.replace(/(\\)+/g, "/"), answer);
|
46
|
-
});
|
47
|
-
});
|
package/test/hooks.js
DELETED
package/test/hooks.test.js
DELETED
@@ -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
|
-
});
|
package/test/marked.test.js
DELETED
@@ -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
|
-
});
|
package/test/target.test.js
DELETED
@@ -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
|
-
});
|