How to use the marked.Parser function in marked

To help you get started, we’ve selected a few marked examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github partageit / vegetables / lib / compile.js View on Github external
var updatedTokens = [];
	//console.log('file:', file.filename, 'tags:', commonTags);
	for (i = 0; i < tokens.length; i++) {
		if ((i !== 0) && (tokens[i].type === 'heading')) {
			if (tokens[i].depth <= 2) {
				updatedTokens.push({'type': 'paragraph', 'text': '#HSLIDE'});
			} else if (tokens[i].depth <= (commonTags.slideshow.headingLevel ? commonTags.slideshow.headingLevel : 3)) {
				updatedTokens.push({'type': 'paragraph', 'text': '#VSLIDE'});
			}
		}
		updatedTokens.push(tokens[i]);
	}
	updatedTokens.links = tokens.links;
	//console.log(updatedTokens);
	var renderer = mdRenderer(new marked.Renderer());
	var parser = new marked.Parser({renderer: renderer});
	var slideMarkdown = parser.parse(updatedTokens);

	// HTML content *************************************************************
	var content = marked.parser(tokens);

	// Autoreload tag ***********************************************************
	var autoReload = '';
	if ((config.mode === 'serve') && config.serveAutoReload) {
		autoReload = '' +
		'';
	}

	// Add content to index *****************************************************
github linuxdeepin / deepin-manual / web / src / app / services / manual-renderer.ts View on Github external
let tokens;
  try {
    tokens = lexer.lex(src);
  } catch (err) {
    throw new Error(`Lexer Error ${err}`);
  }
  tokens = extractTokenRange(tokens, fromHeaderId, toHeaderId);

  // render
  let renderer;
  if (toHeaderId === EXTERNAL_READER_NODE_MODE_SPECIAL_ID) {
    renderer = getHTMLRendererForExternalNode();
  } else {
    renderer = getHTMLRendererForExternalRange();
  }
  const parser = new marked.Parser({
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: false,
    smartLists: false,
    silent: false,
    highlight: null,
    langPrefix: 'lang-',
    smartypants: false,
    headerPrefix: '',
    renderer: renderer,
    xhtml: false,
  });
  const oldTok = parser.tok;
  parser.tok = function() {
github bahmutov / update-markdown / index.js View on Github external
var log = require('debug')('um');
var la = require('lazy-ass');
var check = require('check-more-types');
var read = require('fs').readFileSync;
var write = require('fs').writeFileSync;
var _ = require('lodash');

var marked = require('marked');
var mdRenderer = require('marked-to-md');
var renderer = mdRenderer(new marked.Renderer());
var parser = new marked.Parser({renderer: renderer});

// '## bar' -> 'bar'
function headerText(text) {
  la(check.unemptyString(text), 'missing text', text);
  var tokens = marked.lexer(text);
  la(tokens.length, 'missing tokens', tokens, 'from', text);
  return tokens[0].text;
}

function isHeading(token) {
  return token && token.type === 'heading';
}

// returns indices, both could be -1 or the end could be -1
function findSection(tokens, heading) {
  var text = headerText(heading);
github linuxdeepin / deepin-manual / PageRoot / www / jssrc / renderer.js View on Github external
let tokens;
    try {
        tokens = lexer.lex(src);
    } catch (err) {
        throw new Error(`Lexer Error ${err}`);
    }
    tokens = extractTokenRange(tokens, fromHeaderId, toHeaderId);

    // render
    let renderer;
    if (toHeaderId === EXTERNAL_READER_NODE_MODE_SPECIAL_ID) {
        renderer = getHTMLRendererForExternalNode();
    } else {
        renderer = getHTMLRendererForExternalRange();
    }
    let parser = new marked.Parser({
        gfm: true,
        tables: true,
        breaks: false,
        pedantic: false,
        sanitize: false,
        smartLists: false,
        silent: false,
        highlight: null,
        langPrefix: 'lang-',
        smartypants: false,
        headerPrefix: '',
        renderer: renderer,
        xhtml: false,
    });
    let oldTok = parser.tok;
    parser.tok = function() {
github linuxdeepin / deepin-manual / web / src / app / services / manual.ts View on Github external
let tokens;
  try {
    tokens = lexer.lex(src);
  } catch (err) {
    throw new Error(`Lexer Error ${err}`);
  }
  tokens = extractTokenRange(tokens, fromHeaderId, toHeaderId);

  // render
  let renderer;
  if (toHeaderId === EXTERNAL_READER_NODE_MODE_SPECIAL_ID) {
    renderer = getHTMLRendererForExternalNode();
  } else {
    renderer = getHTMLRendererForExternalRange();
  }
  const parser = new marked.Parser({
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: false,
    smartLists: false,
    silent: false,
    highlight: null,
    langPrefix: 'lang-',
    smartypants: false,
    headerPrefix: '',
    renderer: renderer,
    xhtml: false,
  });
  const oldTok = parser.tok;
  parser.tok = function() {
github linuxdeepin / deepin-manual / web / src / app / services / manual-renderer.ts View on Github external
const _inlineDeMarkdown = function(token) {
    // called by parseNavigationItems,
    // html, paragraph, and text needs inline parsing to strip markdown marks.
    const payload = [token];
    payload.links = tokens.links;
    const parser = new marked.Parser({
      gfm: true,
      tables: true,
      breaks: false,
      pedantic: false,
      sanitize: false,
      smartLists: false,
      silent: false,
      highlight: null,
      langPrefix: 'lang-',
      smartypants: false,
      headerPrefix: '',
      renderer: getPlainRenderer(),
      xhtml: false,
    });
    const text = parser.parse(payload);
    return text;
github DefinitelyTyped / DefinitelyTyped / types / marked / marked-tests.ts View on Github external
return text + level.toString() + slugger.slug(raw);
};
renderer.hr = () => {
    return `\n`;
};
renderer.checkbox = (checked) => {
    return checked ? 'CHECKED' : 'UNCHECKED';
};
const rendererOptions: marked.MarkedOptions = renderer.options;

const textRenderer = new marked.TextRenderer();
console.log(textRenderer.strong(text));

const parseTestText = '- list1\n  - list1.1\n\n listend';
const parseTestTokens: marked.TokensList = marked.lexer(parseTestText, options);
const parser = new marked.Parser();
console.log(parser.parse(parseTestTokens));
console.log(marked.Parser.parse(parseTestTokens));
const parserOptions: marked.MarkedOptions = parser.options;

const links = ['http', 'image'];
const inlineLexer = new marked.InlineLexer(links);
console.log(inlineLexer.output('http://'));
console.log(marked.InlineLexer.output('http://', links));
console.log(marked.InlineLexer.rules);
const inlineLexerOptions: marked.MarkedOptions = inlineLexer.options;
github dwilding / trello-kb / index.js View on Github external
Object.keys(result.tokens).forEach((key) => {
              var renderer = this.customMarkdownRenderer(cardShortId, key);
              var parser = new marked.Parser({
                gfm: true,
                breaks: true,
                tables: false,
                renderer: renderer
              });
              var html = parser.parse(result.tokens[key]);
              result.card[key] = html.replace(/\n+$/, '');
            });
            converted.push(result.card);
github dwilding / trello-kb / index.js View on Github external
constructor(appKey, authToken, boardId) {
    this.api = new Trello(appKey, authToken);
    this.boardId = boardId;
    this.lexer = new marked.Lexer({
      gfm: true,
      breaks: true,
      tables: false
    });
    this.parser = new marked.Parser({
      gfm: true,
      breaks: true,
      tables: false
    });
    this.options = Converter.defaultOptions;
    this.results = {};
    this.warnings = [];
  }
github fy0 / storynote / page / src / md.js View on Github external
baseMarked.Parser.parse = function (src, options) {
    let parser = new baseMarked.Parser(options)
    parser.renderer.headingCount = undefined
    parser.renderer._parser = parser
    return parser.parse(src)
}