@11ty/eleventy-plugin-syntaxhighlight
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "@11ty/eleventy-plugin-syntaxhighlight", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A pack of Eleventy plugins for syntax highlighting for Markdown and Liquid templates.", | ||
@@ -5,0 +5,0 @@ "main": ".eleventy.js", |
@@ -30,2 +30,25 @@ const HighlightLines = require("./HighlightLines"); | ||
splitLineMarkup(line, before, after) { | ||
let startCount = line.split("<span").length; | ||
let endCount = line.split("</span").length; | ||
if( startCount > endCount ) { | ||
if( startCount === 2 ) { // simple cases, one orphan <span> | ||
let split = line.split(">"); | ||
let first = split.shift(); | ||
return first + ">" + before + split.join(">") + after; | ||
} | ||
return line; | ||
} else if( endCount > startCount ) { | ||
if( endCount === 2 ) { // simple cases, one orphan </span> | ||
let split = line.split("</"); | ||
let last = split.pop(); | ||
return before + split.join("</") + after + "</" + last; | ||
} | ||
return line; | ||
} | ||
return before + line + after; | ||
} | ||
getLineMarkup(lineNumber, line, extraClasses = []) { | ||
@@ -35,12 +58,12 @@ let extraClassesStr = (extraClasses.length ? " " + extraClasses.join(" ") : ""); | ||
if (this.isHighlighted(lineNumber)) { | ||
return `<mark class="highlight-line highlight-line-active${extraClassesStr}">${line}</mark>`; | ||
return this.splitLineMarkup(line, `<mark class="highlight-line highlight-line-active${extraClassesStr}">`, `</mark>`); | ||
} | ||
if (this.isHighlightedAdd(lineNumber)) { | ||
return `<ins class="highlight-line highlight-line-add${extraClassesStr}">${line}</ins>`; | ||
return this.splitLineMarkup(line, `<ins class="highlight-line highlight-line-add${extraClassesStr}">`, `</ins>`); | ||
} | ||
if (this.isHighlightedRemove(lineNumber)) { | ||
return `<del class="highlight-line highlight-line-remove${extraClassesStr}">${line}</del>`; | ||
return this.splitLineMarkup(line, `<del class="highlight-line highlight-line-remove${extraClassesStr}">`, `</del>`); | ||
} | ||
return `<span class="highlight-line${extraClassesStr}">${line}</span>`; | ||
return this.splitLineMarkup( line, `<span class="highlight-line${extraClassesStr}">`, `</span>`); | ||
} | ||
@@ -47,0 +70,0 @@ } |
@@ -1,2 +0,1 @@ | ||
const HighlightLinesGroup = require("./HighlightLinesGroup"); | ||
const HighlightPairedShortcode = require("./HighlightPairedShortcode"); | ||
@@ -3,0 +2,0 @@ |
@@ -79,1 +79,9 @@ import test from "ava"; | ||
}); | ||
test("Split Line Markup", t => { | ||
let hilite = new HighlightLinesGroup("", " "); | ||
t.is(hilite.splitLineMarkup("Test", "BEFORE", "AFTER"), "BEFORETestAFTER"); | ||
t.is(hilite.splitLineMarkup("<span>Test</span>", "BEFORE", "AFTER"), "BEFORE<span>Test</span>AFTER"); | ||
t.is(hilite.splitLineMarkup("<span>Test", "BEFORE", "AFTER"), "<span>BEFORETestAFTER"); | ||
t.is(hilite.splitLineMarkup("Test</span>", "BEFORE", "AFTER"), "BEFORETestAFTER</span>"); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25110
18
414