Added more examples & small TOML improvement (#1917) This adds some of the missing examples and makes a small improvement to TOML.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
diff --git a/components/prism-toml.js b/components/prism-toml.js
index 200fbdd..e911d89 100644
--- a/components/prism-toml.js
+++ b/components/prism-toml.js
@@ -9,7 +9,7 @@
greedy: true
},
'table': {
- pattern: RegExp("(\\[\\s*)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*\\])"),
+ pattern: RegExp("(^\\s*\\[\\s*(?:\\[\\s*)?)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*\\])", "m"),
lookbehind: true,
greedy: true,
alias: 'class-name'
diff --git a/components/prism-toml.min.js b/components/prism-toml.min.js
index 2ce58e9..f0ffbd4 100644
--- a/components/prism-toml.min.js
+++ b/components/prism-toml.min.js
@@ -1 +1 @@
-!function(e){var d="(?:[\\w-]+|'[^'\n\r]*'|\"(?:\\.|[^\\\\\"\r\n])*\")";Prism.languages.toml={comment:{pattern:/#.*/,greedy:!0},table:{pattern:RegExp("(\\[\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*\\])"),lookbehind:!0,greedy:!0,alias:"class-name"},key:{pattern:RegExp("(^\\s*|[{,]\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*=)","m"),lookbehind:!0,greedy:!0,alias:"property"},string:{pattern:/"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},date:[{pattern:/\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i,alias:"number"},{pattern:/\d{2}:\d{2}:\d{2}(?:\.\d+)?/i,alias:"number"}],number:/(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/,boolean:/\b(?:true|false)\b/,punctuation:/[.,=[\]{}]/}}();
\ No newline at end of file
+!function(e){var d="(?:[\\w-]+|'[^'\n\r]*'|\"(?:\\.|[^\\\\\"\r\n])*\")";Prism.languages.toml={comment:{pattern:/#.*/,greedy:!0},table:{pattern:RegExp("(^\\s*\\[\\s*(?:\\[\\s*)?)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*\\])","m"),lookbehind:!0,greedy:!0,alias:"class-name"},key:{pattern:RegExp("(^\\s*|[{,]\\s*)"+d+"(?:\\s*\\.\\s*"+d+")*(?=\\s*=)","m"),lookbehind:!0,greedy:!0,alias:"property"},string:{pattern:/"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,greedy:!0},date:[{pattern:/\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i,alias:"number"},{pattern:/\d{2}:\d{2}:\d{2}(?:\.\d+)?/i,alias:"number"}],number:/(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/,boolean:/\b(?:true|false)\b/,punctuation:/[.,=[\]{}]/}}();
\ No newline at end of file
diff --git a/examples/prism-javadoc.html b/examples/prism-javadoc.html
new file mode 100644
index 0000000..4e80979
--- /dev/null
+++ b/examples/prism-javadoc.html
@@ -0,0 +1,29 @@
+<h2>Full example</h2>
+<pre><code class="language-java">/**
+ * Returns the value to which the specified key is mapped,
+ * or {@code null} if this map contains no mapping for the key.
+ *
+ * <p>More formally, if this map contains a mapping from a key
+ * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
+ * key.equals(k))}, then this method returns {@code v}; otherwise
+ * it returns {@code null}. (There can be at most one such mapping.)
+ *
+ * <p>If this map permits null values, then a return value of
+ * {@code null} does not <i>necessarily</i> indicate that the map
+ * contains no mapping for the key; it's also possible that the map
+ * explicitly maps the key to {@code null}. The {@link #containsKey
+ * containsKey} operation may be used to distinguish these two cases.
+ *
+ * @param key the key whose associated value is to be returned
+ * @return the value to which the specified key is mapped, or
+ * {@code null} if this map contains no mapping for the key
+ * @throws ClassCastException if the key is of an inappropriate type for
+ * this map
+ * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified key is null and this map
+ * does not permit null keys
+ * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
+ */
+V get(Object key);
+
+// Source: Java 1.8, Map#get(Object)</code></pre>
diff --git a/examples/prism-jsdoc.html b/examples/prism-jsdoc.html
new file mode 100644
index 0000000..85a7442
--- /dev/null
+++ b/examples/prism-jsdoc.html
@@ -0,0 +1,21 @@
+<h2>Full example</h2>
+<pre><code class="language-javascript">/**
+ * @typedef {object} Foo
+ * @property {string} bar
+ * @memberof Baz
+ */
+
+/**
+ * Trims the given string.
+ *
+ * @param {string} [str=""] the string.
+ * @returns {string} the trimmed string.
+ * @throws {TypeError} if the argument is not a string.
+ * @example trim(" hello ")
+ */
+function trim(str = "") {
+ if (typeof str != "string") {
+ throw new TypeError("str has to be a string");
+ }
+ return str.trim();
+}</code></pre>
diff --git a/examples/prism-phpdoc.html b/examples/prism-phpdoc.html
new file mode 100644
index 0000000..5b2f907
--- /dev/null
+++ b/examples/prism-phpdoc.html
@@ -0,0 +1,15 @@
+<h2>Full example</h2>
+<pre><code class="language-php"><?php
+
+/** @var \DateTime[] An array of DateTime objects. */
+/** @var string[] An array of string objects. */
+/** @var callable[] An array of with callable functions or methods. */
+
+/** @var \ArrayObject|\DateTime[] */
+$dates = array()
+
+/**
+ * @param bool|\DateTime $foo the first argument
+ * @return string|null
+ */
+function bar($foo) { ... }</code></pre>
diff --git a/examples/prism-t4-cs.html b/examples/prism-t4-cs.html
new file mode 100644
index 0000000..e3651c7
--- /dev/null
+++ b/examples/prism-t4-cs.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code><#@ template hostspecific="false" language="C#" #>
+<#@ assembly name="System.Core.dll" #>
+<#@ output extension=".txt" #>
+<#
+ using System.Collections.Generic;
+
+ var numbers = new List<int> { 0, 1, 2, 3, 4, 5, 6, /* 7, */ 8, 9, 10 };
+
+ foreach (var i in numbers)
+ {
+#>
+The square of <#= i #> is <#= i * i #>
+<#
+ }
+#></code></pre>
diff --git a/examples/prism-t4-vb.html b/examples/prism-t4-vb.html
new file mode 100644
index 0000000..04c9996
--- /dev/null
+++ b/examples/prism-t4-vb.html
@@ -0,0 +1,16 @@
+<h2>Full example</h2>
+<pre><code><#@ template hostspecific="false" language="VB" #>
+<#@ assembly name="System.Core.dll" #>
+<#@ output extension=".txt" #>
+<#
+ Imports System.Collections.Generic
+
+ Dim numbers() As Integer = { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10 }
+ ' not including 7
+
+ For Each i In numbers
+#>
+The square of <#= i #> is <#= i * i #>
+<#
+ Next
+#></code></pre>
diff --git a/examples/prism-toml.html b/examples/prism-toml.html
new file mode 100644
index 0000000..7f68c8e
--- /dev/null
+++ b/examples/prism-toml.html
@@ -0,0 +1,28 @@
+<h2>Full example</h2>
+<pre><code># This is a comment
+
+key = "value"
+paths.home = 'c:\foo\'
+
+[database.prod]
+server = "192.168.1.1"
+ports = [ 8001, 8001, 8002 ]
+connection_max = 5000
+enabled = true
+
+
+[[users]]
+name = "John"
+bday = 1995-09-22
+bio = ""
+interests = [ "biking", "fishing" ]
+
+[[users]]
+name = "Jane"
+bday = 1989-05-09
+bio = """\
+Hi!
+
+I love programming!\
+"""
+interests = [ "programming" ]</code></pre>
diff --git a/tests/languages/toml/table_feature.test b/tests/languages/toml/table_feature.test
index c0be8b7..4fbce4e 100644
--- a/tests/languages/toml/table_feature.test
+++ b/tests/languages/toml/table_feature.test
@@ -1,6 +1,9 @@
[table]
[[array]]
+# not a table
+foo = [ "bar" ]
+
----------------------------------------------------
[
@@ -12,6 +15,14 @@
["punctuation", "["],
["table", "array"],
["punctuation", "]"],
+ ["punctuation", "]"],
+
+ ["comment", "# not a table"],
+
+ ["key", "foo"],
+ ["punctuation", "="],
+ ["punctuation", "["],
+ ["string", "\"bar\""],
["punctuation", "]"]
]