MCPcopy Create free account
hub / github.com/Hashnode/starter-kit / marked

Function marked

packages/utils/renderer/marked.js:1284–1362  ·  view source on GitHub ↗

* Marked

(src, opt, callback)

Source from the content-addressed store, hash-verified

1282 */
1283
1284 function marked(src, opt, callback) {
1285 if (callback || typeof opt === 'function') {
1286 if (!callback) {
1287 callback = opt;
1288 opt = null;
1289 }
1290
1291 opt = merge({}, marked.defaults, opt || {});
1292
1293 var highlight = opt.highlight,
1294 tokens,
1295 pending,
1296 i = 0;
1297
1298 try {
1299 tokens = Lexer.lex(src, opt);
1300 } catch (e) {
1301 return callback(e);
1302 }
1303
1304 pending = tokens.length;
1305
1306 var done = function (err) {
1307 if (err) {
1308 opt.highlight = highlight;
1309 return callback(err);
1310 }
1311
1312 var out;
1313
1314 try {
1315 out = Parser.parse(tokens, opt);
1316 } catch (e) {
1317 err = e;
1318 }
1319
1320 opt.highlight = highlight;
1321
1322 return err ? callback(err) : callback(null, out);
1323 };
1324
1325 if (!highlight || highlight.length < 3) {
1326 return done();
1327 }
1328
1329 delete opt.highlight;
1330
1331 if (!pending) return done();
1332
1333 for (; i < tokens.length; i++) {
1334 (function (token) {
1335 if (token.type !== 'code') {
1336 return --pending || done();
1337 }
1338 return highlight(token.text, token.lang, function (err, code) {
1339 if (err) return done(err);
1340 if (code == null || code === token.text) {
1341 return --pending || done();

Callers 1

getHTMLFromMarkdownFunction · 0.85

Calls 3

mergeFunction · 0.85
doneFunction · 0.85
escapeFunction · 0.85

Tested by

no test coverage detected