markdown-maker 1.7.10 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
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
+ });
@@ -26,11 +26,9 @@ describe("Target specific functionality", () => {
26
26
  util.assert.strictEqual(md, '\n\n')
27
27
  });
28
28
  it("Should include #mdref to title elements in markdown", () => {
29
- const parser = new util.Parser("# Some Title!\n#mdref<Some_Title!>");
29
+ const output = new util.Parser("# Some Title!\n#mdref<Some Title!>").get();
30
30
 
31
- const md = parser.get(util.TargetType.MARKDOWN);
32
-
33
- util.assert.strictEqual(md, '# Some Title!\n[Some Title!](#some-title)\n\n')
31
+ util.assert.strictEqual(output, '# Some Title!\n[Some Title!](#some-title)\n\n')
34
32
  });
35
33
 
36
34
  })
@@ -1,28 +1,30 @@
1
- const fs = require('fs');
2
- const assert = require('assert');
3
- const Parser = require('../build/parse');
1
+ const fs = require("fs");
2
+ const assert = require("assert");
3
+ const Parser = require("../build/parse");
4
+
5
+
4
6
 
5
7
  /* make folder for temporary files, if it doesn't exist */
6
8
  if (
7
- !fs.existsSync('test/test-files') ||
8
- !fs.lstatSync('test/test-files').isDirectory()
9
+ !fs.existsSync("test/test-files") ||
10
+ !fs.lstatSync("test/test-files").isDirectory()
9
11
  ) {
10
- fs.mkdirSync('test/test-files');
12
+ fs.mkdirSync("test/test-files");
11
13
  }
12
14
 
13
15
  function put(text, file) {
14
- fs.writeFileSync('test/test-files/' + file, text);
16
+ fs.writeFileSync("test/test-files/" + file, text);
15
17
  }
16
18
 
17
19
  const TargetType = {
18
- HTML: 0,
19
- MARKDOWN: 1,
20
+ HTML: 0,
21
+ MARKDOWN: 1,
20
22
  };
21
23
 
22
24
  module.exports = {
23
- fs,
24
- assert,
25
- Parser,
26
- put,
27
- TargetType,
25
+ fs,
26
+ assert,
27
+ Parser,
28
+ put,
29
+ TargetType,
28
30
  };
package/tsconfig.json CHANGED
@@ -14,7 +14,7 @@
14
14
  // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
15
15
  "declaration": true /* Generates corresponding '.d.ts' file. */,
16
16
  // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
17
- // "sourceMap": true, /* Generates corresponding '.map' file. */
17
+ "sourceMap": true, /* Generates corresponding '.map' file. */
18
18
  // "outFile": "./", /* Concatenate and emit output to single file. */
19
19
  "outDir": "./build" /* Redirect output structure to the directory. */,
20
20
  // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
package/build/cltool.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const argParser: any;
package/build/cltool.js DELETED
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.argParser = void 0;
7
- var fs = require("fs"); /* for handling reading of files */
8
- var path = require("path"); /* for handling file paths */
9
- var Colors = require("colors.ts"); /* for adding colours to strings */
10
- var parse_1 = __importDefault(require("./parse"));
11
- Colors.enable();
12
- var ArgumentParser = require("argparse").ArgumentParser; /* for parsing clargs */
13
- var version = require("../package.json").version; /* package version number */
14
- var choki = require("chokidar");
15
- exports.argParser = new ArgumentParser({
16
- description: "Markdown bundler, with extra options",
17
- });
18
- //#region command line args
19
- exports.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",
21
- });
22
- exports.argParser.add_argument("--version", { action: "version", version: version });
23
- exports.argParser.add_argument("-v", "--verbose", {
24
- action: "store_true",
25
- help: "enable verbose output",
26
- });
27
- exports.argParser.add_argument("-db", "--debug", {
28
- action: "store_true",
29
- help: "enable debugging information",
30
- });
31
- exports.argParser.add_argument("-o", "--output", {
32
- help: "destination of bundle, by default is 'dist/bundle.md'",
33
- default: "dist/bundle.md",
34
- });
35
- exports.argParser.add_argument("-d", "--max-depth", {
36
- help: "maximum recursion depth, by default is 15",
37
- default: 15,
38
- type: "int",
39
- });
40
- exports.argParser.add_argument("-e", "--entry", {
41
- help: "assign entry point in directory, by default is 'main.md'",
42
- default: "main.md",
43
- });
44
- exports.argParser.add_argument("-w", "--watch", {
45
- action: "store_true",
46
- help: "recompile after a change in target target file or directory.",
47
- });
48
- exports.argParser.add_argument("-uu", "--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.",
51
- });
52
- exports.argParser.add_argument("--toc-level", {
53
- help: "the section level of the table of contents, by default is 3",
54
- default: 3,
55
- type: "int",
56
- });
57
- exports.argParser.add_argument("--html", {
58
- action: "store_true",
59
- help: "compile HTML from the parsed markdown",
60
- });
61
- exports.argParser.add_argument("--allow-undef", "-au", {
62
- action: "store_true",
63
- help: "allow undefined variables. Mostly useful for typing inline html tags, and other non-strictly markdown related uses",
64
- });
65
- //#endregion
66
- function main() {
67
- // var server: refreshServer | undefined;
68
- var clargs = exports.argParser.parse_args();
69
- /* helper method for calling parser */
70
- var compile = function (source, output, cb) {
71
- /* load data from file, if it exists,
72
- * otherwise, interpret as string */
73
- var parser = new parse_1.default(source, clargs);
74
- parser.to(output, function (file) {
75
- console.log(("Compiled " + file).green);
76
- if (cb)
77
- cb();
78
- });
79
- return parser;
80
- };
81
- var internalCooldown = 1000;
82
- function watcher(event, path) {
83
- var now = Date.now();
84
- if (!this.time)
85
- this.time = now;
86
- if (now - this.time < internalCooldown)
87
- return;
88
- console.log(path);
89
- console.log("Detected change in " + path + "...");
90
- try {
91
- compile(clargs.src, clargs.output, function () {
92
- // if (server.refresh) server.refresh();
93
- });
94
- }
95
- catch (e) {
96
- console.log(e.message);
97
- }
98
- this.time = now;
99
- }
100
- /* in case source is a directory, look for entry in directory */
101
- if (fs.existsSync(clargs.src) && fs.lstatSync(clargs.src).isDirectory()) {
102
- clargs.src = path.join(clargs.src, clargs.entry);
103
- }
104
- var srcDirName = path.dirname(clargs.src);
105
- if (clargs.debug)
106
- console.dir(clargs);
107
- if (!clargs.watch)
108
- compile(clargs.src, clargs.output);
109
- if (clargs.watch) {
110
- /* watch the folder of entry */
111
- // server = wsServer();
112
- console.log(("Watching " + srcDirName + " for changes...").yellow);
113
- var _watcher = choki.watch(srcDirName).on("all", watcher);
114
- try {
115
- compile(clargs.src, clargs.output);
116
- }
117
- catch (e) {
118
- console.log(e.message);
119
- }
120
- }
121
- }
122
- /* main entrypoint */
123
- if (require.main === module)
124
- main();
@@ -1 +0,0 @@
1
- export {};
package/build/commands.js DELETED
@@ -1,137 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- var path = __importStar(require("path"));
26
- var parse_1 = __importDefault(require("./parse"));
27
- var commands = {
28
- preparse: [],
29
- parse: [],
30
- postparse: [],
31
- };
32
- var CommandType = {
33
- PREPARSE: 0,
34
- PARSE: 1,
35
- POSTPARSE: 2,
36
- };
37
- var TargetType;
38
- (function (TargetType) {
39
- TargetType[TargetType["HTML"] = 0] = "HTML";
40
- TargetType[TargetType["MARKDOWN"] = 1] = "MARKDOWN";
41
- })(TargetType || (TargetType = {}));
42
- var Command = /** @class */ (function () {
43
- function Command(type, validator, acter) {
44
- this.type = type;
45
- this.validator = validator;
46
- this.acter = acter;
47
- /* add this function to appropriate file */
48
- switch (type) {
49
- case CommandType.PARSE:
50
- commands.parse.push(this);
51
- break;
52
- case CommandType.PREPARSE:
53
- commands.preparse.push(this);
54
- break;
55
- case CommandType.POSTPARSE:
56
- commands.postparse.push(this);
57
- break;
58
- }
59
- }
60
- Command.prototype.valid = function (token, parser) {
61
- return this.validator(token, parser);
62
- };
63
- Command.prototype.act = function (token, parser) {
64
- return this.acter(token, parser);
65
- };
66
- return Command;
67
- }());
68
- /* variable shorthand */
69
- new Command(CommandType.PREPARSE, function (t, p) { return t.match(/(?:\s|^)<\w+>/); }, function (t, p) { return "#mdvar" + t; });
70
- /* mddef */
71
- new Command(CommandType.PARSE, function (t, p) { return t.match(/^#mddef<(\w+)=(\w+)>/); }, function (t, p) {
72
- var m = t.match(/^#mddef<(\w+)=(\w+)>/);
73
- p.opts.defs[m[1]] = m[2];
74
- });
75
- /* mdvar */
76
- new Command(CommandType.PARSE, function (t, p) { return t.match(/^#mdvar<(\w+)>/) || t.match(/^<(\w+)>/); }, function (t, p) {
77
- var match = t.match(/#mdvar<(\w+)>/);
78
- var value = p.opts.defs[match[1]];
79
- if (!value && !p.opts.allow_undef)
80
- throw new Error("Undefined variable: " + match[1]);
81
- value = value || "<" + match[1] + ">";
82
- return t.replace(match[0], value.replace("_", " "));
83
- });
84
- /** mdinclude */
85
- new Command(CommandType.PARSE, function (t, p) { return t.match(/^#mdinclude<([\w.\/-]+)(?:[,\s]+([\w]+))?>/); }, function (t, p) {
86
- /* increase the current recursive depth */
87
- p.opts.depth++;
88
- if (p.opts.depth > p.opts.max_depth) {
89
- throw new Error("max depth exceeded!");
90
- }
91
- /* get the matching group */
92
- var match = t.match(/^#mdinclude<([\w.\/-]+)(?:[,\s]+([\w]+))?>/);
93
- var _ = match[0], name = match[1], condition = match[2];
94
- /* implement conditional imports */
95
- if (condition && !p.opts.args.includes(condition))
96
- return;
97
- var recursiveParser = new parse_1.default(path.join(p.wd, name), p.opts, {
98
- parent: p,
99
- });
100
- /* keep the options the same */
101
- recursiveParser.opts = p.opts;
102
- recursiveParser.parent = p;
103
- var fileType = path.extname(recursiveParser.file);
104
- var blob = fileType === ".md"
105
- ? recursiveParser.get(p.opts.targetType)
106
- : recursiveParser.raw;
107
- p.opts.depth--;
108
- return blob;
109
- });
110
- new Command(CommandType.PREPARSE, function (t, p) { return t.match(/#mdlabel<(\d+),([\w\W]+)>/); }, function (t, p) {
111
- if (p.opts.targetType !== TargetType.HTML)
112
- return;
113
- var match = t.match(/#mdlabel<([\d]+),([\w\W]+)>/);
114
- var level = Number.parseInt(match[1]);
115
- var title = match[2];
116
- var link = p.titleId(title);
117
- p.opts.secs.push({ level: level, title: title });
118
- return "<span id=\"" + link + "\"></span>";
119
- });
120
- new Command(CommandType.PARSE, function (t, p) { return t.match(/#mdref<([\w\W]+)>/); }, function (t, p) {
121
- var match = t.match(/#mdref<([\w\W]+)>/);
122
- for (var i = 0; i < p.opts.secs.length; i++) {
123
- var title_1 = p.opts.secs[i].title;
124
- if (title_1 === match[1])
125
- break;
126
- if (i === p.opts.secs.length - 1)
127
- throw new Error("Reference to [" + match[1] + "] could not be resolved!");
128
- }
129
- match[1] = match[1].replace("_", " ");
130
- var link = p.titleId(match[1]);
131
- if (p.opts.targetType === TargetType.HTML)
132
- return "<a href=\"#" + link + "\">" + match[1] + "</a>";
133
- else if (p.opts.targetType === TargetType.MARKDOWN)
134
- return "[" + match[1] + "](#" + link + ")";
135
- });
136
- new Command(CommandType.POSTPARSE, function (t, p) { return t.match(/#mdmaketoc/); }, function (t, p) { return p.gen_toc(); });
137
- module.exports = commands;
package/build/parse.d.ts DELETED
@@ -1,57 +0,0 @@
1
- declare enum TargetType {
2
- HTML = 0,
3
- MARKDOWN = 1
4
- }
5
- declare class Parser {
6
- file: string;
7
- parent?: Parser;
8
- line_num: number;
9
- wd: string;
10
- blobs: {
11
- [key: number]: string | undefined;
12
- };
13
- opts: {
14
- defs: {
15
- [key: string]: string;
16
- };
17
- secs: {
18
- level: number;
19
- title: string;
20
- }[];
21
- args: string[];
22
- depth: number;
23
- verbose: boolean;
24
- debug: boolean;
25
- max_depth: number;
26
- use_underscore: boolean;
27
- toc_level: number;
28
- allow_undef: boolean;
29
- html: boolean;
30
- targetType: TargetType | undefined;
31
- only_warn: boolean;
32
- parent?: Parser;
33
- isFileCallback: (s: string) => false | string;
34
- };
35
- raw: string;
36
- static TOKEN: string;
37
- constructor(filename: any, clargs: any, opts?: {
38
- parent?: Parser;
39
- isFileCallback?: (s: string) => false | string;
40
- });
41
- /**
42
- * parse wrapper for handling
43
- * preprocessing, parsing and postprocess
44
- **/
45
- parse(): any;
46
- mainparse(blob: any): string;
47
- parseToken(token: any): any;
48
- preprocess(blob: any): string;
49
- postprocess(blob: any): string;
50
- titleId(title: string): string;
51
- gen_toc(): string;
52
- remove_double_blank_lines(blob: any): any;
53
- to(bundleName: any, cb: any): void;
54
- html(): any;
55
- get(targetType: TargetType, callback?: any): any;
56
- }
57
- export default Parser;