Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@11ty/eleventy-plugin-syntaxhighlight

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy-plugin-syntaxhighlight - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

.gitattributes

20

.eleventy.js

@@ -6,3 +6,2 @@ const pkg = require("./package.json");

const LiquidHighlightTag = require("./src/LiquidHighlightTag");
const CharacterWrap = require("./src/CharacterWrap");
const markdownPrismJs = require("./src/markdownSyntaxHighlightOptions");

@@ -20,5 +19,5 @@

options = Object.assign({
lineSeparator: "\n",
errorOnInvalidLanguage: false,
alwaysWrapLineHighlights: false,
// eligible to change the default to \n in a new major version.
lineSeparator: "<br>",
preAttributes: {},

@@ -28,3 +27,2 @@ codeAttributes: {}

// TODO hbs?
if( hasTemplateFormat(options.templateFormats, "liquid") ) {

@@ -51,9 +49,8 @@ eleventyConfig.addLiquidTag("highlight", (liquidEngine) => {

if( hasTemplateFormat(options.templateFormats, "11ty.js") ) {
eleventyConfig.addJavaScriptFunction("highlight", (language, content, highlight1, highlight2) => {
let highlightLines = [highlight1, highlight2].filter(entry => entry).join(" ");
let result = HighlightPairedShortcode(content, language, highlightLines, options);
return result;
});
}
// we need to add this as many template languages (Vue, WebC) rely on JavaScript functions (not just 11ty.js)
eleventyConfig.addJavaScriptFunction("highlight", (language, content, highlight1, highlight2) => {
let highlightLines = [highlight1, highlight2].filter(entry => entry).join(" ");
let result = HighlightPairedShortcode(content, language, highlightLines, options);
return result;
});
}

@@ -63,2 +60,1 @@ };

module.exports.pairedShortcode = HighlightPairedShortcode;
module.exports.CharacterWrap = CharacterWrap;
{
"name": "@11ty/eleventy-plugin-syntaxhighlight",
"version": "4.2.0",
"description": "Prism.js based syntax highlighting for Markdown, Liquid, Nunjucks, and 11ty.js templates.",
"version": "5.0.0",
"description": "Prism.js based syntax highlighting for Markdown, Liquid, Nunjucks, WebC, and 11ty.js templates.",
"publishConfig": {

@@ -40,9 +40,7 @@ "access": "public"

"devDependencies": {
"@11ty/eleventy": "^1.0.2",
"ava": "^5.0.1",
"liquidjs": "^9.42.1",
"@11ty/eleventy": "^2.0.1",
"ava": "^5.2.0",
"markdown-it": "^13.0.1"
},
"dependencies": {
"linkedom": "^0.14.19",
"prismjs": "^1.29.0"

@@ -49,0 +47,0 @@ },

7

src/HighlightPairedShortcode.js

@@ -16,3 +16,8 @@ const Prism = require("prismjs");

} else {
highlightedContent = Prism.highlight(content, PrismLoader(language), language);
let loader = PrismLoader(language, options);
if(!loader) {
highlightedContent = content;
} else {
highlightedContent = Prism.highlight(content, loader, language);
}
}

@@ -19,0 +24,0 @@

@@ -23,3 +23,8 @@ const Prism = require("prismjs");

} else {
html = Prism.highlight(str, PrismLoader(language), language);
let loader = PrismLoader(language, options)
if(!loader) {
html = str;
} else {
html = Prism.highlight(str, loader, language);
}
}

@@ -29,4 +34,9 @@

let highlights = new HighlightLinesGroup(split.join("/"), "/");
let lines = html.split("\n").slice(0, -1); // The last line is empty.
let lines = html.split("\n");
// Trim last line if it is empty
if (lines[lines.length - 1] === "") {
lines = lines.slice(0, -1);
}
lines = lines.map(function(line, j) {

@@ -33,0 +43,0 @@ if(options.alwaysWrapLineHighlights || hasHighlightNumbers) {

@@ -8,3 +8,3 @@ const Prism = require("prismjs");

module.exports = function(language) {
module.exports = function(language, options = {}) {
let diffRemovedRawName = language;

@@ -17,6 +17,7 @@ if(language.startsWith("diff-")) {

if(!Prism.languages[ aliasedName ]) {
if(!Prism.languages[ aliasedName ]) { // matches `diff` too
PrismLoader(aliasedName);
}
if(!Prism.languages[ aliasedName ]) {
if(options.errorOnInvalidLanguage && !Prism.languages[ aliasedName ]) {
throw new Error(`"${language}" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight`);

@@ -34,6 +35,7 @@ }

PrismLoader("diff");
// Bundled Plugin
require("prismjs/plugins/diff-highlight/prism-diff-highlight");
}
// Bundled Plugin
require("prismjs/plugins/diff-highlight/prism-diff-highlight");
// Store into with aliased keys

@@ -40,0 +42,0 @@ // ts -> diff-typescript

module.exports = function(data) {
let result = this.highlight("diff-js", "-var test;");
return result;
let result1 = this.highlight("diff", "-var test;");
let result2 = this.highlight("diff-js", "-var test;");
return result1 + "\n" + result2;
};

@@ -10,3 +10,3 @@ const test = require("ava");

test("Base with LF EOL, always wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\nalert();',
t.is(await HighlightPairedShortcode('alert();\nalert();',
"js", "", { alwaysWrapLineHighlights: true }), `<pre class="language-js"><code class="language-js"><span class="highlight-line"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span><br><span class="highlight-line"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span></code></pre>`);

@@ -16,3 +16,3 @@ });

test("Base with LF EOL, no wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\nalert();',
t.is(await HighlightPairedShortcode('alert();\nalert();',
"js", "", { alwaysWrapLineHighlights: false }), `<pre class="language-js"><code class="language-js"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>`);

@@ -22,3 +22,3 @@ });

test("Base with CRLF EOL, always wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
"js", "", { alwaysWrapLineHighlights: true }), `<pre class="language-js"><code class="language-js"><span class="highlight-line"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span><br><span class="highlight-line"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span></code></pre>`);

@@ -28,3 +28,3 @@ });

test("Base with CRLF EOL, no wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
"js", "", { alwaysWrapLineHighlights: false }), `<pre class="language-js"><code class="language-js"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><br><span class="token function">alert</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>`);

@@ -92,8 +92,20 @@ });

test("Test loader invalid language", async t => {
test("Test loader invalid language, with errorOnInvalidLanguage option", async t => {
await t.throwsAsync(async () => {
await HighlightPairedShortcode("", "asldkjflksdaj");
});
await HighlightPairedShortcode("", "asldkjflksdaj", null, {
errorOnInvalidLanguage: true
});
}, { message: `"asldkjflksdaj" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight` });
});
test("Test loader invalid language (should pass)", async t => {
t.is(await HighlightPairedShortcode("test test test", "asldkjflksdaj"), `<pre class="language-asldkjflksdaj"><code class="language-asldkjflksdaj">test test test</code></pre>`)
});
test("Test loader invalid language with ignore", async t => {
let src = `hello
hello`
t.is(await HighlightPairedShortcode(src, "asldkjflksdaj"), `<pre class="language-asldkjflksdaj"><code class="language-asldkjflksdaj">hello<br>hello</code></pre>`);
});
test("Trim content option (defaults true)", async t => {

@@ -100,0 +112,0 @@ t.is(await HighlightPairedShortcode(` alert();

@@ -15,3 +15,3 @@ const test = require("ava");

test("JavaScript Function Diff", async t => {
test("JavaScript Function Diff #76", async t => {
let elev = new Eleventy("./test/11tyjs-diff/", "./test/11tyjs-diff/_site/", {

@@ -24,3 +24,4 @@ configPath: "./test/11tyjs-diff/.eleventy.js"

let rendered = json[0].content;
t.is(`<pre class="language-diff-js"><code class="language-diff-js"><span class="token deleted-sign deleted language-js"><span class="token prefix deleted">-</span><span class="token keyword">var</span> test<span class="token punctuation">;</span></span></code></pre>`, rendered);
t.is(`<pre class="language-diff"><code class="language-diff"><span class="token deleted-sign deleted"><span class="token prefix deleted">-</span><span class="token line">var test;</span></span></code></pre>
<pre class="language-diff-js"><code class="language-diff-js"><span class="token deleted-sign deleted language-js"><span class="token prefix deleted">-</span><span class="token keyword">var</span> test<span class="token punctuation">;</span></span></code></pre>`, rendered);
});

@@ -61,3 +61,29 @@ const test = require("ava");

test("Markdown Invalid language", t => {
let mdLib = md();
mdLib.set({
highlight: markdownPrismJsOptions({
errorOnInvalidLanguage: true
})
});
t.throws(() => {
mdLib.render(`\`\`\`asldkjflksdaj
hello
\`\`\``);
});
});
test("Test loader invalid language with ignore", t => {
let src = `\`\`\`asldkjflksdaj
hello
\`\`\``;
let mdLib = md();
mdLib.set({
highlight: markdownPrismJsOptions()
});
t.is(mdLib.render(src).trim(), `<pre class="language-asldkjflksdaj"><code class="language-asldkjflksdaj">hello</code></pre>`);
});
// test("Test Markdown Highlighter Block Comment", t => {

@@ -64,0 +90,0 @@ // let mdLib = md();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc