How to use marked

Comprehensive marked code examples:

How to use marked.inlineLexer:

How to use marked.js:

53
54
55
56
57
58
59
60
61
62
  this.toc.push({ id, level, raw });
  return super.heading(text, level, raw, slugger);
}

// Use the **function name** as the link ID, otherwise fall back to the ID
// generated by marked.js
const match = text.match(/<strong>(.*)<\/strong>/);
if (match) id = match[1].replace(/[^a-zA-Z]/g, '-');

this.toc.push({ id, level, raw: match ? match[1] : raw });

How to use marked.options:

2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
marked.Lexer = Lexer;
marked.lexer = Lexer.lex;
marked.Tokenizer = Tokenizer;
marked.Slugger = Slugger;
marked.parse = marked;
var options = marked.options;
var setOptions = marked.setOptions;
var use = marked.use;
var walkTokens = marked.walkTokens;
var parseInline = marked.parseInline;

How to use marked.getDefaults:

3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
    tables: true,
    xhtml: false
  };
};


marked.defaults = marked.getDefaults();


/**
 * Expose
 */

How to use marked.TextRenderer:

How to use marked.Parser:

How to use marked.parseInline:

2913
2914
2915
2916
2917
2918
2919
2920
2921
marked.parse = marked;
var options = marked.options;
var setOptions = marked.setOptions;
var use = marked.use;
var walkTokens = marked.walkTokens;
var parseInline = marked.parseInline;
var parse = marked;
var parser = Parser.parse;
var lexer = Lexer.lex;

How to use marked.Lexer:

3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
// rendering, or else they will act as paragraphs and
// not use the inline styling.
// I wonder if WalkTokens would be easier...
//  https://marked.js.org/using_pro#walk-tokens

const lexer = new marked.Lexer();
const tokens = lexer.lex(md);

let precedingParagraph = null;
let precedingInlinedCodeblock = null; // This is a code block with /inline

How to use marked.use:

1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
  tokenizer,
  walkTokens
};


function enhanceMarkedAndOpts() {
  marked.use(markedOpts);
}


//
// End of marked.js extensions

How to use marked.Slugger:

16
17
18
19
20
21
22
23
24
25

/*
 * Note that it is important to create a dedicated instance
 * as it counts occurrence of each title.
 */
const slugger = new marked.Slugger();

return headingTokens
    .map((headingToken) => {
        // text token for the content

How to use marked.parser:

375
376
377
378
379
380
381
382
383
384
    .trim().replace(/\s+/g, '_');
}

if (section.desc && Array.isArray(section.desc)) {
  section.desc.links = section.desc.links || [];
  section.desc = marked.parser(section.desc);
}

if (!section.list) section.list = [];
processList(section);

How to use marked.InlineLexer:

46
47
48
49
50
51
52
53
54
55
  }

  return originalListItemRenderer(text)
}

var originalInlineOutput = marked.InlineLexer.prototype.output

marked.InlineLexer.prototype.output = function (src) {
  return unescapeEmoji(originalInlineOutput.call(this, escapeEmoji(src)))
}

How to use marked.lexer:

8
9
10
11
12
13
14
15
16
var root = {source: filename};
var stack = [root];
var depth = 0;
var current = root;
var state = null;
var lexed = marked.lexer(input);
lexed.forEach(function (tok) {
  var type = tok.type;
  var text = tok.text;

How to use marked.setOptions:

29
30
31
32
33
34
35
36
37
38
var distReadme = join(build, 'dist', grunt.config.get('pkg.name'), 'README.txt');

var srcLicense =  join(root, 'LICENSE.md');
var distLicense = join(build, 'dist', grunt.config.get('pkg.name'), 'LICENSE.txt');

marked.setOptions({
  renderer: new TextRenderer(),
  tables: true,
  breaks: false,
  pedantic: false,

How to use marked.Renderer:

How to use marked.marked:

361
362
363
364
365
366
367
368
369
370
371
372
          },
        },
      ],
    });


    return marked(markdown, markedOptions);
  }


  return render;
}

How to use marked.walkTokens:

2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
var out;

if (!err) {
  try {
    if (opt.walkTokens) {
      marked.walkTokens(tokens, opt.walkTokens);
    }

    out = Parser.parse(tokens, opt);
  } catch (e) {

How to use marked.defaults:

345
346
347
348
349
350
351
352
353
354
 */

function Lexer(options) {
  this.tokens = [];
  this.tokens.links = {};
  this.options = options || marked.defaults;
  this.rules = block.normal;

  if (this.options.gfm) {
    if (this.options.tables) {

How to use marked.parse:

344
345
346
347
348
349
350
351
352
353
354
module.exports = {
	marked : Marked,
	render : (rawBrewText)=>{
		rawBrewText = rawBrewText.replace(/^\\column$/gm, `\n<div class='columnSplit'></div>\n`)
														 .replace(/^(:+)$/gm, (match)=>`${`<div class='blank'></div>`.repeat(match.length)}\n`);
		return Marked.parse(sanatizeScriptTags(rawBrewText));
	},


	validate : (rawBrewText)=>{
		const errors = [];