MCPcopy Index your code
hub / github.com/socketstream/socketstream / marked

Function marked

docs/js/marked.js:1023–1101  ·  view source on GitHub ↗

* Marked

(src, opt, callback)

Source from the content-addressed store, hash-verified

1021 */
1022
1023function marked(src, opt, callback) {
1024 if (callback || typeof opt === 'function') {
1025 if (!callback) {
1026 callback = opt;
1027 opt = null;
1028 }
1029
1030 if (opt) opt = merge({}, marked.defaults, opt);
1031
1032 var highlight = opt.highlight
1033 , tokens
1034 , pending
1035 , i = 0;
1036
1037 try {
1038 tokens = Lexer.lex(src, opt)
1039 } catch (e) {
1040 return callback(e);
1041 }
1042
1043 pending = tokens.length;
1044
1045 var done = function(hi) {
1046 var out, err;
1047
1048 if (hi !== true) {
1049 delete opt.highlight;
1050 }
1051
1052 try {
1053 out = Parser.parse(tokens, opt);
1054 } catch (e) {
1055 err = e;
1056 }
1057
1058 opt.highlight = highlight;
1059
1060 return err
1061 ? callback(err)
1062 : callback(null, out);
1063 };
1064
1065 if (!highlight || highlight.length < 3) {
1066 return done(true);
1067 }
1068
1069 if (!pending) return done();
1070
1071 for (; i < tokens.length; i++) {
1072 (function(token) {
1073 if (token.type !== 'code') {
1074 return --pending || done();
1075 }
1076 return highlight(token.text, token.lang, function(err, code) {
1077 if (code == null || code === token.text) {
1078 return --pending || done();
1079 }
1080 token.text = code;

Callers 1

popoverElementFunction · 0.85

Calls 3

mergeFunction · 0.85
doneFunction · 0.85
escapeFunction · 0.70

Tested by

no test coverage detected