Skip to content

Commit e45266b

Browse files
committed
🐛 Fix yaml date rendering (now rendered as number)
Regex was extracted from `symfony/yaml`: https://github.com/symfony/yaml/blob/fa34c77015aa6720469db7003567b9f772492bf2/Inline.php#L810-L826 Non-js syntax was removed, non-capture groups burden was removed.
1 parent 678a178 commit e45266b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Templates/highlight.php/yaml.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
"literal": "true false yes no null"
8080
}
8181
},
82+
{
83+
"className": "number",
84+
"begin": "\\b([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(([Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(\\.([0-9]*))?([ \\t]*(Z|([-+])([0-9][0-9]?)(:([0-9][0-9]))?))?)?\\b"
85+
},
8286
{
8387
"className": "number",
8488
"begin": "(-?)(\\b0[xX][a-fA-F0-9_]+|(\\b\\d[\\d_]*(\\.[\\d_]*)?|\\.\\d[\\d_]*)([eE][-+]?\\d[\\d_]*)?)\\b"

tests/fixtures/expected/blocks/code-blocks/yaml.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<div translate="no" data-loc="6" class="notranslate codeblock codeblock-length-sm codeblock-yaml">
1+
<div translate="no" data-loc="10" class="notranslate codeblock codeblock-length-md codeblock-yaml">
22
<div class="codeblock-scroll">
33
<pre class="codeblock-lines">1
44
2
55
3
66
4
77
5
8-
6</pre>
8+
6
9+
7
10+
8
11+
9
12+
10</pre>
913
<pre class="codeblock-code">
1014
<code>
1115
<span class="hljs-comment"># some code</span>
@@ -18,6 +22,14 @@
1822
<span class="hljs-number">3.14159_26535_89793</span>
1923
<span class="hljs-attr">hex_words:</span>
2024
<span class="hljs-number">0x_CAFE_F00D</span>
25+
<span class="hljs-attr">canonical:</span>
26+
<span class="hljs-number">2001-12-15T02:59:43.1Z</span>
27+
<span class="hljs-attr">iso8601:</span>
28+
<span class="hljs-number">2001-12-14t21:59:43.10-05:00</span>
29+
<span class="hljs-attr">spaced:</span>
30+
<span class="hljs-number">2001-12-14 21:59:43.10 -5</span>
31+
<span class="hljs-attr">date:</span>
32+
<span class="hljs-number">2002-12-14</span>
2133
</code>
2234
</pre>
2335
</div>

tests/fixtures/source/blocks/code-blocks/yaml.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
long_number: 10_000_000_000
77
pi: 3.14159_26535_89793
88
hex_words: 0x_CAFE_F00D
9+
canonical: 2001-12-15T02:59:43.1Z
10+
iso8601: 2001-12-14t21:59:43.10-05:00
11+
spaced: 2001-12-14 21:59:43.10 -5
12+
date: 2002-12-14

0 commit comments

Comments
 (0)