Commit 6e555bc047b7ccfffd842e0da014c2bda162f533

Martin Hasoň 2015-03-03T23:29:32

Added YAML highlighter

diff --git a/components.js b/components.js
index 2ae508f..7be1869 100644
--- a/components.js
+++ b/components.js
@@ -326,6 +326,10 @@ var components = {
 			"title": "Wiki markup",
 			"require": "markup",
 			"owner": "Golmote"
+		},
+		"yaml": {
+			"title": "YAML",
+			"owner": "hason"
 		}
 	},
 	"plugins": {
diff --git a/components/prism-yaml.js b/components/prism-yaml.js
new file mode 100644
index 0000000..6b45e8a
--- /dev/null
+++ b/components/prism-yaml.js
@@ -0,0 +1,44 @@
+Prism.languages.yaml = {
+	'scalar': {
+		pattern: /([\-:]\s*(![^\s]+)?[ \t]*[|>])[ \t]*(?:(\n[ \t]+)[^\r\n]+(?:\3[^\r\n]+)*)/,
+		lookbehind: true,
+		alias: 'string'
+	},
+	'comment': /#[^\n]+/,
+	'key': {
+		pattern: /(\s*[:\-,[{\n?][ \t]*(![^\s]+)?[ \t]*)[^\n{[\]},#]+?(?=\s*:\s)/,
+		lookbehind: true,
+		alias: 'atrule'
+	},
+	'directive': {
+		pattern: /((^|\n)[ \t]*)%[^\n]+/,
+		lookbehind: true,
+		alias: 'important'
+	},
+	'datetime': {
+		pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(\d{4}-\d\d?-\d\d?([tT]|[ \t]+)\d\d?:\d{2}:\d{2}(\.\d*)?[ \t]*(Z|[-+]\d\d?(:\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(:\d{2}(\.\d*)?)?)(?=[ \t]*(\n|$|,|]|}))/,
+		lookbehind: true,
+		alias: 'number'
+	},
+	'boolean': {
+		pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(true|false)[ \t]*(?=\n|$|,|]|})/i,
+		lookbehind: true,
+		alias: 'important'
+	},
+	'null': {
+		pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(null|~)[ \t]*(?=\n|$|,|]|})/i,
+		lookbehind: true,
+		alias: 'important'
+	},
+	'string': {
+		pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')(?=[ \t]*(\n|$|,|]|}))/,
+		lookbehind: true
+	},
+	'number': {
+		pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)[+\-]?(0x[\dA-Fa-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)[ \t]*(?=\n|$|,|]|})/i,
+		lookbehind: true
+	},
+	'tag': /![^\s]+/,
+	'important': /[&*][\w]+/,
+	'punctuation': /([:[\]{}\-,|>?]|---|\.\.\.)/
+};
diff --git a/components/prism-yaml.min.js b/components/prism-yaml.min.js
new file mode 100644
index 0000000..2fd09f7
--- /dev/null
+++ b/components/prism-yaml.min.js
@@ -0,0 +1 @@
+Prism.languages.yaml={scalar:{pattern:/([\-:]\s*(![^\s]+)?[ \t]*[|>])[ \t]*(?:(\n[ \t]+)[^\r\n]+(?:\3[^\r\n]+)*)/,lookbehind:!0,alias:"string"},comment:/#[^\n]+/,key:{pattern:/(\s*[:\-,[{\n?][ \t]*(![^\s]+)?[ \t]*)[^\n{[\]},#]+?(?=\s*:\s)/,lookbehind:!0,alias:"atrule"},directive:{pattern:/((^|\n)[ \t]*)%[^\n]+/,lookbehind:!0,alias:"important"},datetime:{pattern:/([:\-,[{]\s*(![^\s]+)?[ \t]*)(\d{4}-\d\d?-\d\d?([tT]|[ \t]+)\d\d?:\d{2}:\d{2}(\.\d*)?[ \t]*(Z|[-+]\d\d?(:\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(:\d{2}(\.\d*)?)?)(?=[ \t]*(\n|$|,|]|}))/,lookbehind:!0,alias:"number"},"boolean":{pattern:/([:\-,[{]\s*(![^\s]+)?[ \t]*)(true|false)[ \t]*(?=\n|$|,|]|})/i,lookbehind:!0,alias:"important"},"null":{pattern:/([:\-,[{]\s*(![^\s]+)?[ \t]*)(null|~)[ \t]*(?=\n|$|,|]|})/i,lookbehind:!0,alias:"important"},string:{pattern:/([:\-,[{]\s*(![^\s]+)?[ \t]*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')(?=[ \t]*(\n|$|,|]|}))/,lookbehind:!0},number:{pattern:/([:\-,[{]\s*(![^\s]+)?[ \t]*)[+\-]?(0x[\dA-Fa-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)[ \t]*(?=\n|$|,|]|})/i,lookbehind:!0},tag:/![^\s]+/,important:/[&*][\w]+/,punctuation:/([:[\]{}\-,|>?]|---|\.\.\.)/};
\ No newline at end of file
diff --git a/examples/prism-yaml.html b/examples/prism-yaml.html
new file mode 100644
index 0000000..14cc5bd
--- /dev/null
+++ b/examples/prism-yaml.html
@@ -0,0 +1,110 @@
+<h1>YAML</h1>
+<p>To use this language, use the class "language-yaml".</p>
+
+<h2>Null and Boolean</h2>
+<pre><code>---
+A null: null
+A null: ~
+Also a null: # Empty
+Not a null: ""
+Booleans: [ true, True, false, FALSE ]
+</code></pre>
+
+<h2>Numbers and timestamps</h2>
+<pre><code>---
+Integers: [ 0, -0, 3, 0o7, 0x3A, -19 ]
+Floats: [ 0., -0.0, .5, 12e03, +12e03, -2E+05 ]
+Also floats: [ .inf, -.Inf, +.INF, .NAN ]
+Timestamps:
+  canonical: 2001-12-15T02:59:43.1Z
+  iso8601: 2001-12-14t21:59:43.10-05:00
+  spaced: 2001-12-14 21:59:43.10 -5
+  date: 2002-12-14
+  times:
+    - 10:53
+    - 10:53:20.53
+</code></pre>
+
+<h2>Strings</h2>
+<pre><code>---
+product: High Heeled "Ruby" Slippers
+description: "Putting on these \"slippers\" is easy."
+address:
+  city:   East Centerville
+  street: !!str |
+    123 Tornado Alley
+    Suite 16
+
+  specialDelivery:  >
+    Follow the Yellow Brick
+    Road to the Emerald City.
+    #Pay no attention to the
+    man behind the curtain.
+</code></pre>
+
+<h2>Sequences and maps</h2>
+<pre><code>---
+- Casablanca
+- North by Northwest
+- {
+    name: John Smith, age: 33}
+- name: Mary Smith
+  age: 27
+---
+"name": John Smith
+age: 33
+men: [ John Smith,
+    "Bill Jones" ]
+women:
+ - Mary Smith
+ - "Susan Williams"
+</code></pre>
+
+<h2>Tags</h2>
+<pre><code>---
+!!map {
+  ? !!str friends: !!seq [
+    !!map {
+      ? !!str "age"
+      : !!int 33,
+      ? !!str "name"
+      : !!str "John Smith",
+    }
+  ],
+  men:
+    [ !!str "John Smith", !!str "Bill Jones"]
+}
+</code></pre>
+
+<h2>Full example</h2>
+<pre><code>%YAML 1.2
+--- !&lt;tag:clarkevans.com,2002:invoice&gt;
+invoice: 34843
+date   : 2001-01-23
+bill-to: &id001
+  given  : Chris
+  family : Dumars
+  address:
+    lines: |
+      458 Walkman Dr.
+      Suite #292
+    city    : Royal Oak
+    state   : MI
+    postal  : 48046
+ship-to:
+  <<: *id001
+  product:
+    - sku         : BL394D
+      quantity    : 4
+      description : Basketball
+      price       : 450.00
+    - sku         : BL4438H
+      quantity    : 1
+      description : Super Hoop
+      price       : 2392.00
+tax  : 251.42
+total: 4443.52
+comments:
+    Late afternoon is best.
+    Backup contact is Nancy
+</code></pre>