Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (tokens, idx, options) {
const token = tokens[idx];
let langClass = '';
const langPrefix = options.langPrefix;
let langName = '';
let fenceName = '';
if (token.params) {
fenceName = token.params.split(/\s+/g)[0];
langName = utils.escapeHtml(utils.replaceEntities(utils.unescapeMd(fenceName)));
langClass = langName ? `class="${langPrefix}${langName}"` : '';
}
const highlighted = options.highlight(token.content, langName) || utils.escapeHtml(token.content);
return `<pre><code>${highlighted}</code></pre>${this.getBreak(tokens, idx)}`;
};
function parseCodeBlock(code, lang, langPrefix, highlight) {
let codeBlock = escapeHtml(code);
if (highlight) {
codeBlock = highlight(code, lang);
}
const
langClass = !lang ? '' : `${langPrefix}${escape(lang, true)}`,
jsx = code;
codeBlock = codeBlock
.replace(/{/g, '{"{"{')
.replace(/}/g, '{"}"}')
.replace(/{"{"{/g, '{"{"}')
.replace(/(\n)/g, '{"\\n"}')
.replace(/class=/g, 'className=');
const formatEscape = src => escapeHtml(src)
md.renderer.rules.link_open = (tokens, idx) => {
const title = tokens[idx].title
? ` title="${escapeHtml(replaceEntities(tokens[idx].title))}"`
: '';
const href = escapeHtml(tokens[idx].href);
const isExternal = href.charAt(0) !== '/';
const target = isExternal ? 'target="_blank"' : '';
const rel = isExternal ? 'rel="external nofollow noopener"' : '';
return `<a href="${href}">`;
};
</a>
const imageRule = () => (tokens, idx, options, env) => {
const src: string = ' data-src="' + escapeHtml(tokens[idx].src) + '"';
const title: string = tokens[idx].title ? (' title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '"') : '';
const alt: string = ' alt="' + (tokens[idx].alt ? escapeHtml(replaceEntities(unescapeMd(tokens[idx].alt))) : '') + '"';
const suffix: string = options.xhtmlOut ? ' /' : '';
return '';
};