markdown-maker 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.github/workflows/node.js.yml +21 -26
  2. package/.vscode/extensions.json +3 -0
  3. package/.vscode/settings.json +8 -3
  4. package/.vscode/snippets.code-snippets +6 -8
  5. package/bundle/cltool.d.ts +86 -0
  6. package/bundle/cltool.js +63 -0
  7. package/bundle/cltool.js.map +1 -0
  8. package/bundle/commands.d.ts +23 -0
  9. package/bundle/commands.js +303 -0
  10. package/bundle/commands.js.map +1 -0
  11. package/bundle/errors.d.ts +11 -0
  12. package/bundle/errors.js +51 -0
  13. package/bundle/errors.js.map +1 -0
  14. package/bundle/main.d.ts +6 -0
  15. package/bundle/main.js +152 -0
  16. package/bundle/main.js.map +1 -0
  17. package/bundle/parser.d.ts +35 -0
  18. package/bundle/parser.js +330 -0
  19. package/bundle/parser.js.map +1 -0
  20. package/bundle/templates/mathjax.d.ts +2 -0
  21. package/bundle/templates/mathjax.js +3 -0
  22. package/bundle/templates/mathjax.js.map +1 -0
  23. package/bundle/templates/presentation.d.ts +2 -0
  24. package/bundle/templates/presentation.js +3 -0
  25. package/bundle/templates/presentation.js.map +1 -0
  26. package/bundle/templates.d.ts +10 -0
  27. package/bundle/templates.js +23 -0
  28. package/bundle/templates.js.map +1 -0
  29. package/bundle/types.d.ts +28 -0
  30. package/bundle/types.js +15 -0
  31. package/bundle/types.js.map +1 -0
  32. package/bundle/version.d.ts +1 -0
  33. package/bundle/version.js +5 -0
  34. package/bundle/version.js.map +1 -0
  35. package/jest.config.js +7 -0
  36. package/package.json +42 -40
  37. package/src/cltool.ts +115 -72
  38. package/src/commands.ts +257 -241
  39. package/src/errors.ts +26 -0
  40. package/src/main.ts +114 -109
  41. package/src/parser.ts +378 -350
  42. package/src/templates.ts +5 -1
  43. package/src/types.ts +33 -0
  44. package/src/version.ts +1 -0
  45. package/tests/_test-util.ts +44 -0
  46. package/tests/advanced.spec.ts +102 -0
  47. package/tests/basic.spec.ts +68 -0
  48. package/tests/clargs.spec.ts +50 -0
  49. package/tests/errors.spec.ts +64 -0
  50. package/tests/html.spec.ts +23 -0
  51. package/tests/line.spec.ts +21 -0
  52. package/tests/marked.spec.ts +40 -0
  53. package/tests/target.spec.ts +41 -0
  54. package/tests/vars.spec.ts +45 -0
  55. package/tsconfig.json +66 -64
  56. package/prettierrc.yaml +0 -4
  57. package/test/advanced.test.js +0 -34
  58. package/test/basic.test.js +0 -67
  59. package/test/clargs.test.js +0 -51
  60. package/test/errors.test.js +0 -47
  61. package/test/hooks.js +0 -9
  62. package/test/hooks.test.js +0 -114
  63. package/test/html.test.js +0 -37
  64. package/test/line.test.js +0 -21
  65. package/test/marked.test.js +0 -43
  66. package/test/target.test.js +0 -43
  67. package/test/tester.test.js +0 -41
  68. package/test/vars.test.js +0 -49
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.new_template = void 0;
4
+ var errors_1 = require("./errors");
5
+ var templates = {};
6
+ /**
7
+ * Function to add a template to the templates object. Similar to definitions and variables, but reside as an extension.
8
+ * @param name The name of the template
9
+ * @param content The replacement string
10
+ */
11
+ function new_template(name, content) {
12
+ if (name in templates)
13
+ throw new errors_1.MDMNonParserError("Template \"".concat(name, "\" already exists"));
14
+ templates[name] = content;
15
+ }
16
+ exports.new_template = new_template;
17
+ /* initialize default templates */
18
+ var presentation_template = require("../src/templates/presentation.js");
19
+ var mathjax_template = require("../src/templates/mathjax.js");
20
+ new_template("presentation", presentation_template);
21
+ new_template("mathjax", mathjax_template);
22
+ exports.default = templates;
23
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":";;;AAAA,mCAAuD;AAEvD,IAAM,SAAS,GAA8B,EAAE,CAAC;AAEhD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,OAAe;IACzD,IAAI,IAAI,IAAI,SAAS;QACpB,MAAM,IAAI,0BAAiB,CAAC,qBAAa,IAAI,sBAAkB,CAAC,CAAC;IAClE,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;AAC3B,CAAC;AAJD,oCAIC;AAED,kCAAkC;AAClC,IAAM,qBAAqB,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAC1E,IAAM,gBAAgB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAChE,YAAY,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;AACpD,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAE1C,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { HTMLElement } from "node-html-parser";
2
+ import { Command } from "./commands";
3
+ export type CommandGroupType = {
4
+ preparse: Command[];
5
+ parse: Command[];
6
+ postparse: Command[];
7
+ };
8
+ type TaggedElementArguments = {
9
+ repeat?: number;
10
+ };
11
+ export type TaggedElement = {
12
+ "html-tag": string;
13
+ "var-tag": string;
14
+ _raw: string;
15
+ args: TaggedElementArguments;
16
+ node: HTMLElement;
17
+ };
18
+ export declare enum CommandType {
19
+ PREPARSE = 0,
20
+ PARSE = 1,
21
+ POSTPARSE = 2
22
+ }
23
+ export declare enum TargetType {
24
+ HTML = 0,
25
+ MARKDOWN = 1
26
+ }
27
+ export type Checksum = string;
28
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TargetType = exports.CommandType = void 0;
4
+ var CommandType;
5
+ (function (CommandType) {
6
+ CommandType[CommandType["PREPARSE"] = 0] = "PREPARSE";
7
+ CommandType[CommandType["PARSE"] = 1] = "PARSE";
8
+ CommandType[CommandType["POSTPARSE"] = 2] = "POSTPARSE";
9
+ })(CommandType = exports.CommandType || (exports.CommandType = {}));
10
+ var TargetType;
11
+ (function (TargetType) {
12
+ TargetType[TargetType["HTML"] = 0] = "HTML";
13
+ TargetType[TargetType["MARKDOWN"] = 1] = "MARKDOWN";
14
+ })(TargetType = exports.TargetType || (exports.TargetType = {}));
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAqBA,IAAY,WAIX;AAJD,WAAY,WAAW;IACtB,qDAAQ,CAAA;IACR,+CAAK,CAAA;IACL,uDAAS,CAAA;AACV,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAED,IAAY,UAGX;AAHD,WAAY,UAAU;IACrB,2CAAI,CAAA;IACJ,mDAAQ,CAAA;AACT,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB"}
@@ -0,0 +1 @@
1
+ export declare const LIB_VERSION = "1.10.3";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIB_VERSION = void 0;
4
+ exports.LIB_VERSION = "1.10.3";
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,QAAQ,CAAC"}
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ transform: { "^.+\\.ts?$": "ts-jest" },
3
+ testEnvironment: "node",
4
+ testRegex: "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",
5
+ moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
6
+ maxWorkers: 1,
7
+ };
package/package.json CHANGED
@@ -1,42 +1,44 @@
1
1
  {
2
- "name": "markdown-maker",
3
- "version": "1.10.2",
4
- "description": "A superset-compiler for markdown using marked",
5
- "main": "src/main.ts",
6
- "bin": {
7
- "mdparse": "bundle/main.js"
8
- },
9
- "scripts": {
10
- "test": "mocha --require test/hooks.js",
11
- "test:yarn": "mocha",
12
- "bundle": "tsc --project tsconfig.json",
13
- "main": "node bundle/main.js document/main.md -o dist/bundle.md --debug",
14
- "debug": "node src/main.js -db document/main.md -o dist/bundle.md",
15
- "clear": "rm -rf bundle bin",
16
- "pretest": "npm run bundle",
17
- "pretest:yarn": "yarn bundle"
18
- },
19
- "keywords": [],
20
- "author": "blitzher",
21
- "license": "MIT",
22
- "dependencies": {
23
- "argparse": "^2.0.1",
24
- "chokidar": "^3.5.1",
25
- "colors.ts": "^1.0.20",
26
- "marked": "^2.0.1",
27
- "node-html-parser": "^6.1.13",
28
- "require-runtime": "^2.0.0",
29
- "ws": "^8.8.1"
30
- },
31
- "devDependencies": {
32
- "@types/argparse": "^2.0.16",
33
- "@types/chokidar": "^2.1.3",
34
- "@types/colors": "^1.2.1",
35
- "@types/node": "^15.6.1",
36
- "@types/ws": "^8.5.3",
37
- "cloc": "^2.7.0",
38
- "mocha": "^8.3.1",
39
- "prettier": "^2.3.0",
40
- "typescript": "^4.3.2"
41
- }
2
+ "name": "markdown-maker",
3
+ "version": "1.10.4",
4
+ "description": "A superset-compiler for markdown using marked",
5
+ "main": "src/main.ts",
6
+ "bin": {
7
+ "mdparse": "bundle/main.js"
8
+ },
9
+ "scripts": {
10
+ "prebundle": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
11
+ "test": "jest",
12
+ "bundle": "tsc --project tsconfig.json",
13
+ "main": "node bundle/main.js",
14
+ "clean": "rm -rf bundle bin",
15
+ "pretest": "npm run bundle"
16
+ },
17
+ "keywords": [],
18
+ "author": "blitzher",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "argparse": "^2.0.1",
22
+ "chokidar": "^3.5.1",
23
+ "colors.ts": "^1.0.20",
24
+ "marked": "^12.0.2",
25
+ "node-html-parser": "^6.1.13",
26
+ "require-runtime": "^2.0.0",
27
+ "ts-node": "^10.9.2",
28
+ "ws": "^8.8.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/argparse": "^2.0.16",
32
+ "@types/chokidar": "^2.1.3",
33
+ "@types/colors": "^1.2.1",
34
+ "@types/jest": "^29.5.12",
35
+ "@types/node": "^15.6.1",
36
+ "@types/ws": "^8.5.3",
37
+ "@types/xregexp": "^4.4.0",
38
+ "cloc": "^2.7.0",
39
+ "jest": "^29.7.0",
40
+ "prettier": "^2.3.0",
41
+ "ts-jest": "^29.1.2",
42
+ "typescript": "^4.3.2"
43
+ }
42
44
  }
package/src/cltool.ts CHANGED
@@ -1,110 +1,153 @@
1
- const fs = require("fs"); /* for handling reading of files */
2
- const path = require("path"); /* for handling file paths */
1
+ import fs from "fs"; /* for handling reading of files */
2
+ import path from "path"; /* for handling file paths */
3
3
 
4
- import Colors = require("colors.ts"); /* for adding colours to strings */
5
- import { TargetType } from "./commands";
4
+ const Colors = require("colors.ts"); /* for adding colours to strings */
5
+ import { TaggedElement, TargetType } from "./types";
6
+ import { LIB_VERSION } from "./version";
6
7
  import Parser from "./parser";
7
8
 
9
+ const version = LIB_VERSION;
10
+
8
11
  Colors.enable();
9
12
  import { ArgumentParser } from "argparse"; /* for parsing clargs */
10
- const { version } = require("../package.json"); /* package version number */
13
+ import { HTMLElement } from "node-html-parser";
11
14
 
12
15
  export const argParser = new ArgumentParser({
13
- description:
14
- "Markdown bundler, with extra options. Extension file is loaded from ./extensions.js, if it exists",
15
- prog: "mdparse",
16
+ description:
17
+ "Markdown bundler, with extra options. Extension file is loaded from ./extensions.js, if it exists",
18
+ prog: "mdparse",
16
19
  });
17
20
 
18
21
  //#region command line args
19
22
  argParser.add_argument("src", {
20
- help: "file to be parsed. If this is a directory, it looks for entry point in the directory, see --entry",
23
+ help: "file to be parsed. If this is a directory, it looks for entry point in the directory, see --entry",
24
+ });
25
+ argParser.add_argument("--version", {
26
+ action: "version",
27
+ version: `v${version}`,
21
28
  });
22
- argParser.add_argument("--version", { action: "version", version });
23
29
  argParser.add_argument("-v", "--verbose", {
24
- action: "store_true",
25
- help: "enable verbose output",
30
+ action: "store_true",
31
+ help: "enable verbose output",
26
32
  });
27
33
  argParser.add_argument("-D", "--debug", {
28
- action: "store_true",
29
- help: "enable debugging information",
34
+ action: "store_true",
35
+ help: "enable debugging information",
30
36
  });
31
37
  argParser.add_argument("-o", "--output", {
32
- help: "destination of bundle, by default is 'dist/bundle.md'",
33
- default: "dist/bundle.md",
38
+ help: "destination of bundle, by default is 'dist/bundle.md'",
39
+ default: "dist/bundle.md",
34
40
  });
35
41
  argParser.add_argument("-d", "--max-depth", {
36
- help: "maximum recursion depth, by default is 15",
37
- default: 15,
38
- type: "int",
42
+ help: "maximum recursion depth, by default is 15",
43
+ default: 15,
44
+ type: "int",
39
45
  });
40
46
  argParser.add_argument("-e", "--entry", {
41
- help: "assign entry point in directory, by default is 'main.md'",
42
- default: "main.md",
47
+ help: "assign entry point in directory, by default is 'main.md'",
48
+ default: "main.md",
43
49
  });
44
50
  argParser.add_argument("-w", "--watch", {
45
- action: "store_true",
46
- help: "recompile after a change in target target file or directory.",
51
+ action: "store_true",
52
+ help: "recompile after a change in target target file or directory.",
47
53
  });
48
54
  argParser.add_argument("-u", "--use-underscore", {
49
- action: "store_true",
50
- help: "set the parser to use '_' as seperator in ids for Table of Content. If the links in the table does not work, this is likely to be the issue.",
55
+ action: "store_true",
56
+ help: "set the parser to use '_' as seperator in ids for Table of Content. If the links in the table does not work, this is likely to be the issue.",
51
57
  });
52
58
  argParser.add_argument("-t", "--toc-level", {
53
- help: "the section level of the table of contents, by default is 3",
54
- default: 3,
55
- type: "int",
59
+ help: "the section level of the table of contents, by default is 3",
60
+ default: 3,
61
+ type: "int",
56
62
  });
57
63
  argParser.add_argument("-H", "--html", {
58
- action: "store_true",
59
- help: "compile HTML from the parsed markdown",
64
+ action: "store_true",
65
+ help: "compile HTML from the parsed markdown",
60
66
  });
61
67
  argParser.add_argument("--allow-undefined", "-A", {
62
- action: "store_true",
63
- help: "allow the use of the \"<thing>\" syntax, without raising an error when 'thing' is not a variable. Mostly useful when writing inline html tags, and other non-strictly markdown related uses",
68
+ action: "store_true",
69
+ help: "allow the use of the \"<thing>\" syntax, without raising an error when 'thing' is not a variable. Mostly useful when writing inline html tags, and other non-strictly markdown related uses",
64
70
  });
65
71
  //#endregion
66
72
 
67
- export type CLArgs = {
68
- src: string;
69
- output: string;
70
- verbose: boolean;
71
- debug: boolean;
72
- max_depth: number;
73
- entry: string;
74
- watch: boolean;
75
- use_underscore: boolean;
76
- toc_level: number;
77
- html: boolean;
78
- allow_undefined: boolean;
73
+ export type CommandLineArgs = {
74
+ src: string;
75
+ output: string;
76
+ verbose: boolean;
77
+ debug: boolean;
78
+ max_depth: number;
79
+ entry: string;
80
+ watch: boolean;
81
+ use_underscore: boolean;
82
+ toc_level: number;
83
+ html: boolean;
84
+ allow_undefined: boolean;
85
+ };
86
+
87
+ export type IncompleteCommandLineArgs = {
88
+ src?: string;
89
+ output?: string;
90
+ verbose?: boolean;
91
+ debug?: boolean;
92
+ max_depth?: number;
93
+ entry?: string;
94
+ watch?: boolean;
95
+ use_underscore?: boolean;
96
+ toc_level?: number;
97
+ html?: boolean;
98
+ allow_undefined?: boolean;
79
99
  };
80
100
 
81
101
  export type ParserOptions = {
82
- defs: {
83
- [key: string]: string;
84
- };
85
- secs: {
86
- level: number;
87
- title: string;
88
- }[];
89
- args: string[];
90
- depth: number;
91
- verbose: boolean;
92
- debug: boolean;
93
- max_depth: number;
94
- use_underscore: boolean;
95
- toc_level: number;
96
- allow_undefined: boolean;
97
- html: boolean;
98
- watch: boolean;
99
- targetType: TargetType | undefined;
100
- only_warn: boolean;
101
- parent?: Parser;
102
- hooks: { [key: string]: () => string };
103
- adv_hooks: {
104
- [key: string]: (
105
- tree: HTMLElement,
106
- map: { [tag: string]: HTMLElement }
107
- ) => HTMLElement;
108
- };
109
- isFileCallback: (s: string) => false | string;
102
+ defs: {
103
+ [key: string]: string;
104
+ };
105
+ secs: {
106
+ level: number;
107
+ title: string;
108
+ }[];
109
+ args: string[];
110
+ depth: number;
111
+ verbose: boolean;
112
+ debug: boolean;
113
+ max_depth: number;
114
+ use_underscore: boolean;
115
+ toc_level: number;
116
+ allow_undefined: boolean;
117
+ html: boolean;
118
+ watch: boolean;
119
+ targetType: TargetType | undefined;
120
+ only_warn: boolean;
121
+ parent?: Parser;
122
+ hooks: {
123
+ [key: string]: (map: { [tag: string]: TaggedElement }) => void;
124
+ };
125
+ isFileCallback: (s: string) => false | string;
126
+ };
127
+
128
+ export type IncompleteParserOptions = {
129
+ defs?: {
130
+ [key: string]: string;
131
+ };
132
+ secs?: {
133
+ level: number;
134
+ title: string;
135
+ }[];
136
+ args?: string[];
137
+ depth?: number;
138
+ verbose?: boolean;
139
+ debug?: boolean;
140
+ max_depth?: number;
141
+ use_underscore?: boolean;
142
+ toc_level?: number;
143
+ allow_undefined?: boolean;
144
+ html?: boolean;
145
+ watch?: boolean;
146
+ targetType?: TargetType | undefined;
147
+ only_warn?: boolean;
148
+ parent?: Parser;
149
+ hooks?: {
150
+ [key: string]: (map: { [tag: string]: TaggedElement }) => void;
151
+ };
152
+ isFileCallback?: (s: string) => false | string;
110
153
  };