use prism-tomorrow.css
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
<body>
|
||||
<section id="main" class="language-javascript">
|
||||
|
||||
<pre>
|
||||
|
||||
<code>
|
||||
|
||||
|
||||
var example = {
|
||||
foo: true,
|
||||
|
||||
bar: false
|
||||
};
|
||||
|
||||
|
||||
</code>
|
||||
|
||||
</pre>
|
||||
|
||||
</section>
|
||||
|
||||
<script src="prism.js"></script>
|
||||
<script src="plugins/normalize-whitespace/prism-normalize-whitespace.js"></script>
|
||||
<script type="text/javascript">
|
||||
// Optional
|
||||
Prism.plugins.NormalizeWhitespace.setDefaults({
|
||||
'remove-trailing': true,
|
||||
'remove-indent': true,
|
||||
'left-trim': true,
|
||||
'right-trim': true,
|
||||
});
|
||||
</script>
|
||||
</body>
|
180
docs/_style/prism-master/plugins/normalize-whitespace/index.html
Normal file
180
docs/_style/prism-master/plugins/normalize-whitespace/index.html
Normal file
@ -0,0 +1,180 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.png" />
|
||||
<title>Normalize Whitespace ▲ 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>Normalize Whitespace</h2>
|
||||
<p>Supports multiple operations to normalize whitespace in code blocks.</p>
|
||||
</header>
|
||||
|
||||
<section class="language-markup">
|
||||
<h1>How to use</h1>
|
||||
|
||||
<p>Obviously, this is supposed to work only for code blocks (<code><pre><code></code>) and not for inline code.</p>
|
||||
<p>By default the plugin trims all leading and trailing whitespace of every code block.
|
||||
It also removes extra indents and trailing whitespace on every line.</p>
|
||||
|
||||
<p>The plugin can be disabled for a particular code block by adding the class <code>no-whitespace-normalization</code> to
|
||||
either the <code><pre></code> or <code><code></code> tag.</p>
|
||||
|
||||
<p>The default settings can be overridden with the <code class="language-javascript">setDefaults()</code> method
|
||||
like so:</p>
|
||||
|
||||
<pre class="language-javascript"><code>
|
||||
Prism.plugins.NormalizeWhitespace.setDefaults({
|
||||
'remove-trailing': true,
|
||||
'remove-indent': true,
|
||||
'left-trim': true,
|
||||
'right-trim': true,
|
||||
/*'break-lines': 80,
|
||||
'indent': 2,
|
||||
'remove-initial-line-feed': false,
|
||||
'tabs-to-spaces': 4,
|
||||
'spaces-to-tabs': 4*/
|
||||
});
|
||||
</code></pre>
|
||||
|
||||
<p>The following settings are available:</p>
|
||||
|
||||
<dl>
|
||||
<dt>remove-trailing</dt>
|
||||
<dd>Removes trailing whitespace on all lines.</dd>
|
||||
<dt>remove-indent</dt>
|
||||
<dd>If the whole code block is indented too much it removes the extra indent.</dd>
|
||||
<dt>left-trim</dt>
|
||||
<dd>Removes all whitespace from the top of the code block.</dd>
|
||||
<dt>right-trim</dt>
|
||||
<dd>Removes all whitespace from the bottom of the code block.</dd>
|
||||
<dt>break-lines</dt>
|
||||
<dd>Simple way of breaking long lines at a certain length (default is 80 characters).</dd>
|
||||
<dt>indent</dt>
|
||||
<dd>Adds a certain number of tabs to every line.</dd>
|
||||
<dt>remove-initial-line-feed</dt>
|
||||
<dd>Less aggressive version of left-trim.
|
||||
It only removes a single line feed from the top of the code block.</dd>
|
||||
<dt>tabs-to-spaces</dt>
|
||||
<dd>Converts all tabs to a certain number of spaces (default is 4 spaces).</dd>
|
||||
<dt>spaces-to-tabs</dt>
|
||||
<dd>Converts a certain number of spaces to a tab (default is 4 spaces).</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="language-markup">
|
||||
<h1>Examples</h1>
|
||||
|
||||
<p>The following example demonstrates the use of this plugin:</p>
|
||||
|
||||
<pre data-src="plugins/normalize-whitespace/demo.html"></pre>
|
||||
|
||||
<p>The result looks like this:</p>
|
||||
|
||||
<pre class="language-javascript">
|
||||
|
||||
<code>
|
||||
|
||||
|
||||
var example = {
|
||||
foo: true,
|
||||
|
||||
bar: false
|
||||
};
|
||||
|
||||
|
||||
</code>
|
||||
|
||||
</pre>
|
||||
|
||||
<p>It is also compatible with the <a href="plugins/keep-markup/">keep-markup</a> plugin:</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>This plugin can also be used on the server or on the command line with Node.js:</p>
|
||||
|
||||
<pre><code class="language-javascript">
|
||||
var Prism = require('prismjs');
|
||||
var Normalizer = require('prismjs/plugins/normalize-whitespace/prism-normalize-whitespace');
|
||||
// Create a new Normalizer object
|
||||
var nw = new Normalizer({
|
||||
'remove-trailing': true,
|
||||
'remove-indent': true,
|
||||
'left-trim': true,
|
||||
'right-trim': true,
|
||||
/*'break-lines': 80,
|
||||
'indent': 2,
|
||||
'remove-initial-line-feed': false,
|
||||
'tabs-to-spaces': 4,
|
||||
'spaces-to-tabs': 4*/
|
||||
});
|
||||
|
||||
// ..or use the default object from Prism
|
||||
nw = Prism.plugins.NormalizeWhitespace;
|
||||
|
||||
// The code snippet you want to highlight, as a string
|
||||
var code = "\t\t\tvar data = 1; ";
|
||||
|
||||
// Removes leading and trailing whitespace
|
||||
// and then indents by 1 tab
|
||||
code = nw.normalize(code, {
|
||||
// Extra settings
|
||||
indent: 1
|
||||
});
|
||||
|
||||
// Returns a highlighted HTML string
|
||||
var html = Prism.highlight(code, Prism.languages.javascript);
|
||||
</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<footer data-src="templates/footer.html" data-type="text/html"></footer>
|
||||
|
||||
<script src="prism.js"></script>
|
||||
<script src="plugins/normalize-whitespace/prism-normalize-whitespace.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,190 @@
|
||||
(function() {
|
||||
|
||||
var assign = Object.assign || function (obj1, obj2) {
|
||||
for (var name in obj2) {
|
||||
if (obj2.hasOwnProperty(name))
|
||||
obj1[name] = obj2[name];
|
||||
}
|
||||
return obj1;
|
||||
}
|
||||
|
||||
function NormalizeWhitespace(defaults) {
|
||||
this.defaults = assign({}, defaults);
|
||||
}
|
||||
|
||||
function toCamelCase(value) {
|
||||
return value.replace(/-(\w)/g, function(match, firstChar) {
|
||||
return firstChar.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function tabLen(str) {
|
||||
var res = 0;
|
||||
for (var i = 0; i < str.length; ++i) {
|
||||
if (str.charCodeAt(i) == '\t'.charCodeAt(0))
|
||||
res += 3;
|
||||
}
|
||||
return str.length + res;
|
||||
}
|
||||
|
||||
NormalizeWhitespace.prototype = {
|
||||
setDefaults: function (defaults) {
|
||||
this.defaults = assign(this.defaults, defaults);
|
||||
},
|
||||
normalize: function (input, settings) {
|
||||
settings = assign(this.defaults, settings);
|
||||
|
||||
for (var name in settings) {
|
||||
var methodName = toCamelCase(name);
|
||||
if (name !== "normalize" && methodName !== 'setDefaults' &&
|
||||
settings[name] && this[methodName]) {
|
||||
input = this[methodName].call(this, input, settings[name]);
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
},
|
||||
|
||||
/*
|
||||
* Normalization methods
|
||||
*/
|
||||
leftTrim: function (input) {
|
||||
return input.replace(/^\s+/, '');
|
||||
},
|
||||
rightTrim: function (input) {
|
||||
return input.replace(/\s+$/, '');
|
||||
},
|
||||
tabsToSpaces: function (input, spaces) {
|
||||
spaces = spaces|0 || 4;
|
||||
return input.replace(/\t/g, new Array(++spaces).join(' '));
|
||||
},
|
||||
spacesToTabs: function (input, spaces) {
|
||||
spaces = spaces|0 || 4;
|
||||
return input.replace(RegExp(' {' + spaces + '}', 'g'), '\t');
|
||||
},
|
||||
removeTrailing: function (input) {
|
||||
return input.replace(/\s*?$/gm, '');
|
||||
},
|
||||
// Support for deprecated plugin remove-initial-line-feed
|
||||
removeInitialLineFeed: function (input) {
|
||||
return input.replace(/^(?:\r?\n|\r)/, '');
|
||||
},
|
||||
removeIndent: function (input) {
|
||||
var indents = input.match(/^[^\S\n\r]*(?=\S)/gm);
|
||||
|
||||
if (!indents || !indents[0].length)
|
||||
return input;
|
||||
|
||||
indents.sort(function(a, b){return a.length - b.length; });
|
||||
|
||||
if (!indents[0].length)
|
||||
return input;
|
||||
|
||||
return input.replace(RegExp('^' + indents[0], 'gm'), '');
|
||||
},
|
||||
indent: function (input, tabs) {
|
||||
return input.replace(/^[^\S\n\r]*(?=\S)/gm, new Array(++tabs).join('\t') + '$&');
|
||||
},
|
||||
breakLines: function (input, characters) {
|
||||
characters = (characters === true) ? 80 : characters|0 || 80;
|
||||
|
||||
var lines = input.split('\n');
|
||||
for (var i = 0; i < lines.length; ++i) {
|
||||
if (tabLen(lines[i]) <= characters)
|
||||
continue;
|
||||
|
||||
var line = lines[i].split(/(\s+)/g),
|
||||
len = 0;
|
||||
|
||||
for (var j = 0; j < line.length; ++j) {
|
||||
var tl = tabLen(line[j]);
|
||||
len += tl;
|
||||
if (len > characters) {
|
||||
line[j] = '\n' + line[j];
|
||||
len = tl;
|
||||
}
|
||||
}
|
||||
lines[i] = line.join('');
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
};
|
||||
|
||||
// Support node modules
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = NormalizeWhitespace;
|
||||
}
|
||||
|
||||
// Exit if prism is not loaded
|
||||
if (typeof Prism === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
Prism.plugins.NormalizeWhitespace = new NormalizeWhitespace({
|
||||
'remove-trailing': true,
|
||||
'remove-indent': true,
|
||||
'left-trim': true,
|
||||
'right-trim': true,
|
||||
/*'break-lines': 80,
|
||||
'indent': 2,
|
||||
'remove-initial-line-feed': false,
|
||||
'tabs-to-spaces': 4,
|
||||
'spaces-to-tabs': 4*/
|
||||
});
|
||||
|
||||
Prism.hooks.add('before-sanity-check', function (env) {
|
||||
var Normalizer = Prism.plugins.NormalizeWhitespace;
|
||||
|
||||
// Check settings
|
||||
if (env.settings && env.settings['whitespace-normalization'] === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Simple mode if there is no env.element
|
||||
if ((!env.element || !env.element.parentNode) && env.code) {
|
||||
env.code = Normalizer.normalize(env.code, env.settings);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal mode
|
||||
var pre = env.element.parentNode;
|
||||
var clsReg = /\bno-whitespace-normalization\b/;
|
||||
if (!env.code || !pre || pre.nodeName.toLowerCase() !== 'pre' ||
|
||||
clsReg.test(pre.className) || clsReg.test(env.element.className))
|
||||
return;
|
||||
|
||||
var children = pre.childNodes,
|
||||
before = '',
|
||||
after = '',
|
||||
codeFound = false;
|
||||
|
||||
// Move surrounding whitespace from the <pre> tag into the <code> tag
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
var node = children[i];
|
||||
|
||||
if (node == env.element) {
|
||||
codeFound = true;
|
||||
} else if (node.nodeName === "#text") {
|
||||
if (codeFound) {
|
||||
after += node.nodeValue;
|
||||
} else {
|
||||
before += node.nodeValue;
|
||||
}
|
||||
|
||||
pre.removeChild(node);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!env.element.children.length || !Prism.plugins.KeepMarkup) {
|
||||
env.code = before + env.code + after;
|
||||
env.code = Normalizer.normalize(env.code, env.settings);
|
||||
} else {
|
||||
// Preserve markup for keep-markup plugin
|
||||
var html = before + env.element.innerHTML + after;
|
||||
env.element.innerHTML = Normalizer.normalize(html, env.settings);
|
||||
env.code = env.element.textContent;
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
1
docs/_style/prism-master/plugins/normalize-whitespace/prism-normalize-whitespace.min.js
vendored
Normal file
1
docs/_style/prism-master/plugins/normalize-whitespace/prism-normalize-whitespace.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(){function e(e){this.defaults=r({},e)}function n(e){return e.replace(/-(\w)/g,function(e,n){return n.toUpperCase()})}function t(e){for(var n=0,t=0;t<e.length;++t)e.charCodeAt(t)==" ".charCodeAt(0)&&(n+=3);return e.length+n}var r=Object.assign||function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e};e.prototype={setDefaults:function(e){this.defaults=r(this.defaults,e)},normalize:function(e,t){t=r(this.defaults,t);for(var i in t){var o=n(i);"normalize"!==i&&"setDefaults"!==o&&t[i]&&this[o]&&(e=this[o].call(this,e,t[i]))}return e},leftTrim:function(e){return e.replace(/^\s+/,"")},rightTrim:function(e){return e.replace(/\s+$/,"")},tabsToSpaces:function(e,n){return n=0|n||4,e.replace(/\t/g,new Array(++n).join(" "))},spacesToTabs:function(e,n){return n=0|n||4,e.replace(RegExp(" {"+n+"}","g")," ")},removeTrailing:function(e){return e.replace(/\s*?$/gm,"")},removeInitialLineFeed:function(e){return e.replace(/^(?:\r?\n|\r)/,"")},removeIndent:function(e){var n=e.match(/^[^\S\n\r]*(?=\S)/gm);return n&&n[0].length?(n.sort(function(e,n){return e.length-n.length}),n[0].length?e.replace(RegExp("^"+n[0],"gm"),""):e):e},indent:function(e,n){return e.replace(/^[^\S\n\r]*(?=\S)/gm,new Array(++n).join(" ")+"$&")},breakLines:function(e,n){n=n===!0?80:0|n||80;for(var r=e.split("\n"),i=0;i<r.length;++i)if(!(t(r[i])<=n)){for(var o=r[i].split(/(\s+)/g),a=0,s=0;s<o.length;++s){var l=t(o[s]);a+=l,a>n&&(o[s]="\n"+o[s],a=l)}r[i]=o.join("")}return r.join("\n")}},"undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof Prism&&(Prism.plugins.NormalizeWhitespace=new e({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0}),Prism.hooks.add("before-sanity-check",function(e){var n=Prism.plugins.NormalizeWhitespace;if(!e.settings||e.settings["whitespace-normalization"]!==!1){if((!e.element||!e.element.parentNode)&&e.code)return e.code=n.normalize(e.code,e.settings),void 0;var t=e.element.parentNode,r=/\bno-whitespace-normalization\b/;if(e.code&&t&&"pre"===t.nodeName.toLowerCase()&&!r.test(t.className)&&!r.test(e.element.className)){for(var i=t.childNodes,o="",a="",s=!1,l=0;l<i.length;++l){var c=i[l];c==e.element?s=!0:"#text"===c.nodeName&&(s?a+=c.nodeValue:o+=c.nodeValue,t.removeChild(c),--l)}if(e.element.children.length&&Prism.plugins.KeepMarkup){var u=o+e.element.innerHTML+a;e.element.innerHTML=n.normalize(u,e.settings),e.code=e.element.textContent}else e.code=o+e.code+a,e.code=n.normalize(e.code,e.settings)}}}))}();
|
Reference in New Issue
Block a user