MCPcopy Create free account
hub / github.com/CoderOpen/waimai / marked

Function marked

front/components/marked/lib/marked.js:1421–1512  ·  view source on GitHub ↗

* Marked

(src, opt, callback)

Source from the content-addressed store, hash-verified

1419 */
1420
1421function marked(src, opt, callback) {
1422 // throw error in case of non string input
1423 if (typeof src === 'undefined' || src === null) {
1424 throw new Error('marked(): input parameter is undefined or null');
1425 }
1426 if (typeof src !== 'string') {
1427 throw new Error('marked(): input parameter is of type '
1428 + Object.prototype.toString.call(src) + ', string expected');
1429 }
1430
1431 if (callback || typeof opt === 'function') {
1432 if (!callback) {
1433 callback = opt;
1434 opt = null;
1435 }
1436
1437 opt = merge({}, marked.defaults, opt || {});
1438
1439 var highlight = opt.highlight,
1440 tokens,
1441 pending,
1442 i = 0;
1443
1444 try {
1445 tokens = Lexer.lex(src, opt)
1446 } catch (e) {
1447 return callback(e);
1448 }
1449
1450 pending = tokens.length;
1451
1452 var done = function(err) {
1453 if (err) {
1454 opt.highlight = highlight;
1455 return callback(err);
1456 }
1457
1458 var out;
1459
1460 try {
1461 out = Parser.parse(tokens, opt);
1462 } catch (e) {
1463 err = e;
1464 }
1465
1466 opt.highlight = highlight;
1467
1468 return err
1469 ? callback(err)
1470 : callback(null, out);
1471 };
1472
1473 if (!highlight || highlight.length < 3) {
1474 return done();
1475 }
1476
1477 delete opt.highlight;
1478

Callers

nothing calls this directly

Calls 3

mergeFunction · 0.85
doneFunction · 0.85
escapeFunction · 0.85

Tested by

no test coverage detected