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,35 +1,30 @@
1
1
  # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
3
 
4
- name: Mocha
4
+ name: Jest
5
5
 
6
6
  on: [push, pull_request]
7
7
 
8
8
  jobs:
9
- build:
9
+ build:
10
+ runs-on: ubuntu-latest
10
11
 
11
- runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [20.x, 21.x, 22.x]
15
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
12
16
 
13
- strategy:
14
- matrix:
15
- node-version: [16.x, 18.x, 20.x]
16
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
17
-
18
- steps:
19
- - uses: actions/checkout@v2
20
- - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v1
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
- - name: yarn install
25
- uses: borales/actions-yarn@v3.0.0
26
- with:
27
- cmd: install # will run `yarn install` command
28
- - name: yarn build
29
- uses: borales/actions-yarn@v3.0.0
30
- with:
31
- cmd: build # will run `yarn build` command
32
- - name: yarn test
33
- uses: borales/actions-yarn@v3.0.0
34
- with:
35
- cmd: test # will run `yarn test` command
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ - name: yarn install
24
+ uses: borales/actions-yarn@v3.0.0
25
+ with:
26
+ cmd: install # will run `yarn install` command
27
+ - name: yarn test
28
+ uses: borales/actions-yarn@v3.0.0
29
+ with:
30
+ cmd: test # will run `yarn test` command
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["orta.vscode-jest", "github.vscode-github-actions"]
3
+ }
@@ -4,31 +4,13 @@
4
4
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
- {
8
- "name": "Compile main",
9
- "request": "launch",
10
- "runtimeArgs": [
11
- "run-script",
12
- "main"
13
- ],
14
- "runtimeExecutable": "npm",
15
- "skipFiles": [
16
- "<node_internals>/**"
17
- ],
18
- "type": "pwa-node"
19
- },
20
7
  {
21
8
  "name": "Run test",
22
9
  "request": "launch",
23
- "runtimeArgs": [
24
- "run-script",
25
- "test"
26
- ],
10
+ "runtimeArgs": ["run-script", "test"],
27
11
  "runtimeExecutable": "npm",
28
- "skipFiles": [
29
- "<node_internals>/**"
30
- ],
31
- "type": "pwa-node"
12
+ "skipFiles": ["<node_internals>/**"],
13
+ "type": "node"
32
14
  }
33
15
  ]
34
- }
16
+ }
@@ -1,5 +1,10 @@
1
1
  {
2
- "editor.formatOnPaste": true,
3
- "editor.defaultFormatter": "esbenp.prettier-vscode",
4
- "prettier.tabWidth": 4
2
+ "editor.formatOnPaste": true,
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
4
+ "prettier.tabWidth": 4,
5
+ "prettier.useEditorConfig": true,
6
+ "prettier.configPath": "",
7
+ "prettier.requireConfig": false,
8
+ "prettier.useTabs": true,
9
+ "jest.jestCommandLine": "npx jest -i"
5
10
  }
@@ -1,9 +1,9 @@
1
1
  {
2
- // Place your markdown-maker workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3
- // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4
- // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5
- // used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6
- // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
2
+ // Place your markdown-maker workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3
+ // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4
+ // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5
+ // used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6
+ // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
7
7
  // Placeholders with the same ids are connected.
8
8
  // Example:
9
9
  // "Print to console": {
@@ -15,7 +15,7 @@
15
15
  // ],
16
16
  // "description": "Log output to console"
17
17
  // }
18
- "MD Command" : {
18
+ "MD Command": {
19
19
  "scope": "javascript,typescript",
20
20
  "prefix": "cummy",
21
21
  "body": [
@@ -27,6 +27,4 @@
27
27
  ],
28
28
  "description": "Snippet for a new command"
29
29
  }
30
-
31
30
  }
32
-
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,66 +1,43 @@
1
1
  {
2
- "name": "markdown-maker",
3
- "version": "1.10.1",
4
- "description": "",
5
- "main": "src/cltool.ts",
6
- "bin": {
7
- "mdparse": "build/cltool.js"
8
- },
9
- "pkg": {
10
- "assets": [
11
- "node_modules/argparse/*",
12
- "node_modules/chokidar/*",
13
- "node_modules/colors/*",
14
- "node_modules/colors./*",
15
- "node_modules/marked/*",
16
- "build/cltool.js",
17
- "src/templates/*"
18
- ],
19
- "targets": [
20
- "node12-macos-x64",
21
- "node12-win-x64",
22
- "node12-linux-x64"
23
- ]
24
- },
25
- "scripts": {
26
- "test": "mocha --require test/hooks.js",
27
- "test:yarn": "mocha",
28
- "bundle": "tsc --project tsconfig.json",
29
- "main": "node build/cltool.js document/main.md -o dist/bundle.md --debug",
30
- "debug": "node src/cltool.js -db document/main.md -o dist/bundle.md",
31
- "build": "npm run bundle && pkg --output bin/mdparse .",
32
- "build:yarn": "yarn bundle && pkg --output bin/mdparse .",
33
- "clear": "rm -rf dist",
34
- "premac-deploy": "npm run build",
35
- "mac-deploy": "mv bin/mdparse-macos ~/Documents/commands/mdparse",
36
- "prewin-deploy": "npm run build",
37
- "win-deploy": "mv bin/mdparse-win.exe ../../commands/mdparse.exe",
38
- "pretest": "npm run bundle",
39
- "pretest:yarn": "yarn bundle",
40
- "prepare": "npm run build"
41
- },
42
- "keywords": [],
43
- "author": "blitzher",
44
- "license": "MIT",
45
- "dependencies": {
46
- "@types/chokidar": "^2.1.3",
47
- "@types/colors": "^1.2.1",
48
- "@types/node": "^15.6.1",
49
- "@types/ws": "^8.5.3",
50
- "argparse": "^2.0.1",
51
- "chokidar": "^3.5.1",
52
- "colors": "^1.4.0",
53
- "colors.ts": "^1.0.20",
54
- "marked": "^2.0.1",
55
- "node-html-parser": "^6.1.13",
56
- "require-runtime": "^2.0.0",
57
- "ws": "^8.8.1"
58
- },
59
- "devDependencies": {
60
- "cloc": "^2.7.0",
61
- "mocha": "^8.3.1",
62
- "pkg": "^4.4.9",
63
- "prettier": "^2.3.0",
64
- "typescript": "^4.3.2"
65
- }
2
+ "name": "markdown-maker",
3
+ "version": "1.10.3",
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": "jest",
11
+ "bundle": "tsc --project tsconfig.json",
12
+ "main": "node bundle/main.js",
13
+ "clean": "rm -rf bundle bin",
14
+ "pretest": "npm run bundle"
15
+ },
16
+ "keywords": [],
17
+ "author": "blitzher",
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "argparse": "^2.0.1",
21
+ "chokidar": "^3.5.1",
22
+ "colors.ts": "^1.0.20",
23
+ "marked": "^12.0.2",
24
+ "node-html-parser": "^6.1.13",
25
+ "require-runtime": "^2.0.0",
26
+ "ts-node": "^10.9.2",
27
+ "ws": "^8.8.1"
28
+ },
29
+ "devDependencies": {
30
+ "@types/argparse": "^2.0.16",
31
+ "@types/chokidar": "^2.1.3",
32
+ "@types/colors": "^1.2.1",
33
+ "@types/jest": "^29.5.12",
34
+ "@types/node": "^15.6.1",
35
+ "@types/ws": "^8.5.3",
36
+ "@types/xregexp": "^4.4.0",
37
+ "cloc": "^2.7.0",
38
+ "jest": "^29.7.0",
39
+ "prettier": "^2.3.0",
40
+ "ts-jest": "^29.1.2",
41
+ "typescript": "^4.3.2"
42
+ }
66
43
  }
package/src/cltool.ts CHANGED
@@ -1,168 +1,152 @@
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
4
  import Colors = require("colors.ts"); /* for adding colours to strings */
5
- import Parser from "./parse";
6
- import { WebSocketServer } from "ws";
5
+ import { TaggedElement, TargetType } from "./types";
6
+ import Parser from "./parser";
7
+
8
+ const version = process.env.npm_package_version || "0.0.0";
7
9
 
8
10
  Colors.enable();
9
- const { ArgumentParser } = require("argparse"); /* for parsing clargs */
10
- const { version } = require("../package.json"); /* package version number */
11
- const choki = require("chokidar");
11
+ import { ArgumentParser } from "argparse"; /* for parsing clargs */
12
+ import { HTMLElement } from "node-html-parser";
12
13
 
13
14
  export const argParser = new ArgumentParser({
14
- description: "Markdown bundler, with extra options. Extension file is loaded from ./extensions.js, if it exists",
15
- prog: "mdparse",
15
+ description:
16
+ "Markdown bundler, with extra options. Extension file is loaded from ./extensions.js, if it exists",
17
+ prog: "mdparse",
16
18
  });
17
19
 
18
- const configFileName = ".mdmconfig.json";
19
-
20
20
  //#region command line args
21
21
  argParser.add_argument("src", {
22
- help: "file to be parsed. If this is a directory, it looks for entry point in the directory, see --entry",
22
+ help: "file to be parsed. If this is a directory, it looks for entry point in the directory, see --entry",
23
+ });
24
+ argParser.add_argument("--version", {
25
+ action: "version",
26
+ version: `v${version}`,
23
27
  });
24
- argParser.add_argument("--version", { action: "version", version });
25
28
  argParser.add_argument("-v", "--verbose", {
26
- action: "store_true",
27
- help: "enable verbose output",
29
+ action: "store_true",
30
+ help: "enable verbose output",
28
31
  });
29
32
  argParser.add_argument("-D", "--debug", {
30
- action: "store_true",
31
- help: "enable debugging information",
33
+ action: "store_true",
34
+ help: "enable debugging information",
32
35
  });
33
36
  argParser.add_argument("-o", "--output", {
34
- help: "destination of bundle, by default is 'dist/bundle.md'",
35
- default: "dist/bundle.md",
37
+ help: "destination of bundle, by default is 'dist/bundle.md'",
38
+ default: "dist/bundle.md",
36
39
  });
37
40
  argParser.add_argument("-d", "--max-depth", {
38
- help: "maximum recursion depth, by default is 15",
39
- default: 15,
40
- type: "int",
41
+ help: "maximum recursion depth, by default is 15",
42
+ default: 15,
43
+ type: "int",
41
44
  });
42
45
  argParser.add_argument("-e", "--entry", {
43
- help: "assign entry point in directory, by default is 'main.md'",
44
- default: "main.md",
46
+ help: "assign entry point in directory, by default is 'main.md'",
47
+ default: "main.md",
45
48
  });
46
49
  argParser.add_argument("-w", "--watch", {
47
- action: "store_true",
48
- help: "recompile after a change in target target file or directory.",
50
+ action: "store_true",
51
+ help: "recompile after a change in target target file or directory.",
49
52
  });
50
53
  argParser.add_argument("-u", "--use-underscore", {
51
- action: "store_true",
52
- 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.",
54
+ action: "store_true",
55
+ 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.",
53
56
  });
54
57
  argParser.add_argument("-t", "--toc-level", {
55
- help: "the section level of the table of contents, by default is 3",
56
- default: 3,
57
- type: "int",
58
+ help: "the section level of the table of contents, by default is 3",
59
+ default: 3,
60
+ type: "int",
58
61
  });
59
62
  argParser.add_argument("-H", "--html", {
60
- action: "store_true",
61
- help: "compile HTML from the parsed markdown",
63
+ action: "store_true",
64
+ help: "compile HTML from the parsed markdown",
62
65
  });
63
66
  argParser.add_argument("--allow-undefined", "-A", {
64
- action: "store_true",
65
- 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",
67
+ action: "store_true",
68
+ 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",
66
69
  });
67
70
  //#endregion
68
71
 
69
- function main() {
70
- let clargs, fileargs;
71
- let server: WebSocketServer | undefined;
72
-
73
- /* Read config file or parse args from cmd-line */
74
- if (fs.existsSync(configFileName)) {
75
- let data: { [key: string]: string | boolean | number } = JSON.parse(fs.readFileSync(configFileName)).opts;
76
-
77
- let args: (string | number)[] = [];
78
- Object.entries(data).forEach(([key, value]) => {
79
- if (key != "src" && value !== false) {
80
- args.push("--" + key);
81
- }
82
- if (typeof value != "boolean") {
83
- args.push(value);
84
- }
85
- });
86
-
87
- /* We skip [0] and [1], as it is the binary and source file, even when compiled*/
88
- for (let i = 2; i < process.argv.length; i++) args.push(process.argv[i]);
89
-
90
- clargs = argParser.parse_args(args);
91
- } else {
92
- clargs = argParser.parse_args();
93
- }
94
-
95
- /* if src is init, create config file and exit */
96
- if (clargs.src == "init") {
97
- const template = fs.readFileSync(path.join(__dirname, "..", "src", "templates", "configTemplate.json"));
98
- fs.writeFileSync(configFileName, template);
99
- fs.writeFileSync("main.md", "# Main\n");
100
- return;
101
- }
102
-
103
- /* helper method for calling parser */
104
- const compile = (source, output, cb?) => {
105
- /* load data from file, if it exists,
106
- * otherwise, interpret as string */
107
-
108
- const parser = new Parser(source, clargs);
109
- parser.to(output, (file) => {
110
- console.log(`Compiled ${file}`.green);
111
- if (cb) cb();
112
- });
113
- return parser;
114
- };
115
-
116
- const internalCooldown = 1000;
117
- function watcher(event, path) {
118
- const now = Date.now();
119
-
120
- if (!this.time) this.time = now;
121
-
122
- if (now - this.time < internalCooldown) return;
123
-
124
- console.log(path);
125
-
126
- console.log(`Detected change in ${path}...`);
127
-
128
- try {
129
- compile(clargs.src, clargs.output, () => {
130
- /* after compile, send refresh command to clients */
131
- server.clients.forEach((client) => {
132
- if (client.OPEN) client.send("refresh");
133
- });
134
- });
135
- } catch (e) {
136
- console.log(e.message);
137
- }
138
-
139
- this.time = now;
140
- }
141
-
142
- /* in case source is a directory, look for entry in directory */
143
- if (fs.existsSync(clargs.src) && fs.lstatSync(clargs.src).isDirectory()) {
144
- clargs.src = path.join(clargs.src, clargs.entry);
145
- }
146
-
147
- if (clargs.debug) console.dir(clargs);
148
-
149
- /* compile once */
150
- if (!clargs.watch) compile(clargs.src, clargs.output);
151
- /* watch the folder and recompile on change */
152
- else {
153
- const srcDirName = path.dirname(clargs.src);
154
- console.log(`Watching ${srcDirName} for changes...`.yellow);
155
- server = new WebSocketServer({ port: 7788 });
156
-
157
- const _watcher = choki.watch(srcDirName).on("all", watcher);
158
- try {
159
- compile(clargs.src, clargs.output);
160
- } catch (e) {
161
- console.log(e.message);
162
- }
163
- }
164
-
165
- }
166
-
167
- /* main entrypoint */
168
- if (require.main === module) main();
72
+ export type CommandLineArgs = {
73
+ src: string;
74
+ output: string;
75
+ verbose: boolean;
76
+ debug: boolean;
77
+ max_depth: number;
78
+ entry: string;
79
+ watch: boolean;
80
+ use_underscore: boolean;
81
+ toc_level: number;
82
+ html: boolean;
83
+ allow_undefined: boolean;
84
+ };
85
+
86
+ export type IncompleteCommandLineArgs = {
87
+ src?: string;
88
+ output?: string;
89
+ verbose?: boolean;
90
+ debug?: boolean;
91
+ max_depth?: number;
92
+ entry?: string;
93
+ watch?: boolean;
94
+ use_underscore?: boolean;
95
+ toc_level?: number;
96
+ html?: boolean;
97
+ allow_undefined?: boolean;
98
+ };
99
+
100
+ export type ParserOptions = {
101
+ defs: {
102
+ [key: string]: string;
103
+ };
104
+ secs: {
105
+ level: number;
106
+ title: string;
107
+ }[];
108
+ args: string[];
109
+ depth: number;
110
+ verbose: boolean;
111
+ debug: boolean;
112
+ max_depth: number;
113
+ use_underscore: boolean;
114
+ toc_level: number;
115
+ allow_undefined: boolean;
116
+ html: boolean;
117
+ watch: boolean;
118
+ targetType: TargetType | undefined;
119
+ only_warn: boolean;
120
+ parent?: Parser;
121
+ hooks: {
122
+ [key: string]: (map: { [tag: string]: TaggedElement }) => void;
123
+ };
124
+ isFileCallback: (s: string) => false | string;
125
+ };
126
+
127
+ export type IncompleteParserOptions = {
128
+ defs?: {
129
+ [key: string]: string;
130
+ };
131
+ secs?: {
132
+ level: number;
133
+ title: string;
134
+ }[];
135
+ args?: string[];
136
+ depth?: number;
137
+ verbose?: boolean;
138
+ debug?: boolean;
139
+ max_depth?: number;
140
+ use_underscore?: boolean;
141
+ toc_level?: number;
142
+ allow_undefined?: boolean;
143
+ html?: boolean;
144
+ watch?: boolean;
145
+ targetType?: TargetType | undefined;
146
+ only_warn?: boolean;
147
+ parent?: Parser;
148
+ hooks?: {
149
+ [key: string]: (map: { [tag: string]: TaggedElement }) => void;
150
+ };
151
+ isFileCallback?: (s: string) => false | string;
152
+ };