Commit 29760d7742871d1e7fd31f249f15fde6d9e315f0

Golmote 2015-09-14T07:58:28

Add pages for previewer base and previewer color plugins

diff --git a/components.js b/components.js
index 987483f..46c2fae 100644
--- a/components.js
+++ b/components.js
@@ -480,11 +480,11 @@ var components = {
 			"noCSS": true
 		},
 		"previewer-base": {
-			"title": "Previewer Base",
+			"title": "Previewer: Base",
 			"owner": "Golmote"
 		},
 		"previewer-color": {
-			"title": "Previewer Color",
+			"title": "Previewer: Color",
 			"require": "previewer-base",
 			"owner": "Golmote"
 		}
diff --git a/plugins/previewer-base/index.html b/plugins/previewer-base/index.html
new file mode 100644
index 0000000..7a7c96b
--- /dev/null
+++ b/plugins/previewer-base/index.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+
+	<meta charset="utf-8" />
+	<link rel="shortcut icon" href="favicon.png" />
+	<title>Previewer: Base ▲ Prism plugins</title>
+	<base href="../.." />
+	<link rel="stylesheet" href="style.css" />
+	<link rel="stylesheet" href="themes/prism.css" data-noprefix />
+	<link rel="stylesheet" href="plugins/previewer-base/prism-previewer-base.css" data-noprefix />
+
+	<style type="text/css">
+		.prism-previewer-color {
+			background-image: linear-gradient(45deg, #bbb 25%, transparent 25%, transparent 75%, #bbb 75%, #bbb), linear-gradient(45deg, #bbb 25%, #eee 25%, #eee 75%, #bbb 75%, #bbb);
+			background-size: 10px 10px;
+			background-position: 0 0, 5px 5px;
+		}
+		.prism-previewer-color:before {
+			background-color: inherit;
+			background-clip: padding-box;
+		}
+	</style>
+
+	<script src="prefixfree.min.js"></script>
+
+	<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
+	<script src="http://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>Previewer: Base</h2>
+	<p>Provides an API to add previewers.</p>
+</header>
+
+<section class="language-javascript">
+	<h1>How to use</h1>
+
+	<p>This plugins provides a constructor that can be accessed through <code>Prism.plugins.Previewer</code>.</p>
+	<p>Once a previewer has been instanciated, an HTML element is appended to the document body.
+	This element will appear when specific tokens are hovered.</p>
+
+	<h2><code>new Prism.plugins.Previewer(type, updater, supportedLanguages)</code></h2>
+
+	<ul>
+		<li>
+			<p><code>type</code>: the token type this previewer is associated to.
+			The previewer will be shown when hovering tokens of this type.</p>
+		</li>
+		<li>
+			<p><code>updater</code>: the function that will be called each time an associated token is hovered.
+			This function takes the text content of the token as its only parameter.
+			The previewer HTML element can be accessed through the keyword <code>this</code>.
+			This function must return <code>true</code> for the previewer to be shown.</p>
+		</li>
+		<li>
+			<p><code>supportedLanguages</code>: an optional array of supported languages.
+			The previewer will be available only for those.
+			Defaults to <code>'*'</code>, which means every languages.</p>
+		</li>
+	</ul>
+
+</section>
+
+<section class="language-javascript">
+	<h1>Examples</h1>
+
+	<p>This is a simplified version of the <a href="plugins/previewer-color">color previewer plugin</a>.</p>
+
+	<h2>Implementing a previewer for hexadecimal CSS colors</h2>
+	<p>First, you need to add specific tokens to the grammar. For hexadecimal CSS colors, it might look like this:</p>
+	<pre><code>Prism.languages.insertBefore('css', 'important', {
+	'color': /\B#(?:[0-9a-f]{3}){1,2}\b/i
+});</code></pre>
+
+	<p>Then, the previewer can be instanciated. The updater function will set the background color of the previewer HTML element, based of the hovered token.</p>
+
+	<pre><code>new Prism.plugins.Previewer('color', function(value) {
+	// Reset the background color
+	this.style.backgroundColor = '';
+	// Set the background color to the value of the current hovered token
+	this.style.backgroundColor = value;
+	// Returns true if the color is valid, false otherwise
+	return !!this.style.backgroundColor;
+}, 'css');</code></pre>
+
+	<p>Now, with a bit of CSS to style the previewer, the result would be something like this:</p>
+
+	<pre class="language-css"><code>div {
+	color: #dd4a68;
+	background: #669900;
+	border: 1px solid #ee9900;
+}</code></pre>
+
+</section>
+
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
+
+<script src="prism.js"></script>
+<script src="plugins/previewer-base/prism-previewer-base.js"></script>
+<script src="utopia.js"></script>
+<script src="components.js"></script>
+<script src="code.js"></script>
+
+<script>
+	Prism.languages.insertBefore('css', 'important', {
+		'color': /\B#(?:[0-9a-f]{3}){1,2}\b/i
+	});
+	new Prism.plugins.Previewer('color', function(value) {
+		// Reset the background color
+		this.style.backgroundColor = '';
+		// Set the background color to the value of the current hovered token
+		this.style.backgroundColor = value;
+		// Returns true if the color is valid, false otherwise
+		return !!this.style.backgroundColor;
+	}, 'css');
+</script>
+
+
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/previewer-color/index.html b/plugins/previewer-color/index.html
new file mode 100644
index 0000000..ca84757
--- /dev/null
+++ b/plugins/previewer-color/index.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+
+	<meta charset="utf-8" />
+	<link rel="shortcut icon" href="favicon.png" />
+	<title>Previewer: Color ▲ Prism plugins</title>
+	<base href="../.." />
+	<link rel="stylesheet" href="style.css" />
+	<link rel="stylesheet" href="themes/prism.css" data-noprefix />
+	<link rel="stylesheet" href="plugins/previewer-base/prism-previewer-base.css" data-noprefix />
+	<link rel="stylesheet" href="plugins/previewer-color/prism-previewer-color.css" data-noprefix />
+	<script src="prefixfree.min.js"></script>
+
+	<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
+	<script src="http://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>Previewer: Color</h2>
+	<p>Previewer for CSS colors.</p>
+</header>
+
+<section class="language-markup">
+	<h1>How to use</h1>
+
+	<p>You don't need to do anything. With this plugin loaded, a previewer will appear on hovering the color values in code blocks.</p>
+	<p>This plugin is compatible with CSS, Markup attributes, Less, Sass, Scss and Stylus.</p>
+</section>
+
+<section>
+	<h1>Examples</h1>
+
+	<h2>CSS</h2>
+	<pre class="language-css"><code>div {
+	color: rgba(255, 0, 0, 0.2);
+	background: purple;
+	border: 1px solid hsl(100,70%,40%);
+}</code></pre>
+
+	<h2>Markup attributes</h2>
+	<pre class="language-markup"><code>&lt;table bgcolor="#6E5494">
+&lt;tr style="background: lightblue;"></code></pre>
+
+	<h2>Less</h2>
+	<pre class="language-less"><code>@nice-blue: #5B83AD;
+#header a {
+	color: hsla(102, 53%, 42%, 0.4);
+}</code></pre>
+
+	<h2>Sass</h2>
+	<pre class="language-sass"><code>@mixin foobar
+    color: rgba(147, 32, 34, 0.8)
+.foo
+    color: pink
+</code></pre>
+
+	<h2>Scss</h2>
+	<pre class="language-scss"><code>$color: blue;
+$attr = background;
+.foo {
+    #{$attr}-color: rgba(255,255,0,0.75);
+}</code></pre>
+
+	<h2>Stylus</h2>
+	<pre class="language-stylus"><code>color = olive
+.foo
+	color: #000
+</code></pre>
+
+</section>
+
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
+
+<script src="prism.js"></script>
+<script src="components/prism-less.js"></script>
+<script src="components/prism-sass.js"></script>
+<script src="components/prism-scss.js"></script>
+<script src="components/prism-stylus.js"></script>
+<script src="plugins/previewer-base/prism-previewer-base.js"></script>
+<script src="plugins/previewer-color/prism-previewer-color.js"></script>
+<script src="utopia.js"></script>
+<script src="components.js"></script>
+<script src="code.js"></script>
+
+
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/previewer-color/prism-previewer-color.js b/plugins/previewer-color/prism-previewer-color.js
index 17a9a80..6844621 100644
--- a/plugins/previewer-color/prism-previewer-color.js
+++ b/plugins/previewer-color/prism-previewer-color.js
@@ -50,7 +50,7 @@
 		}
 		if(!skip && Prism.languages[lang]) {
 			Prism.languages.insertBefore(inside, before, {
-				'color': /(?:\B#(?:[0-9a-f]{3}){1,2}\b|\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B|\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b)/i
+				'color': /\B#(?:[0-9a-f]{3}){1,2}\b|\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B|\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i
 			}, root);
 		}
 	});
diff --git a/plugins/previewer-color/prism-previewer-color.min.js b/plugins/previewer-color/prism-previewer-color.min.js
index 5ebe626..7c45a0d 100644
--- a/plugins/previewer-color/prism-previewer-color.min.js
+++ b/plugins/previewer-color/prism-previewer-color.min.js
@@ -1 +1 @@
-!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var e=["css","less",{lang:"markup",before:"punctuation",inside:"inside",root:Prism.languages.markup&&Prism.languages.markup.tag.inside["attr-value"]},{lang:"sass",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["property-line"]},"scss",{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["property-declaration"].inside},{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["variable-declaration"].inside}];e.forEach(function(e){var a,r,i,l;"string"==typeof e?(a="important",r=e):(a=e.before||"important",r=e.inside||e.lang,i=e.root||Prism.languages,l=e.skip,e=e.lang),!l&&Prism.languages[e]&&Prism.languages.insertBefore(r,a,{color:/(?:\B#(?:[0-9a-f]{3}){1,2}\b|\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B|\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b)/i},i)}),Prism.plugins.Previewer&&new Prism.plugins.Previewer("color",function(e){return this.style.backgroundColor="",this.style.backgroundColor=e,!!this.style.backgroundColor})}}();
\ No newline at end of file
+!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var e=["css","less",{lang:"markup",before:"punctuation",inside:"inside",root:Prism.languages.markup&&Prism.languages.markup.tag.inside["attr-value"]},{lang:"sass",inside:"inside",root:Prism.languages.sass&&Prism.languages.sass["property-line"]},"scss",{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["property-declaration"].inside},{lang:"stylus",before:"hexcode",inside:"rest",root:Prism.languages.stylus&&Prism.languages.stylus["variable-declaration"].inside}];e.forEach(function(e){var a,r,i,l;"string"==typeof e?(a="important",r=e):(a=e.before||"important",r=e.inside||e.lang,i=e.root||Prism.languages,l=e.skip,e=e.lang),!l&&Prism.languages[e]&&Prism.languages.insertBefore(r,a,{color:/\B#(?:[0-9a-f]{3}){1,2}\b|\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B|\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gray|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i},i)}),Prism.plugins.Previewer&&new Prism.plugins.Previewer("color",function(e){return this.style.backgroundColor="",this.style.backgroundColor=e,!!this.style.backgroundColor})}}();
\ No newline at end of file