Commit eaf8ac0c61830de62f4acb2c021f520d0dea2ab8

Golmote 2015-01-07T19:48:29

Improved Markdown + added example

diff --git a/components/prism-markdown.js b/components/prism-markdown.js
index 6f89eeb..f58bcc5 100644
--- a/components/prism-markdown.js
+++ b/components/prism-markdown.js
@@ -3,7 +3,7 @@ Prism.languages.markdown = Prism.languages.extend('markup', {
 		// > ...
 		pattern: /(^|\n)>(?:[\t ]*>)*/,
 		lookbehind: true,
-		alias: 'operator'
+		alias: 'punctuation'
 	},
 	'code': [
 		{
@@ -27,14 +27,20 @@ Prism.languages.markdown = Prism.languages.extend('markup', {
 			// title 2
 			// -------
 			pattern: /\w+.*\n(?:==+|--+)/,
-			alias: 'important'
+			alias: 'important',
+			inside: {
+				punctuation: /==+$|--+$/
+			}
 		},
 		{
 			// # title 1
 			// ###### title 6
 			pattern: /((?:^|\n)\s*)#+.+/,
 			lookbehind: true,
-			alias: 'important'
+			alias: 'important',
+			inside: {
+				punctuation: /^#+|#+$/
+			}
 		}
 	],
 	'hr': {
@@ -42,7 +48,8 @@ Prism.languages.markdown = Prism.languages.extend('markup', {
 		// ---
 		// * * *
 		// -----------
-		pattern: /([*-])([\t ]*\1){2,}/,
+		pattern: /((?:^|\n)\s*)([*-])([\t ]*\2){2,}(?=\s*(?:\n|$))/,
+		lookbehind: true,
 		alias: 'punctuation'
 	},
 	'list': {
@@ -50,55 +57,64 @@ Prism.languages.markdown = Prism.languages.extend('markup', {
 		// + item
 		// - item
 		// 1. item
-		pattern: /(?:[*+-]|\d+\.)(?=[\t ].)/,
-		alias: 'operator'
+		pattern: /((?:^|\n)\s*)(?:[*+-]|\d+\.)(?=[\t ].)/,
+		lookbehind: true,
+		alias: 'punctuation'
 	},
-	'link-reference': {
+	'url-reference': {
 		// [id]: http://example.com "Optional title"
 		// [id]: http://example.com 'Optional title'
 		// [id]: http://example.com (Optional title)
 		// [id]: <http://example.com> "Optional title"
 		pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:[^>]|\\>)+>)(?:[\t ]+(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\)))?/,
-		alias: 'symbol namespace'
-	},
-	'link': [
-		{
-			// [example](http://example.com "Optional title")
-			pattern: /!?\[[^\]]+\]\([^\s)]+(?:[\t ]+"(?:[^"]|\\")*")?\)/,
-			alias: 'symbol'
+		inside: {
+			'variable': {
+				pattern: /^(!?\[)[^\]]+/,
+				lookbehind: true
+			},
+			'string': /(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\))$/,
+			'punctuation': /[[\]\(\)<>:]/
 		},
-		{
-			// [example] [id]
-			pattern: /!?\[[^\]]+\] ?\[[^\]\n]*\]/,
-			alias: 'symbol'
+		alias: 'url'
+	},
+	'url': {
+		// [example](http://example.com "Optional title")
+		// [example] [id]
+		pattern: /!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:[^"]|\\")*")?\)| ?\[[^\]\n]*\])/,
+		inside: {
+			'variable': {
+				pattern: /(!?\[)[^\]]+(?=\]$)/,
+				lookbehind: true
+			},
+			'string': {
+				pattern: /"(?:[^"]|\\")*"(?=\)$)/
+			}
 		}
-	],
-	'strong': [
+	},
+	'bold': [
 		{
 			// **strong**
 			// __strong__
-			pattern: /(^|[^\\])\*\*[\s\S]+?\*\*/,
-			lookbehind: true,
-			alias: 'string'
-		},
-		{
-			pattern: /(^|[^\\])__[\s\S]+?__/,
+
+			// Allow only one line break
+			pattern: /(^|[^\\])(\*\*|__)(?:\n(?!\n)|.)+?\2/,
 			lookbehind: true,
-			alias: 'string'
+			inside: {
+				'punctuation': /^\*\*|^__|\*\*\s*$|__\s*$/
+			}
 		}
 	],
-	'em': [
+	'italic': [
 		{
 			// *em*
-			pattern: /(^|[^\\])\*[^*\t ][^*]*\*/,
-			lookbehind: true,
-			alias: 'string'
-		},
-		{
 			// _em_
-			pattern: /(^|[^\\])_[^_]+_/,
+
+			// Allow only one line break
+			pattern: /(^|[^\\])(?:\*(?:\n(?!\n)|.)+?\*|_(?:\n(?!\n)|.)+?_)/,
 			lookbehind: true,
-			alias: 'string'
+			inside: {
+				'punctuation': /^[*_]|[*_]$/
+			}
 		}
 	]
 });
\ No newline at end of file
diff --git a/components/prism-markdown.min.js b/components/prism-markdown.min.js
index ff36a05..c0ea219 100644
--- a/components/prism-markdown.min.js
+++ b/components/prism-markdown.min.js
@@ -1 +1 @@
-Prism.languages.markdown=Prism.languages.extend("markup",{blockquote:{pattern:/(^|\n)>(?:[\t ]*>)*/,lookbehind:!0,alias:"operator"},code:[{pattern:/(^|\n)(?: {4}|\t).+/,lookbehind:!0,alias:"keyword"},{pattern:/``.+?``|`[^`\n]+`/,alias:"keyword"}],title:[{pattern:/\w+.*\n(?:==+|--+)/,alias:"important"},{pattern:/((?:^|\n)\s*)#+.+/,lookbehind:!0,alias:"important"}],hr:{pattern:/([*-])([\t ]*\1){2,}/,alias:"punctuation"},list:{pattern:/(?:[*+-]|\d+\.)(?=[\t ].)/,alias:"operator"},"link-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:[^>]|\\>)+>)(?:[\t ]+(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\)))?/,alias:"symbol namespace"},link:[{pattern:/!?\[[^\]]+\]\([^\s)]+(?:[\t ]+"(?:[^"]|\\")*")?\)/,alias:"symbol"},{pattern:/!?\[[^\]]+\] ?\[[^\]\n]*\]/,alias:"symbol"}],strong:[{pattern:/(^|[^\\])\*\*[\s\S]+?\*\*/,lookbehind:!0,alias:"string"},{pattern:/(^|[^\\])__[\s\S]+?__/,lookbehind:!0,alias:"string"}],em:[{pattern:/(^|[^\\])\*[^*\t ][^*]*\*/,lookbehind:!0,alias:"string"},{pattern:/(^|[^\\])_[^_]+_/,lookbehind:!0,alias:"string"}]});
\ No newline at end of file
+Prism.languages.markdown=Prism.languages.extend("markup",{blockquote:{pattern:/(^|\n)>(?:[\t ]*>)*/,lookbehind:!0,alias:"punctuation"},code:[{pattern:/(^|\n)(?: {4}|\t).+/,lookbehind:!0,alias:"keyword"},{pattern:/``.+?``|`[^`\n]+`/,alias:"keyword"}],title:[{pattern:/\w+.*\n(?:==+|--+)/,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/((?:^|\n)\s*)#+.+/,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/((?:^|\n)\s*)([*-])([\t ]*\2){2,}(?=\s*(?:\n|$))/,lookbehind:!0,alias:"punctuation"},list:{pattern:/((?:^|\n)\s*)(?:[*+-]|\d+\.)(?=[\t ].)/,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:[^>]|\\>)+>)(?:[\t ]+(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:[^"]|\\")*"|'(?:[^']|\\')*'|\((?:[^)]|\\\))*\))$/,punctuation:/[[\]\(\)<>:]/},alias:"url"},url:{pattern:/!?\[[^\]]+\](?:\([^\s)]+(?:[\t ]+"(?:[^"]|\\")*")?\)| ?\[[^\]\n]*\])/,inside:{variable:{pattern:/(!?\[)[^\]]+(?=\]$)/,lookbehind:!0},string:{pattern:/"(?:[^"]|\\")*"(?=\)$)/}}},bold:[{pattern:/(^|[^\\])(\*\*|__)(?:\n(?!\n)|.)+?\2/,lookbehind:!0,inside:{punctuation:/^\*\*|^__|\*\*\s*$|__\s*$/}}],italic:[{pattern:/(^|[^\\])(?:\*(?:\n(?!\n)|.)+?\*|_(?:\n(?!\n)|.)+?_)/,lookbehind:!0,inside:{punctuation:/^[*_]|[*_]$/}}]});
\ No newline at end of file
diff --git a/examples/prism-markdown.html b/examples/prism-markdown.html
new file mode 100644
index 0000000..ac013b3
--- /dev/null
+++ b/examples/prism-markdown.html
@@ -0,0 +1,72 @@
+<h1>Markdown</h1>
+<p>To use this language, use the class "language-markdown".</p>
+
+<h2>Titles</h2>
+<pre><code>Title 1
+==
+
+Title 2
+-------
+
+# Title 1
+## Title 2
+### Title 3
+#### Title 4
+##### Title 5
+###### Title 6
+</code></pre>
+
+<h2>Bold and italic</h2>
+<pre><code>* Italic *
+** Bold on
+multiple lines **
+* Italic on
+multiple lines too *
+__ It also works with underscores __
+_ It also works with underscores _
+
+__ An empty line
+
+is not allowed __
+</code></pre>
+
+<h2>Links</h2>
+<pre><code>[Prism](http://www.prismjs.com)
+[Prism](http://www.prismjs.com "Prism")
+
+[prism link]: http://www.prismjs.com (Prism)
+[Prism] [prism link]
+</code></pre>
+
+<h2>Lists and quotes</h2>
+<pre><code>* This is
+* an unordered list
+
+1. This is an
+2. ordered list
+
+* *List item in italic*
+* **List item in bold**
+* [List item as a link](http://example.com "This is an example")
+
+> This is a quotation
+>> With another quotation inside
+> _italic here_, __bold there__
+> And a [link](http://example.com)
+</code></pre>
+
+<h2>Known failures</h2>
+<p>There are certain edge cases where Prism will fail.
+	There are always such cases in every regex-based syntax highlighter.
+	However, Prism dares to be open and honest about them.
+	If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
+</p>
+
+<h3>Nested elements</h3>
+<pre><code>_ **bold** inside italic _
+
+__ *italic* inside bold __
+
+__ [Bold link?](http://example.com) __
+
+[Link in *italic*](http://example.com)</code></pre>
\ No newline at end of file
diff --git a/themes/prism-coy.css b/themes/prism-coy.css
index f8954bb..831d03f 100644
--- a/themes/prism-coy.css
+++ b/themes/prism-coy.css
@@ -170,6 +170,13 @@ pre[class*="language-"]:after {
 	font-weight: normal;
 }
 
+.token.bold {
+	font-weight: bold;
+}
+.token.italic {
+	font-style: italic;
+}
+
 .token.entity {
 	cursor: help;
 }
diff --git a/themes/prism-dark.css b/themes/prism-dark.css
index 5cabfa7..a8047fc 100644
--- a/themes/prism-dark.css
+++ b/themes/prism-dark.css
@@ -109,9 +109,13 @@ pre[class*="language-"] {
 	color: #e90;
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;
diff --git a/themes/prism-funky.css b/themes/prism-funky.css
index d213825..f2614d1 100644
--- a/themes/prism-funky.css
+++ b/themes/prism-funky.css
@@ -98,9 +98,13 @@ code[class*="language-"] {
 	color: orange;
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;
diff --git a/themes/prism-okaidia.css b/themes/prism-okaidia.css
index 8be4b0b..d64cde3 100644
--- a/themes/prism-okaidia.css
+++ b/themes/prism-okaidia.css
@@ -105,9 +105,13 @@ pre[class*="language-"] {
 	color: #fd971f;
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;
diff --git a/themes/prism-tomorrow.css b/themes/prism-tomorrow.css
index e41de8d..c998fb2 100644
--- a/themes/prism-tomorrow.css
+++ b/themes/prism-tomorrow.css
@@ -102,9 +102,13 @@ pre[class*="language-"] {
 	color: #67cdcc;
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;
diff --git a/themes/prism-twilight.css b/themes/prism-twilight.css
index aa7b901..89dbe84 100644
--- a/themes/prism-twilight.css
+++ b/themes/prism-twilight.css
@@ -125,9 +125,13 @@ code[class*="language-"]::selection, code[class*="language-"] ::selection {
 	color: hsl(42, 75%, 65%); /* #E9C062 */
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;
diff --git a/themes/prism.css b/themes/prism.css
index 3a9a1e6..a04c82c 100644
--- a/themes/prism.css
+++ b/themes/prism.css
@@ -122,9 +122,13 @@ pre[class*="language-"] {
 	color: #e90;
 }
 
-.token.important {
+.token.important,
+.token.bold {
 	font-weight: bold;
 }
+.token.italic {
+	font-style: italic;
+}
 
 .token.entity {
 	cursor: help;