Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (match[3]) {
options.caption += `<a href="${match[3]}">${match[4] ? match[4] : 'link'}</a>`;
}
}
}
}
// PR #3765
if (start.includes('>')) {
const depth = start.split('>').length - 1;
const regexp = new RegExp(`^([^\\S\\r\\n]*>){0,${depth}}([^\\S\\r\\n]|$)`, 'mg');
const paddingOnEnd = ' '; // complement uncaptured whitespaces at last line
content = (content + paddingOnEnd).replace(regexp, '').replace(/\n$/, '');
}
content = highlight(stripIndent(content), options)
.replace(/{/g, '{')
.replace(/}/g, '}');
return `${start}${content}${end}`;
});
}
code = stripIndent(code).trim();
if (!config.enable) {
return `<pre><code>${code}</code></pre>`;
}
// If the title is not defined, use file name instead
title = title || basename(path);
// If the language is not defined, use file extension instead
lang = lang || extname(path).substring(1);
const caption = `<span>${title}</span><a href="${ctx.config.root}${codeDir}${path}">view raw</a>`;
return highlight(code, {
lang,
caption,
gutter: config.line_number,
hljs: config.hljs,
tab: config.tab_replace
});
});
};
it('render() - escaping swig blocks with similar names', () => {
const code = 'alert("Hello world")';
const highlighted = util.highlight(code);
const content = [
'{% codeblock %}',
code,
'{% endcodeblock %}',
'',
'{% code %}',
code,
'{% endcode %}'
].join('\n');
return post.render(null, {
content
}).then(data => {
data.content.trim().should.eql([
highlighted,
it('from and to', () => {
const fixture = [
'sleep();'
].join('\n');
const expected = highlight(fixture, {
lang: 'js',
caption: '<span>Hello world</span><a href="/downloads/code/test.js">view raw</a>'
});
return code('Hello world lang:js from:2 to:2 test.js').then(result => {
result.should.eql(expected);
});
});
function highlight(code, options) {
return util.highlight(code, options || {})
.replace(/{/g, '{')
.replace(/}/g, '}');
}
function highlight(code, options) {
return util.highlight(code, options || {})
.replace(/{/g, '{')
.replace(/}/g, '}');
}
exports.expected = [
'<h1 id="Title"><a title="Title" class="headerlink" href="#Title"></a>Title</h1>',
highlight(code, {lang: 'python'}),
'\n<p>some content</p>\n',
'<h2 id="Another-title"><a title="Another title" class="headerlink" href="#Another-title"></a>Another title</h2>',
'<blockquote>',
'<p>quote content</p>\n',
'</blockquote>\n\n',
'<blockquote><p>quote content</p>\n',
'<footer><strong>Hello World</strong></footer></blockquote>'
].join('');
exports.expected_disable_nunjucks = [
'<h1 id="Title"><a title="Title" class="headerlink" href="#Title"></a>Title</h1>',
highlight(code, {lang: 'python'}),
'\n<p>some content</p>\n',
'<h2 id="Another-title"><a title="Another title" class="headerlink" href="#Another-title"></a>Another title</h2>',
'<p>{% blockquote %}<br>',
'quote content<br>',
'{% endblockquote %}</p>\n',
'<p>{% quote Hello World %}<br>',
'quote content<br>',
'{% endquote %}</p>'
].join('');
if (rHighlight.test(arg)) {
arg = arg.replace(rHighlight, (match, _enable) => {
enable = _enable === 'true';
return '';
});
}
if (!enable) {
content = escapeHTML(content);
return `<pre><code>${content}</code></pre>`;
}
content = stripIndent(content);
content = highlight(content, getHighlightOptions(config, arg));
content = content.replace(/{/g, '{')
.replace(/}/g, '}');
return content;
};
$('.highlight code').each(function(index, elem) {
options.lang = elem.attribs['data-lang'];
var code = entities.decodeXML($(elem).text());
var content = util.highlight(code, options);
$(elem).html(content);
});