use prism-tomorrow.css
This commit is contained in:
80
docs/_style/prism-master/plugins/keep-markup/index.html
Normal file
80
docs/_style/prism-master/plugins/keep-markup/index.html
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.png" />
|
||||
<title>Keep markup ▲ Prism plugins</title>
|
||||
<base href="../.." />
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
|
||||
|
||||
<style type="text/css">
|
||||
code[class*="language-"] mark,
|
||||
pre[class*="language-"] mark {
|
||||
display: inline-block;
|
||||
color: inherit;
|
||||
background: none;
|
||||
border: 1px solid #000;
|
||||
box-shadow: 0 0 2px #fff;
|
||||
padding: 1px;
|
||||
background: rgba(0,0,0,0.2);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="prefixfree.min.js"></script>
|
||||
|
||||
<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
|
||||
<script src="https://www.google-analytics.com/ga.js" async></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div>
|
||||
|
||||
<h2>Keep markup</h2>
|
||||
<p>Prevents custom markup from being dropped out during highlighting.</p>
|
||||
</header>
|
||||
|
||||
<section>
|
||||
|
||||
<h1>How to use</h1>
|
||||
<p>You have nothing to do. With this plugin loaded, all markup inside code will be kept.</p>
|
||||
|
||||
<h1>Examples</h1>
|
||||
|
||||
<p>The following source code</p>
|
||||
<pre><code class="language-markup"><pre><code class="language-css">
|
||||
@media <mark>screen</mark> {
|
||||
div {
|
||||
<mark>text</mark>-decoration: <mark><mark>under</mark>line</mark>;
|
||||
back<mark>ground: url</mark>('foo.png');
|
||||
}
|
||||
}</code></pre></code></pre>
|
||||
|
||||
<p>would render like this:</p>
|
||||
<pre><code class="language-css">
|
||||
@media <mark>screen</mark> {
|
||||
div {
|
||||
<mark>text</mark>-decoration: <mark><mark>under</mark>line</mark>;
|
||||
back<mark>ground: url</mark>('foo.png');
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<p>
|
||||
It also works for inline code:
|
||||
<code class="language-javascript">v<mark>ar b</mark>ar = <mark>func</mark>tion () { <mark>/*</mark> foo <mark>*</mark>/ };</code>
|
||||
</p>
|
||||
|
||||
</section>
|
||||
|
||||
<footer data-src="templates/footer.html" data-type="text/html"></footer>
|
||||
|
||||
<script src="prism.js"></script>
|
||||
<script src="plugins/keep-markup/prism-keep-markup.js"></script>
|
||||
<script src="utopia.js"></script>
|
||||
<script src="components.js"></script>
|
||||
<script src="code.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,99 @@
|
||||
(function () {
|
||||
|
||||
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.createRange) {
|
||||
return;
|
||||
}
|
||||
|
||||
Prism.plugins.KeepMarkup = true;
|
||||
|
||||
Prism.hooks.add('before-highlight', function (env) {
|
||||
if (!env.element.children.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pos = 0;
|
||||
var data = [];
|
||||
var f = function (elt, baseNode) {
|
||||
var o = {};
|
||||
if (!baseNode) {
|
||||
// Clone the original tag to keep all attributes
|
||||
o.clone = elt.cloneNode(false);
|
||||
o.posOpen = pos;
|
||||
data.push(o);
|
||||
}
|
||||
for (var i = 0, l = elt.childNodes.length; i < l; i++) {
|
||||
var child = elt.childNodes[i];
|
||||
if (child.nodeType === 1) { // element
|
||||
f(child);
|
||||
} else if(child.nodeType === 3) { // text
|
||||
pos += child.data.length;
|
||||
}
|
||||
}
|
||||
if (!baseNode) {
|
||||
o.posClose = pos;
|
||||
}
|
||||
};
|
||||
f(env.element, true);
|
||||
|
||||
if (data && data.length) {
|
||||
// data is an array of all existing tags
|
||||
env.keepMarkup = data;
|
||||
}
|
||||
});
|
||||
|
||||
Prism.hooks.add('after-highlight', function (env) {
|
||||
if(env.keepMarkup && env.keepMarkup.length) {
|
||||
|
||||
var walk = function (elt, nodeState) {
|
||||
for (var i = 0, l = elt.childNodes.length; i < l; i++) {
|
||||
|
||||
var child = elt.childNodes[i];
|
||||
|
||||
if (child.nodeType === 1) { // element
|
||||
if (!walk(child, nodeState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} else if (child.nodeType === 3) { // text
|
||||
if(!nodeState.nodeStart && nodeState.pos + child.data.length > nodeState.node.posOpen) {
|
||||
// We found the start position
|
||||
nodeState.nodeStart = child;
|
||||
nodeState.nodeStartPos = nodeState.node.posOpen - nodeState.pos;
|
||||
}
|
||||
if(nodeState.nodeStart && nodeState.pos + child.data.length >= nodeState.node.posClose) {
|
||||
// We found the end position
|
||||
nodeState.nodeEnd = child;
|
||||
nodeState.nodeEndPos = nodeState.node.posClose - nodeState.pos;
|
||||
}
|
||||
|
||||
nodeState.pos += child.data.length;
|
||||
}
|
||||
|
||||
if (nodeState.nodeStart && nodeState.nodeEnd) {
|
||||
// Select the range and wrap it with the clone
|
||||
var range = document.createRange();
|
||||
range.setStart(nodeState.nodeStart, nodeState.nodeStartPos);
|
||||
range.setEnd(nodeState.nodeEnd, nodeState.nodeEndPos);
|
||||
nodeState.node.clone.appendChild(range.extractContents());
|
||||
range.insertNode(nodeState.node.clone);
|
||||
range.detach();
|
||||
|
||||
// Process is over
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// For each tag, we walk the DOM to reinsert it
|
||||
env.keepMarkup.forEach(function (node) {
|
||||
walk(env.element, {
|
||||
node: node,
|
||||
pos: 0
|
||||
});
|
||||
});
|
||||
// Store new highlightedCode for later hooks calls
|
||||
env.highlightedCode = env.element.innerHTML;
|
||||
}
|
||||
});
|
||||
}());
|
1
docs/_style/prism-master/plugins/keep-markup/prism-keep-markup.min.js
vendored
Normal file
1
docs/_style/prism-master/plugins/keep-markup/prism-keep-markup.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(){"undefined"!=typeof self&&self.Prism&&self.document&&document.createRange&&(Prism.plugins.KeepMarkup=!0,Prism.hooks.add("before-highlight",function(e){if(e.element.children.length){var n=0,o=[],t=function(e,d){var r={};d||(r.clone=e.cloneNode(!1),r.posOpen=n,o.push(r));for(var a=0,s=e.childNodes.length;s>a;a++){var l=e.childNodes[a];1===l.nodeType?t(l):3===l.nodeType&&(n+=l.data.length)}d||(r.posClose=n)};t(e.element,!0),o&&o.length&&(e.keepMarkup=o)}}),Prism.hooks.add("after-highlight",function(e){if(e.keepMarkup&&e.keepMarkup.length){var n=function(e,o){for(var t=0,d=e.childNodes.length;d>t;t++){var r=e.childNodes[t];if(1===r.nodeType){if(!n(r,o))return!1}else 3===r.nodeType&&(!o.nodeStart&&o.pos+r.data.length>o.node.posOpen&&(o.nodeStart=r,o.nodeStartPos=o.node.posOpen-o.pos),o.nodeStart&&o.pos+r.data.length>=o.node.posClose&&(o.nodeEnd=r,o.nodeEndPos=o.node.posClose-o.pos),o.pos+=r.data.length);if(o.nodeStart&&o.nodeEnd){var a=document.createRange();return a.setStart(o.nodeStart,o.nodeStartPos),a.setEnd(o.nodeEnd,o.nodeEndPos),o.node.clone.appendChild(a.extractContents()),a.insertNode(o.node.clone),a.detach(),!1}}return!0};e.keepMarkup.forEach(function(o){n(e.element,{node:o,pos:0})}),e.highlightedCode=e.element.innerHTML}}))}();
|
Reference in New Issue
Block a user