Commit 483831ee6d5b1ef99e2b4030f0c6c45a710d7d92

Lea Verou 2012-07-30T18:27:16

Autolinker plugin

diff --git a/code.js b/code.js
index 4f9c39e..2f4cc2f 100644
--- a/code.js
+++ b/code.js
@@ -165,7 +165,8 @@ var components = {
 			hasCSS: true
 		},
 		'line-highlight': 'Line Highlight',
-		'show-invisibles': 'Show Invisibles'
+		'show-invisibles': 'Show Invisibles',
+		'autolinker': 'Autolinker'
 	}
 };
 
diff --git a/download.html b/download.html
index 4088790..d82fd58 100644
--- a/download.html
+++ b/download.html
@@ -101,7 +101,7 @@ section.download {
 		<p>
 			Total filesize: <strong id="filesize"></strong> (<strong id="percent-js"></strong> JavaScript + <strong id="percent-css"></strong> CSS)
 		</p>
-		<p><strong>Note:</strong> The filesizes displayed refer to non-gizipped files and include any CSS code required.</p>
+		<p><strong>Note:</strong> The filesizes displayed refer to non-gizipped files and include any CSS code required. The CSS code is not minified.</p>
 		
 		<section id="download">
 			<section id="download-js" class="download">
diff --git a/plugins/autolinker/index.html b/plugins/autolinker/index.html
new file mode 100644
index 0000000..430b0aa
--- /dev/null
+++ b/plugins/autolinker/index.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en" class="simple">
+<head>
+
+<meta charset="utf-8" />
+<title>Show Invisibles ▲ Prism plugins</title>
+<base href="../.." />
+<link rel="stylesheet" href="style.css" />
+<link rel="stylesheet" href="prism.css" data-noprefix />
+<link rel="stylesheet" href="plugins/autolinker/prism-autolinker.css" data-noprefix />
+<script src="../prefixfree/prefixfree.min.js"></script>
+
+</head>
+<body>
+
+<header>
+	<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div>
+
+	<h2>Autolinker</h2>
+	<p>Converts URLs and emails in code to clickable links</p>
+</header>
+
+<section>
+	<h1>Examples</h1>
+	
+	<pre><code class="language-javascript">/**
+ * Prism: Lightweight, robust, elegant syntax highlighting
+ * MIT license http://www.opensource.org/licenses/mit-license.php/
+ * @author Lea Verou http://lea.verou.me 
+ * Reach Lea at fake@email.com (no, not really)
+ */
+var foo = 5;
+// And a single line comment http://google.com</code></pre>
+ 	
+ 	<pre><code class="language-css">@font-face {
+	src: url(http://lea.verou.me/logo.otf);
+	font-family: 'LeaVerou';
+}</code></pre>
+</section>
+
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
+
+<script src="prism.js"></script>
+<script src="plugins/autolinker/prism-autolinker.js"></script>
+<script src="utopia.js"></script>
+<script src="code.js"></script>
+
+
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/autolinker/prism-autolinker.css b/plugins/autolinker/prism-autolinker.css
new file mode 100644
index 0000000..b5f7630
--- /dev/null
+++ b/plugins/autolinker/prism-autolinker.css
@@ -0,0 +1,3 @@
+.token a {
+	color: inherit;
+}
\ No newline at end of file
diff --git a/plugins/autolinker/prism-autolinker.js b/plugins/autolinker/prism-autolinker.js
new file mode 100644
index 0000000..71f23eb
--- /dev/null
+++ b/plugins/autolinker/prism-autolinker.js
@@ -0,0 +1,19 @@
+(function(){
+
+if (!window.Prism) {
+	return;
+}
+
+var url = /\b([a-z]{3,7}:\/\/|tel:)\S+/g,
+    email = /\b\S+@[\w.]+[a-z]{2}/g,
+    candidates = ['comment', 'line-comment', 'url'];
+
+Prism.hooks.add('wrap', function(env) {
+	if (candidates.indexOf(env.type) > -1) {
+		env.content = env.content
+			.replace(url, '<a href="$&">$&</a>')
+			.replace(email, '<a href="mailto:$&">$&</a>')
+	}
+});
+
+})();
\ No newline at end of file
diff --git a/plugins/autolinker/prism-autolinker.min.js b/plugins/autolinker/prism-autolinker.min.js
new file mode 100644
index 0000000..5e43fd3
--- /dev/null
+++ b/plugins/autolinker/prism-autolinker.min.js
@@ -0,0 +1 @@
+(function(){if(!window.Prism)return;var e=/\b([a-z]{3,7}:\/\/|tel:)\S+/g,t=/\b\S+@[\w.]+[a-z]{2}/g,n=["comment","line-comment","url"];Prism.hooks.add("wrap",function(r){n.indexOf(r.type)>-1&&(r.content=r.content.replace(e,'<a href="$&">$&</a>').replace(t,'<a href="mailto:$&">$&</a>'))})})();
\ No newline at end of file
diff --git a/prism-funky.css b/prism-funky.css
index 4120132..693d663 100644
--- a/prism-funky.css
+++ b/prism-funky.css
@@ -30,7 +30,6 @@ pre[class*="language-"] {
 	overflow: auto;
 	background: url('data:image/svg+xml;charset=utf-8,<svg%20version%3D"1.1"%20xmlns%3D"http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg"%20width%3D"100"%20height%3D"100"%20fill%3D"rgba(0%2C0%2C0%2C.2)">%0D%0A<polygon%20points%3D"0%2C50%2050%2C0%200%2C0"%20%2F>%0D%0A<polygon%20points%3D"0%2C100%2050%2C100%20100%2C50%20100%2C0"%20%2F>%0D%0A<%2Fsvg>');
 	background-size: 1em 1em;
-	line-height: 1.4;
 }
 
 code[class*="language-"] {