How to use the marked.parse 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 CharlBest / nean-stack-starter / src / client / app / shared / github / github / github.component.ts View on Github external
async getMarkdownPage() {
    try {
      const response = await this.gitHubService.getFile(this.filePath);
      this.readmeText = parse(response);
      this.doneLoading.emit();
    } catch (error) {
      // TODO: error handling
    }
  }
}
github ngx-meta / rules / apps / doc-app / src / app / layout / markdown / markdown.component.ts View on Github external
render(): void {
    /* parse markdown and replace innerHTML of component */
    this.element.nativeElement.innerHTML = marked.parse(this.mdFile);
    /* highlight syntax by PrismJS */
    Prism.highlightAllUnder(this.element.nativeElement);
    /* get list of main headings for nav menu */
    this.headingsListService.getHeaders(this.element.nativeElement);
    /* add default styling classes for 'pre' tags without specified language */
    this.addDefaultCodeStyling();
  }
github jxcore / jxcore / tools / doc / html.js View on Github external
lexed.forEach(function(tok) {
    if (tok.type !== 'heading') return;
    if (tok.depth - depth > 1) { return cb(new Error(
            'Inappropriate heading level\n' + JSON.stringify(tok))); }

    depth = tok.depth;
    // original from node team:
    // var id = getId(filename + '_' + tok.text.trim());
    var id = getId(tok.text.trim());
    toc.push(new Array((depth - 1) * 2 + 1).join(' ') + '* <a href="#' + id
            + '">' + tok.text + '</a>');
    tok.text += '<span><a href="#' + id + '" class="mark">#</a></span>';
  });

  toc = marked.parse(toc.join('\n'));
  cb(null, toc);
}
github DefinitelyTyped / DefinitelyTyped / types / marked / marked-tests.ts View on Github external
function callback(err: string, markdown: string) {
    console.log('Callback called!');
    return markdown;
}

let myOldMarked: typeof marked = marked.options(options);
myOldMarked = marked.setOptions(options);

console.log(marked('1) I am using __markdown__.'));
console.log(marked('2) I am using __markdown__.', options));
console.log(marked('3) I am using __markdown__.', callback));
console.log(marked('4) I am using __markdown__.', options, callback));

console.log(marked.parse('5) I am using __markdown__.'));
console.log(marked.parse('6) I am using __markdown__.', options));
console.log(marked.parse('7) I am using __markdown__.', callback));
console.log(marked.parse('8) I am using __markdown__.', options, callback));

const text = 'Something';
const tokens: marked.TokensList = marked.lexer(text, options);
console.log(marked.parser(tokens));

const lexer = new marked.Lexer(options);
const tokens2 = lexer.lex(text);
console.log(tokens2);
const re: RegExp | marked.Rules = marked.Lexer.rules['code'];
console.log(lexer.token(text, true));
const lexerOptions: marked.MarkedOptions = lexer.options;

const renderer = new marked.Renderer();
renderer.heading = (text, level, raw, slugger) => {
github powercord-org / powercord-backend / src / routes / ui.js View on Github external
async _markdown (req, res, file, title) {
    let markdown = await get(file).then(r => r.body);
    if (markdown.startsWith(`# ${title}`)) {
      markdown = markdown.split('\n').slice(2).join('\n');
    } else {
      markdown = markdown.replace(/^#/gm, '##');
    }

    res.render('markdown', {
      title,
      markdown: marked.parse(markdown),
      ...req.session
    });
  }
}
github twolfson / twolfson.com / articles / index.js View on Github external
formatter: function (md) {
    return marked.parse(md, {langPrefix: ''});
  },
  render: false
github pmq20 / node-packer / node / tools / doc / html.js View on Github external
if (tok.depth - depth &gt; 1) {
      return cb(new Error('Inappropriate heading level\n' +
                          JSON.stringify(tok)));
    }

    depth = tok.depth;
    const realFilename = path.basename(realFilenames[0], '.md');
    const id = getId(realFilename + '_' + tok.text.trim());
    toc.push(new Array((depth - 1) * 2 + 1).join(' ') +
             '* <span class="stability_' + tok.stability + '">' +
             '<a href="#' + id + '">' + tok.text + '</a></span>');
    tok.text += '<span><a href="#' + id + '" class="mark">#</a></span>';
  });

  toc = marked.parse(toc.join('\n'));
  cb(null, toc);
}
github expressjs / express / examples / view-constructor / index.js View on Github external
app.engine('md', function(str, options, fn){
  try {
    var html = md(str);
    html = html.replace(/\{([^}]+)\}/g, function(_, name){
      return options[name] || '';
    });
    fn(null, html);
  } catch(err) {
    fn(err);
  }
});
github twolfson / twolfson.com / lib / gfmParser.js View on Github external
module.exports = function (code) {
  return gfm.parse(code, {langPrefix: ''});
};