aboutsummaryrefslogtreecommitdiff
path: root/node_modules/prismjs/plugins/line-highlight
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prismjs/plugins/line-highlight')
-rw-r--r--node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css49
-rw-r--r--node_modules/prismjs/plugins/line-highlight/prism-line-highlight.js181
-rw-r--r--node_modules/prismjs/plugins/line-highlight/prism-line-highlight.min.js1
3 files changed, 231 insertions, 0 deletions
diff --git a/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css
new file mode 100644
index 00000000..6058db44
--- /dev/null
+++ b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.css
@@ -0,0 +1,49 @@
+pre[data-line] {
+ position: relative;
+ padding: 1em 0 1em 3em;
+}
+
+.line-highlight {
+ position: absolute;
+ left: 0;
+ right: 0;
+ padding: inherit 0;
+ margin-top: 1em; /* Same as .prism’s padding-top */
+
+ background: hsla(24, 20%, 50%,.08);
+ background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
+
+ pointer-events: none;
+
+ line-height: inherit;
+ white-space: pre;
+}
+
+ .line-highlight:before,
+ .line-highlight[data-end]:after {
+ content: attr(data-start);
+ position: absolute;
+ top: .4em;
+ left: .6em;
+ min-width: 1em;
+ padding: 0 .5em;
+ background-color: hsla(24, 20%, 50%,.4);
+ color: hsl(24, 20%, 95%);
+ font: bold 65%/1.5 sans-serif;
+ text-align: center;
+ vertical-align: .3em;
+ border-radius: 999px;
+ text-shadow: none;
+ box-shadow: 0 1px white;
+ }
+
+ .line-highlight[data-end]:after {
+ content: attr(data-end);
+ top: auto;
+ bottom: .4em;
+ }
+
+.line-numbers .line-highlight:before,
+.line-numbers .line-highlight:after {
+ content: none;
+}
diff --git a/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.js b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.js
new file mode 100644
index 00000000..5d919ae6
--- /dev/null
+++ b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.js
@@ -0,0 +1,181 @@
+(function(){
+
+if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
+ return;
+}
+
+function $$(expr, con) {
+ return Array.prototype.slice.call((con || document).querySelectorAll(expr));
+}
+
+function hasClass(element, className) {
+ className = " " + className + " ";
+ return (" " + element.className + " ").replace(/[\n\t]/g, " ").indexOf(className) > -1
+}
+
+// Some browsers round the line-height, others don't.
+// We need to test for it to position the elements properly.
+var isLineHeightRounded = (function() {
+ var res;
+ return function() {
+ if(typeof res === 'undefined') {
+ var d = document.createElement('div');
+ d.style.fontSize = '13px';
+ d.style.lineHeight = '1.5';
+ d.style.padding = 0;
+ d.style.border = 0;
+ d.innerHTML = '&nbsp;<br />&nbsp;';
+ document.body.appendChild(d);
+ // Browsers that round the line-height should have offsetHeight === 38
+ // The others should have 39.
+ res = d.offsetHeight === 38;
+ document.body.removeChild(d);
+ }
+ return res;
+ }
+}());
+
+function highlightLines(pre, lines, classes) {
+ lines = typeof lines === 'string' ? lines : pre.getAttribute('data-line');
+
+ var ranges = lines.replace(/\s+/g, '').split(','),
+ offset = +pre.getAttribute('data-line-offset') || 0;
+
+ var parseMethod = isLineHeightRounded() ? parseInt : parseFloat;
+ var lineHeight = parseMethod(getComputedStyle(pre).lineHeight);
+ var hasLineNumbers = hasClass(pre, 'line-numbers');
+
+ for (var i=0, currentRange; currentRange = ranges[i++];) {
+ var range = currentRange.split('-');
+
+ var start = +range[0],
+ end = +range[1] || start;
+
+ var line = pre.querySelector('.line-highlight[data-range="' + currentRange + '"]') || document.createElement('div');
+
+ line.setAttribute('aria-hidden', 'true');
+ line.setAttribute('data-range', currentRange);
+ line.className = (classes || '') + ' line-highlight';
+
+ //if the line-numbers plugin is enabled, then there is no reason for this plugin to display the line numbers
+ if(hasLineNumbers && Prism.plugins.lineNumbers) {
+ var startNode = Prism.plugins.lineNumbers.getLine(pre, start);
+ var endNode = Prism.plugins.lineNumbers.getLine(pre, end);
+
+ if (startNode) {
+ line.style.top = startNode.offsetTop + 'px';
+ }
+
+ if (endNode) {
+ line.style.height = (endNode.offsetTop - startNode.offsetTop) + endNode.offsetHeight + 'px';
+ }
+ } else {
+ line.setAttribute('data-start', start);
+
+ if(end > start) {
+ line.setAttribute('data-end', end);
+ }
+
+ line.style.top = (start - offset - 1) * lineHeight + 'px';
+
+ line.textContent = new Array(end - start + 2).join(' \n');
+ }
+
+ //allow this to play nicely with the line-numbers plugin
+ if(hasLineNumbers) {
+ //need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
+ pre.appendChild(line);
+ } else {
+ (pre.querySelector('code') || pre).appendChild(line);
+ }
+ }
+}
+
+function applyHash() {
+ var hash = location.hash.slice(1);
+
+ // Remove pre-existing temporary lines
+ $$('.temporary.line-highlight').forEach(function (line) {
+ line.parentNode.removeChild(line);
+ });
+
+ var range = (hash.match(/\.([\d,-]+)$/) || [,''])[1];
+
+ if (!range || document.getElementById(hash)) {
+ return;
+ }
+
+ var id = hash.slice(0, hash.lastIndexOf('.')),
+ pre = document.getElementById(id);
+
+ if (!pre) {
+ return;
+ }
+
+ if (!pre.hasAttribute('data-line')) {
+ pre.setAttribute('data-line', '');
+ }
+
+ highlightLines(pre, range, 'temporary ');
+
+ document.querySelector('.temporary.line-highlight').scrollIntoView();
+}
+
+var fakeTimer = 0; // Hack to limit the number of times applyHash() runs
+
+Prism.hooks.add('before-sanity-check', function(env) {
+ var pre = env.element.parentNode;
+ var lines = pre && pre.getAttribute('data-line');
+
+ if (!pre || !lines || !/pre/i.test(pre.nodeName)) {
+ return;
+ }
+
+ /*
+ * Cleanup for other plugins (e.g. autoloader).
+ *
+ * Sometimes <code> blocks are highlighted multiple times. It is necessary
+ * to cleanup any left-over tags, because the whitespace inside of the <div>
+ * tags change the content of the <code> tag.
+ */
+ var num = 0;
+ $$('.line-highlight', pre).forEach(function (line) {
+ num += line.textContent.length;
+ line.parentNode.removeChild(line);
+ });
+ // Remove extra whitespace
+ if (num && /^( \n)+$/.test(env.code.slice(-num))) {
+ env.code = env.code.slice(0, -num);
+ }
+});
+
+Prism.hooks.add('complete', function completeHook(env) {
+ var pre = env.element.parentNode;
+ var lines = pre && pre.getAttribute('data-line');
+
+ if (!pre || !lines || !/pre/i.test(pre.nodeName)) {
+ return;
+ }
+
+ clearTimeout(fakeTimer);
+
+ var hasLineNumbers = Prism.plugins.lineNumbers;
+ var isLineNumbersLoaded = env.plugins && env.plugins.lineNumbers;
+
+ if (hasClass(pre, 'line-numbers') && hasLineNumbers && !isLineNumbersLoaded) {
+ Prism.hooks.add('line-numbers', completeHook);
+ } else {
+ highlightLines(pre, lines);
+ fakeTimer = setTimeout(applyHash, 1);
+ }
+});
+
+ window.addEventListener('hashchange', applyHash);
+ window.addEventListener('resize', function () {
+ var preElements = document.querySelectorAll('pre[data-line]');
+ Array.prototype.forEach.call(preElements, function (pre) {
+ highlightLines(pre);
+ });
+ });
+
+})(); \ No newline at end of file
diff --git a/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.min.js b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.min.js
new file mode 100644
index 00000000..6c870914
--- /dev/null
+++ b/node_modules/prismjs/plugins/line-highlight/prism-line-highlight.min.js
@@ -0,0 +1 @@
+!function(){function e(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function t(e,t){return t=" "+t+" ",(" "+e.className+" ").replace(/[\n\t]/g," ").indexOf(t)>-1}function n(e,n,i){n="string"==typeof n?n:e.getAttribute("data-line");for(var o,l=n.replace(/\s+/g,"").split(","),a=+e.getAttribute("data-line-offset")||0,s=r()?parseInt:parseFloat,d=s(getComputedStyle(e).lineHeight),u=t(e,"line-numbers"),c=0;o=l[c++];){var p=o.split("-"),m=+p[0],f=+p[1]||m,h=e.querySelector('.line-highlight[data-range="'+o+'"]')||document.createElement("div");if(h.setAttribute("aria-hidden","true"),h.setAttribute("data-range",o),h.className=(i||"")+" line-highlight",u&&Prism.plugins.lineNumbers){var g=Prism.plugins.lineNumbers.getLine(e,m),y=Prism.plugins.lineNumbers.getLine(e,f);g&&(h.style.top=g.offsetTop+"px"),y&&(h.style.height=y.offsetTop-g.offsetTop+y.offsetHeight+"px")}else h.setAttribute("data-start",m),f>m&&h.setAttribute("data-end",f),h.style.top=(m-a-1)*d+"px",h.textContent=new Array(f-m+2).join(" \n");u?e.appendChild(h):(e.querySelector("code")||e).appendChild(h)}}function i(){var t=location.hash.slice(1);e(".temporary.line-highlight").forEach(function(e){e.parentNode.removeChild(e)});var i=(t.match(/\.([\d,-]+)$/)||[,""])[1];if(i&&!document.getElementById(t)){var r=t.slice(0,t.lastIndexOf(".")),o=document.getElementById(r);o&&(o.hasAttribute("data-line")||o.setAttribute("data-line",""),n(o,i,"temporary "),document.querySelector(".temporary.line-highlight").scrollIntoView())}}if("undefined"!=typeof self&&self.Prism&&self.document&&document.querySelector){var r=function(){var e;return function(){if("undefined"==typeof e){var t=document.createElement("div");t.style.fontSize="13px",t.style.lineHeight="1.5",t.style.padding=0,t.style.border=0,t.innerHTML="&nbsp;<br />&nbsp;",document.body.appendChild(t),e=38===t.offsetHeight,document.body.removeChild(t)}return e}}(),o=0;Prism.hooks.add("before-sanity-check",function(t){var n=t.element.parentNode,i=n&&n.getAttribute("data-line");if(n&&i&&/pre/i.test(n.nodeName)){var r=0;e(".line-highlight",n).forEach(function(e){r+=e.textContent.length,e.parentNode.removeChild(e)}),r&&/^( \n)+$/.test(t.code.slice(-r))&&(t.code=t.code.slice(0,-r))}}),Prism.hooks.add("complete",function l(e){var r=e.element.parentNode,a=r&&r.getAttribute("data-line");if(r&&a&&/pre/i.test(r.nodeName)){clearTimeout(o);var s=Prism.plugins.lineNumbers,d=e.plugins&&e.plugins.lineNumbers;t(r,"line-numbers")&&s&&!d?Prism.hooks.add("line-numbers",l):(n(r,a),o=setTimeout(i,1))}}),window.addEventListener("hashchange",i),window.addEventListener("resize",function(){var e=document.querySelectorAll("pre[data-line]");Array.prototype.forEach.call(e,function(e){n(e)})})}}(); \ No newline at end of file