Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getMarkdownPage() {
try {
const response = await this.gitHubService.getFile(this.filePath);
this.readmeText = parse(response);
this.doneLoading.emit();
} catch (error) {
// TODO: error handling
}
}
}
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();
}
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);
}
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) => {
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
});
}
}
formatter: function (md) {
return marked.parse(md, {langPrefix: ''});
},
render: false
if (tok.depth - depth > 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);
}
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);
}
});
module.exports = function (code) {
return gfm.parse(code, {langPrefix: ''});
};