- #parseMarkdown(lexer2, parser3) {
- return (src, optOrCallback, callback) => {
- if (typeof optOrCallback === "function") {
- callback = optOrCallback;
- optOrCallback = null;
- }
- const origOpt = { ...optOrCallback };
- const opt = { ...this.defaults, ...origOpt };
- const throwError = this.#onError(!!opt.silent, !!opt.async, callback);
- if (typeof src === "undefined" || src === null) {
- return throwError(new Error("marked(): input parameter is undefined or null"));
- }
- if (typeof src !== "string") {
- return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
- }
- checkDeprecations(opt, callback);
- if (opt.hooks) {
- opt.hooks.options = opt;
- }
- if (callback) {
- const highlight = opt.highlight;
- let tokens;
- try {
- if (opt.hooks) {
- src = opt.hooks.preprocess(src);
- }
- tokens = lexer2(src, opt);
- } catch (e3) {
- return throwError(e3);
- }
- const done = (err) => {
- let out;
- if (!err) {
- try {
- if (opt.walkTokens) {
- this.walkTokens(tokens, opt.walkTokens);
- }
- out = parser3(tokens, opt);
- if (opt.hooks) {
- out = opt.hooks.postprocess(out);
- }
- } catch (e3) {
- err = e3;
- }
- }
- opt.highlight = highlight;
- return err ? throwError(err) : callback(null, out);
- };
- if (!highlight || highlight.length < 3) {
- return done();
- }
- delete opt.highlight;
- if (!tokens.length)
- return done();
- let pending = 0;
- this.walkTokens(tokens, (token) => {
- if (token.type === "code") {
- pending++;
- setTimeout(() => {
- highlight(token.text, token.lang, (err, code) => {
- if (err) {
- return done(err);
- }
- if (code != null && code !== token.text) {
- token.text = code;
- token.escaped = true;
- }
- pending--;
- if (pending === 0) {
- done();
- }
- });
- }, 0);
- }
- });
- if (pending === 0) {
- done();
- }
- return;
- }
- if (opt.async) {
- return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer2(src2, opt)).then((tokens) => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser3(tokens, opt)).then((html2) => opt.hooks ? opt.hooks.postprocess(html2) : html2).catch(throwError);
- }
+ };
+ _parseMarkdown = new WeakSet();
+ parseMarkdown_fn = function(lexer2, parser3) {
+ return (src, optOrCallback, callback) => {
+ if (typeof optOrCallback === "function") {
+ callback = optOrCallback;
+ optOrCallback = null;
+ }
+ const origOpt = __spreadValues({}, optOrCallback);
+ const opt = __spreadValues(__spreadValues({}, this.defaults), origOpt);
+ const throwError = __privateMethod(this, _onError, onError_fn).call(this, !!opt.silent, !!opt.async, callback);
+ if (typeof src === "undefined" || src === null) {
+ return throwError(new Error("marked(): input parameter is undefined or null"));
+ }
+ if (typeof src !== "string") {
+ return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
+ }
+ checkDeprecations(opt, callback);
+ if (opt.hooks) {
+ opt.hooks.options = opt;
+ }
+ if (callback) {
+ const highlight = opt.highlight;
+ let tokens;