markdown-maker 1.10.3 → 1.10.4
Sign up to get free protection for your applications and to get access to all the features.
- package/bundle/cltool.d.ts +86 -0
- package/bundle/cltool.js +63 -0
- package/bundle/cltool.js.map +1 -0
- package/bundle/commands.d.ts +23 -0
- package/bundle/commands.js +303 -0
- package/bundle/commands.js.map +1 -0
- package/bundle/errors.d.ts +11 -0
- package/bundle/errors.js +51 -0
- package/bundle/errors.js.map +1 -0
- package/bundle/main.d.ts +6 -0
- package/bundle/main.js +152 -0
- package/bundle/main.js.map +1 -0
- package/bundle/parser.d.ts +35 -0
- package/bundle/parser.js +330 -0
- package/bundle/parser.js.map +1 -0
- package/bundle/templates/mathjax.d.ts +2 -0
- package/bundle/templates/mathjax.js +3 -0
- package/bundle/templates/mathjax.js.map +1 -0
- package/bundle/templates/presentation.d.ts +2 -0
- package/bundle/templates/presentation.js +3 -0
- package/bundle/templates/presentation.js.map +1 -0
- package/bundle/templates.d.ts +10 -0
- package/bundle/templates.js +23 -0
- package/bundle/templates.js.map +1 -0
- package/bundle/types.d.ts +28 -0
- package/bundle/types.js +15 -0
- package/bundle/types.js.map +1 -0
- package/bundle/version.d.ts +1 -0
- package/bundle/version.js +5 -0
- package/bundle/version.js.map +1 -0
- package/package.json +2 -1
- package/src/cltool.ts +3 -2
- package/src/commands.ts +22 -0
- package/src/main.ts +4 -0
- package/src/version.ts +1 -0
- package/tests/advanced.spec.ts +10 -0
package/bundle/main.js
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
|
+
if (k2 === undefined) k2 = k;
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
8
|
+
}
|
9
|
+
Object.defineProperty(o, k2, desc);
|
10
|
+
}) : (function(o, m, k, k2) {
|
11
|
+
if (k2 === undefined) k2 = k;
|
12
|
+
o[k2] = m[k];
|
13
|
+
}));
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
16
|
+
}) : function(o, v) {
|
17
|
+
o["default"] = v;
|
18
|
+
});
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
20
|
+
if (mod && mod.__esModule) return mod;
|
21
|
+
var result = {};
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
23
|
+
__setModuleDefault(result, mod);
|
24
|
+
return result;
|
25
|
+
};
|
26
|
+
var __read = (this && this.__read) || function (o, n) {
|
27
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
28
|
+
if (!m) return o;
|
29
|
+
var i = m.call(o), r, ar = [], e;
|
30
|
+
try {
|
31
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
32
|
+
}
|
33
|
+
catch (error) { e = { error: error }; }
|
34
|
+
finally {
|
35
|
+
try {
|
36
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
37
|
+
}
|
38
|
+
finally { if (e) throw e.error; }
|
39
|
+
}
|
40
|
+
return ar;
|
41
|
+
};
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
44
|
+
};
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
46
|
+
var path_1 = __importDefault(require("path"));
|
47
|
+
var ws_1 = require("ws");
|
48
|
+
var fs = __importStar(require("fs"));
|
49
|
+
var chokidar_1 = __importDefault(require("chokidar"));
|
50
|
+
var parser_1 = __importDefault(require("./parser"));
|
51
|
+
/* for adding colours to strings */
|
52
|
+
var colors_ts_1 = require("colors.ts");
|
53
|
+
(0, colors_ts_1.enable)();
|
54
|
+
var cltool_1 = require("./cltool");
|
55
|
+
var configFileName = ".mdmconfig.json";
|
56
|
+
function main() {
|
57
|
+
var clargs;
|
58
|
+
var server;
|
59
|
+
/* Read config file or parse args from cmd-line */
|
60
|
+
if (fs.existsSync(configFileName)) {
|
61
|
+
var data = JSON.parse(fs.readFileSync(configFileName).toString()).opts;
|
62
|
+
var args_1 = [];
|
63
|
+
Object.entries(data).forEach(function (_a) {
|
64
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
65
|
+
if (key != "src" && value !== false) {
|
66
|
+
args_1.push("--" + key);
|
67
|
+
}
|
68
|
+
if (typeof value != "boolean") {
|
69
|
+
args_1.push(value);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
/* We skip [0] and [1], as it is the binary and source file, even when compiled*/
|
73
|
+
for (var i = 2; i < process.argv.length; i++)
|
74
|
+
args_1.push(process.argv[i]);
|
75
|
+
clargs = cltool_1.argParser.parse_args(args_1.map(function (x) { return x.toString(); }));
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
clargs = cltool_1.argParser.parse_args();
|
79
|
+
}
|
80
|
+
/* if src is init, create config file and exit */
|
81
|
+
if (clargs.src == "init") {
|
82
|
+
var template = fs.readFileSync(path_1.default.join(__dirname, "..", "src", "templates", "configTemplate.json"));
|
83
|
+
fs.writeFileSync(configFileName, template);
|
84
|
+
fs.writeFileSync("main.md", "# Main\n");
|
85
|
+
console.log("Created config file ".concat(configFileName.green));
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
/* helper method for calling parser */
|
89
|
+
var compile = function (source, output, cb) {
|
90
|
+
/* load data from file, if it exists,
|
91
|
+
* otherwise, interpret as string */
|
92
|
+
var parser = new parser_1.default(source, clargs);
|
93
|
+
parser.to(output, function (file) {
|
94
|
+
console.log("Compiled ".concat(file).green);
|
95
|
+
if (cb)
|
96
|
+
cb();
|
97
|
+
});
|
98
|
+
return parser;
|
99
|
+
};
|
100
|
+
var internalCooldown = 1000;
|
101
|
+
function watcher(_, path) {
|
102
|
+
var now = Date.now();
|
103
|
+
if (!this.time)
|
104
|
+
this.time = now;
|
105
|
+
if (now - this.time < internalCooldown)
|
106
|
+
return;
|
107
|
+
console.log("Detected change in ".concat(path, "..."));
|
108
|
+
try {
|
109
|
+
compile(clargs.src, clargs.output, function () {
|
110
|
+
/* after compile, send refresh command to clients */
|
111
|
+
server.clients.forEach(function (client) {
|
112
|
+
if (client.OPEN)
|
113
|
+
client.send("refresh");
|
114
|
+
});
|
115
|
+
});
|
116
|
+
}
|
117
|
+
catch (e) {
|
118
|
+
console.log(e.message);
|
119
|
+
}
|
120
|
+
this.time = now;
|
121
|
+
}
|
122
|
+
/* in case source is a directory, look for entry in directory */
|
123
|
+
if (fs.existsSync(clargs.src) && fs.lstatSync(clargs.src).isDirectory()) {
|
124
|
+
clargs.src = path_1.default.join(clargs.src, clargs.entry);
|
125
|
+
}
|
126
|
+
if (clargs.debug)
|
127
|
+
console.dir(clargs);
|
128
|
+
/* compile once if not watching
|
129
|
+
otherwise watch the folder and recompile on change */
|
130
|
+
if (!clargs.watch)
|
131
|
+
compile(clargs.src, clargs.output);
|
132
|
+
else {
|
133
|
+
var srcDirName = path_1.default.dirname(clargs.src);
|
134
|
+
console.log("Watching ".concat(srcDirName, " for changes...").yellow);
|
135
|
+
server = new ws_1.WebSocketServer({ port: 7788 });
|
136
|
+
var _watcher = chokidar_1.default.watch(srcDirName).on("all", watcher);
|
137
|
+
try {
|
138
|
+
compile(clargs.src, clargs.output);
|
139
|
+
}
|
140
|
+
catch (e) {
|
141
|
+
console.log(e.message);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
exports.default = {
|
146
|
+
Parser: parser_1.default,
|
147
|
+
};
|
148
|
+
/* main entrypoint */
|
149
|
+
if (require.main === module) {
|
150
|
+
main();
|
151
|
+
}
|
152
|
+
//# sourceMappingURL=main.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts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AK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI;YACH,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACnC;QAAC,OAAO,CAAC,EAAE;YACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACvB;KACD;AACF,CAAC;AACD,kBAAe;IACd,MAAM,kBAAA;CACN,CAAC;AACF,qBAAqB;AACrB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;IAC5B,IAAI,EAAE,CAAC;CACP"}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { IncompleteCommandLineArgs, IncompleteParserOptions, ParserOptions } from "./cltool";
|
2
|
+
import { TaggedElement, TargetType } from "./types";
|
3
|
+
declare class Parser {
|
4
|
+
file: string;
|
5
|
+
parent?: Parser;
|
6
|
+
line_num: number;
|
7
|
+
wd: string;
|
8
|
+
wd_full: string;
|
9
|
+
blobs: {
|
10
|
+
[key: number]: string | undefined;
|
11
|
+
};
|
12
|
+
opts: ParserOptions;
|
13
|
+
raw: string;
|
14
|
+
static TOKEN: string;
|
15
|
+
constructor(filename: string, clargs?: IncompleteCommandLineArgs, opts?: IncompleteParserOptions);
|
16
|
+
private parse;
|
17
|
+
private mainparse;
|
18
|
+
private preprocess;
|
19
|
+
private postprocess;
|
20
|
+
private parse_commands;
|
21
|
+
private parse_all_commands;
|
22
|
+
titleId(title: string): string;
|
23
|
+
get_toc(): string;
|
24
|
+
add_hook(name: string, hook: (map: {
|
25
|
+
[key: string]: TaggedElement;
|
26
|
+
}) => void): void;
|
27
|
+
private line_num_from_index;
|
28
|
+
private remove_double_blank_lines;
|
29
|
+
to(bundleName: string, callback: (fileName: string) => void): void;
|
30
|
+
html(): string;
|
31
|
+
createChild(file: string): Parser;
|
32
|
+
get(targetType?: TargetType, callback?: (blob: string) => void): string;
|
33
|
+
}
|
34
|
+
export declare function splice(str: string, startIndex: number, width: number, newSubStr: string): string;
|
35
|
+
export default Parser;
|
package/bundle/parser.js
ADDED
@@ -0,0 +1,330 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
exports.splice = void 0;
|
18
|
+
var fs_1 = __importDefault(require("fs")); /* for handling reading of files */
|
19
|
+
var path_1 = __importDefault(require("path")); /* for handling file paths */
|
20
|
+
var marked_1 = __importDefault(require("marked"));
|
21
|
+
var commands_1 = require("./commands");
|
22
|
+
var cltool_1 = require("./cltool");
|
23
|
+
var errors_1 = require("./errors");
|
24
|
+
var types_1 = require("./types");
|
25
|
+
/* parse some md
|
26
|
+
* recursively with extra options */
|
27
|
+
var Parser = /** @class */ (function () {
|
28
|
+
function Parser(filename, clargs, opts) {
|
29
|
+
/* this.working_directory */
|
30
|
+
this.file = filename;
|
31
|
+
this.line_num = 0;
|
32
|
+
this.wd = path_1.default.dirname(filename);
|
33
|
+
this.wd_full = path_1.default.resolve(this.wd);
|
34
|
+
/* finished blob */
|
35
|
+
this.blobs = {};
|
36
|
+
if (!clargs) {
|
37
|
+
clargs = cltool_1.argParser.parse_args([filename]);
|
38
|
+
}
|
39
|
+
/* get default options, and overwrite with the ones present
|
40
|
+
in the arguments */
|
41
|
+
this.opts = defaultParserOptions();
|
42
|
+
Object.assign(this.opts, clargs);
|
43
|
+
Object.assign(this.opts, opts);
|
44
|
+
this.raw = this.opts.isFileCallback(filename) || filename;
|
45
|
+
}
|
46
|
+
Parser.prototype.parse = function () {
|
47
|
+
(0, commands_1.load_extensions)(this);
|
48
|
+
if (this.opts.verbose || this.opts.debug) {
|
49
|
+
console.log("parsing ".concat(this.file, ": depth=").concat(this.opts.depth).magenta);
|
50
|
+
}
|
51
|
+
if (this.opts.debug) {
|
52
|
+
console.log("Parsing options:");
|
53
|
+
console.log(this.opts);
|
54
|
+
}
|
55
|
+
/* reset sections for beginning parse */
|
56
|
+
if (this.opts.depth === 0)
|
57
|
+
this.opts.secs = [];
|
58
|
+
var __blob = this.raw;
|
59
|
+
/* apply preproccessing to raw file */
|
60
|
+
__blob = this.preprocess(__blob);
|
61
|
+
/* main parser instance call */
|
62
|
+
__blob = this.mainparse(__blob);
|
63
|
+
/**
|
64
|
+
* apply postprocessing after */
|
65
|
+
__blob = this.postprocess(__blob);
|
66
|
+
return __blob;
|
67
|
+
};
|
68
|
+
Parser.prototype.mainparse = function (blob) {
|
69
|
+
var _this = this;
|
70
|
+
if (this.opts.verbose || this.opts.debug) {
|
71
|
+
console.debug("beginning mainparse of '".concat(this.file, "'").blue);
|
72
|
+
}
|
73
|
+
/* main parser instance loop */
|
74
|
+
blob.split("\n").forEach(function (line, lnum) {
|
75
|
+
_this.line_num = lnum;
|
76
|
+
/* if line looks like a title */
|
77
|
+
var titleMatch = line.trim().match(/^(#+) (.+)$/);
|
78
|
+
if (titleMatch) {
|
79
|
+
if (_this.opts.verbose || _this.opts.debug)
|
80
|
+
console.log("found toc element: " + line);
|
81
|
+
/* implement toc level */
|
82
|
+
var level = titleMatch[1].length;
|
83
|
+
var title = titleMatch[2];
|
84
|
+
_this.opts.secs.push({ level: level, title: title });
|
85
|
+
if (_this.opts.debug) {
|
86
|
+
console.log("updated sections:", { level: level, title: title });
|
87
|
+
}
|
88
|
+
}
|
89
|
+
});
|
90
|
+
return this.parse_commands(blob, commands_1.commands.parse);
|
91
|
+
};
|
92
|
+
Parser.prototype.preprocess = function (blob) {
|
93
|
+
if (this.opts.verbose || this.opts.debug) {
|
94
|
+
console.debug("beginning preprocess of '".concat(this.file, "'").blue);
|
95
|
+
}
|
96
|
+
return this.parse_commands(blob, commands_1.commands.preparse);
|
97
|
+
};
|
98
|
+
Parser.prototype.postprocess = function (blob) {
|
99
|
+
if (this.opts.verbose || this.opts.debug) {
|
100
|
+
console.debug("beginning postprocess of '".concat(this.file, "'").blue);
|
101
|
+
}
|
102
|
+
blob = this.parse_commands(blob, commands_1.commands.postparse);
|
103
|
+
/* remove double empty lines */
|
104
|
+
blob = this.remove_double_blank_lines(blob);
|
105
|
+
blob = blob.trimEnd() + "\n\n";
|
106
|
+
return blob;
|
107
|
+
};
|
108
|
+
Parser.prototype.parse_commands = function (blob, commands) {
|
109
|
+
var _this = this;
|
110
|
+
commands.forEach(function (command) {
|
111
|
+
/* Add global flag to RegExp */
|
112
|
+
var re = new RegExp(command.validator.source, (command.validator.flags || "") + "g");
|
113
|
+
var replacer = function (args) {
|
114
|
+
try {
|
115
|
+
return command.act(args, _this) || "";
|
116
|
+
}
|
117
|
+
catch (error) {
|
118
|
+
switch (true) {
|
119
|
+
case error instanceof errors_1.MDMError:
|
120
|
+
throw error;
|
121
|
+
case error instanceof errors_1.MDMWarning:
|
122
|
+
console.warn(error.message);
|
123
|
+
return "**Warning: ".concat(error.message, "**");
|
124
|
+
default:
|
125
|
+
console.error(error);
|
126
|
+
throw error;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
};
|
130
|
+
/* */
|
131
|
+
var match;
|
132
|
+
while ((match = re.exec(blob)) !== null) {
|
133
|
+
blob =
|
134
|
+
blob.slice(0, match.index) +
|
135
|
+
replacer(match) +
|
136
|
+
blob.slice(match.index + match[0].length);
|
137
|
+
}
|
138
|
+
});
|
139
|
+
return blob;
|
140
|
+
};
|
141
|
+
/* Parse all commands sequentially on a sub-blob */
|
142
|
+
Parser.prototype.parse_all_commands = function (blob, commands) {
|
143
|
+
blob = this.parse_commands(blob, commands.preparse);
|
144
|
+
blob = this.parse_commands(blob, commands.parse);
|
145
|
+
blob = this.parse_commands(blob, commands.postparse);
|
146
|
+
return blob;
|
147
|
+
};
|
148
|
+
Parser.prototype.titleId = function (title) {
|
149
|
+
var sep = this.opts.use_underscore ? "_" : "-";
|
150
|
+
title = title
|
151
|
+
.toLowerCase()
|
152
|
+
.replace(/[^\w\s]+/g, "")
|
153
|
+
.replace(/[\s_]+/g, sep);
|
154
|
+
return title;
|
155
|
+
};
|
156
|
+
Parser.prototype.get_toc = function () {
|
157
|
+
var _this = this;
|
158
|
+
var __blob = [];
|
159
|
+
var tabSize = 2;
|
160
|
+
var beg = "* ";
|
161
|
+
var hor = " ".repeat(tabSize);
|
162
|
+
this.opts.secs.forEach(function (sec) {
|
163
|
+
if (sec.level > _this.opts.toc_level)
|
164
|
+
return;
|
165
|
+
var title = sec.title.replace(/_/g, " ");
|
166
|
+
title = _this.parse_all_commands(title, commands_1.commands);
|
167
|
+
var link = _this.titleId(title);
|
168
|
+
var __line = hor.repeat(Math.max(sec.level - 1, 0)) +
|
169
|
+
beg +
|
170
|
+
"[".concat(title, "](#").concat(link, ")");
|
171
|
+
__blob.push(__line);
|
172
|
+
});
|
173
|
+
return __blob.join("\n");
|
174
|
+
};
|
175
|
+
Parser.prototype.add_hook = function (name, hook) {
|
176
|
+
if (this.opts.hooks[name] != undefined)
|
177
|
+
throw new errors_1.MDMNonParserError("Hook \"".concat(name, "\" already exists!"));
|
178
|
+
this.opts.hooks[name] = hook;
|
179
|
+
};
|
180
|
+
Parser.prototype.line_num_from_index = function (index) {
|
181
|
+
return this.raw.substring(0, index).split("\n").length;
|
182
|
+
};
|
183
|
+
Parser.prototype.remove_double_blank_lines = function (blob) {
|
184
|
+
/* replace all triple newlines, and EOF by double newline */
|
185
|
+
blob = blob.replace(/(\r\n|\n){3,}/g, "\n\n");
|
186
|
+
return blob;
|
187
|
+
};
|
188
|
+
/* output the parsed document to bundle */
|
189
|
+
Parser.prototype.to = function (bundleName, callback) {
|
190
|
+
var dir = path_1.default.dirname(bundleName);
|
191
|
+
if (callback === undefined)
|
192
|
+
callback = function () { };
|
193
|
+
if (!fs_1.default.existsSync(dir)) {
|
194
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
195
|
+
}
|
196
|
+
if (!this.opts.html) {
|
197
|
+
this.get(types_1.TargetType.MARKDOWN, function (blob) {
|
198
|
+
fs_1.default.writeFile(bundleName, blob, function () { return callback(bundleName); });
|
199
|
+
});
|
200
|
+
}
|
201
|
+
else {
|
202
|
+
var htmlFileName_1 = bundleName.replace(".md", ".html");
|
203
|
+
fs_1.default.writeFile(htmlFileName_1, this.html(), function () {
|
204
|
+
return callback(htmlFileName_1);
|
205
|
+
});
|
206
|
+
}
|
207
|
+
};
|
208
|
+
Parser.prototype.html = function () {
|
209
|
+
var htmlFormatted = marked_1.default
|
210
|
+
.parse(this.get(types_1.TargetType.HTML))
|
211
|
+
.toString();
|
212
|
+
if (this.opts.watch) {
|
213
|
+
return ("<script>" +
|
214
|
+
"w=new WebSocket(\"ws:localhost:7788\");" +
|
215
|
+
"w.addEventListener(\"message\",(e)=>" +
|
216
|
+
" {if(e.data==\"refresh\")location.reload();}" +
|
217
|
+
");" +
|
218
|
+
"</script>\n" +
|
219
|
+
htmlFormatted);
|
220
|
+
}
|
221
|
+
return htmlFormatted;
|
222
|
+
};
|
223
|
+
Parser.prototype.createChild = function (file) {
|
224
|
+
return new Parser(file, undefined, __assign({ parent: this, depth: this.opts.depth + 1 }, this.opts));
|
225
|
+
};
|
226
|
+
Parser.prototype.get = function (targetType, callback) {
|
227
|
+
/* If target type is undefined, markdown is the default */
|
228
|
+
if (targetType === undefined)
|
229
|
+
targetType = types_1.TargetType.MARKDOWN;
|
230
|
+
if (this.blobs[targetType]) {
|
231
|
+
if (callback) {
|
232
|
+
callback(this.blobs[targetType]);
|
233
|
+
}
|
234
|
+
return this.blobs[targetType];
|
235
|
+
}
|
236
|
+
else {
|
237
|
+
try {
|
238
|
+
this.opts.targetType = targetType;
|
239
|
+
var blob = this.parse();
|
240
|
+
this.opts.targetType = undefined;
|
241
|
+
if (callback)
|
242
|
+
callback(blob);
|
243
|
+
return blob;
|
244
|
+
}
|
245
|
+
catch (error) {
|
246
|
+
/* Compile a traceback of error */
|
247
|
+
var traceback = "";
|
248
|
+
var p = this;
|
249
|
+
do {
|
250
|
+
if (error instanceof errors_1.MDMError)
|
251
|
+
traceback += "\n...on line ".concat(p.line_num_from_index(error.match.index), " in ").concat(p.file).grey(15);
|
252
|
+
else
|
253
|
+
traceback +=
|
254
|
+
"\n...on line ".concat(p.line_num, " in ").concat(p.file).grey(15);
|
255
|
+
if (p.parent)
|
256
|
+
p = p.parent;
|
257
|
+
} while (p.parent);
|
258
|
+
error.message += traceback;
|
259
|
+
/* only interested in node stacktrace when debugging */
|
260
|
+
if (!this.opts.debug)
|
261
|
+
error.stack = "";
|
262
|
+
if (this.opts.only_warn)
|
263
|
+
console.error(error);
|
264
|
+
else
|
265
|
+
throw error;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
};
|
269
|
+
Parser.TOKEN = "#md";
|
270
|
+
return Parser;
|
271
|
+
}());
|
272
|
+
function defaultParserOptions() {
|
273
|
+
return {
|
274
|
+
defs: {},
|
275
|
+
secs: [],
|
276
|
+
args: [],
|
277
|
+
depth: 0,
|
278
|
+
verbose: false,
|
279
|
+
debug: false,
|
280
|
+
max_depth: 5,
|
281
|
+
use_underscore: false,
|
282
|
+
toc_level: 3,
|
283
|
+
allow_undefined: false,
|
284
|
+
html: false,
|
285
|
+
watch: false,
|
286
|
+
targetType: undefined,
|
287
|
+
only_warn: false,
|
288
|
+
parent: undefined,
|
289
|
+
hooks: {},
|
290
|
+
isFileCallback: function (f) {
|
291
|
+
if (!fs_1.default.existsSync(f))
|
292
|
+
return false;
|
293
|
+
return fs_1.default.readFileSync(f, "utf-8") + "\n";
|
294
|
+
},
|
295
|
+
};
|
296
|
+
}
|
297
|
+
function splice(str, startIndex, width, newSubStr) {
|
298
|
+
var start = str.slice(0, startIndex);
|
299
|
+
var end = str.slice(startIndex + width);
|
300
|
+
return start + newSubStr + end;
|
301
|
+
}
|
302
|
+
exports.splice = splice;
|
303
|
+
/* add extention to marked for classed blockquotes*/
|
304
|
+
marked_1.default.use({
|
305
|
+
renderer: {
|
306
|
+
blockquote: function (quote) {
|
307
|
+
/* find the ending, and if not, return the default */
|
308
|
+
var ending = quote.match(/\{(.+)\}\s*<\/p>/);
|
309
|
+
if (!ending)
|
310
|
+
return "<blockquote>".concat(quote, "</blockquote>");
|
311
|
+
var args = ending[1].split(" ");
|
312
|
+
var classes = args.filter(function (arg) { return arg.startsWith("."); });
|
313
|
+
var id = args.filter(function (arg) { return arg.startsWith("#"); });
|
314
|
+
var classNames = classes.map(function (c) { return c.slice(1); });
|
315
|
+
var classText = classes.length > 0 ? "class=\"".concat(classNames.join(" "), "\"") : "";
|
316
|
+
var idText = id.length > 0 ? "id=\"".concat(id[0].slice(1), "\"") : "";
|
317
|
+
/* remove the ending from the quote */
|
318
|
+
quote = quote.replace(/\{(.+)\}\s*<\/p>/, "</p>");
|
319
|
+
return "<blockquote ".concat(classText, " ").concat(idText, ">\n").concat(quote.trim(), "</blockquote>");
|
320
|
+
},
|
321
|
+
heading: function (text, level) {
|
322
|
+
/* add an id to each heading */
|
323
|
+
return "<h".concat(level, " id=\"").concat(text
|
324
|
+
.replace(/ /g, "-")
|
325
|
+
.toLowerCase(), "\">").concat(text, "</h").concat(level, ">");
|
326
|
+
},
|
327
|
+
},
|
328
|
+
});
|
329
|
+
exports.default = Parser;
|
330
|
+
//# sourceMappingURL=parser.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAoB,CAAC,mCAAmC;AACxD,8CAAwB,CAAC,6BAA6B;AAEtD,kDAA4B;AAE5B,uCAAgE;A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,CAAC;QACxC,CAAC;KACD;CACD,CAAC,CAAC;AAEH,kBAAe,MAAM,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mathjax.js","sourceRoot":"","sources":["../../src/templates/mathjax.js"],"names":[],"mappings":"AAAA,IAAM,QAAQ,GAAG,gMAA0L,CAAC;AAE5M,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
export = template;
|
2
|
+
declare 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>";
|
@@ -0,0 +1,3 @@
|
|
1
|
+
var 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>";
|
2
|
+
module.exports = template;
|
3
|
+
//# sourceMappingURL=presentation.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"presentation.js","sourceRoot":"","sources":["../../src/templates/presentation.js"],"names":[],"mappings":"AAAA,IAAM,QAAQ,GAAG,qiCAAyhC,CAAC;AAE3iC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
declare const templates: {
|
2
|
+
[key: string]: string;
|
3
|
+
};
|
4
|
+
/**
|
5
|
+
* Function to add a template to the templates object. Similar to definitions and variables, but reside as an extension.
|
6
|
+
* @param name The name of the template
|
7
|
+
* @param content The replacement string
|
8
|
+
*/
|
9
|
+
export declare function new_template(name: string, content: string): void;
|
10
|
+
export default templates;
|
@@ -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 {};
|
package/bundle/types.js
ADDED
@@ -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
|