Skip to content

Commit

Permalink
🐛 Fix yaml date rendering (now rendered as number)
Browse files Browse the repository at this point in the history
Regex was extracted from `symfony/yaml`: https:/symfony/yaml/blob/fa34c77015aa6720469db7003567b9f772492bf2/Inline.php#L810-L826
Non-js syntax was removed, non-capture groups burden was removed.
  • Loading branch information
homersimpsons committed Sep 6, 2024
1 parent 678a178 commit e45266b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Templates/highlight.php/yaml.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"literal": "true false yes no null"
}
},
{
"className": "number",
"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"
},
{
"className": "number",
"begin": "(-?)(\\b0[xX][a-fA-F0-9_]+|(\\b\\d[\\d_]*(\\.[\\d_]*)?|\\.\\d[\\d_]*)([eE][-+]?\\d[\\d_]*)?)\\b"
Expand Down
16 changes: 14 additions & 2 deletions tests/fixtures/expected/blocks/code-blocks/yaml.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<div translate="no" data-loc="6" class="notranslate codeblock codeblock-length-sm codeblock-yaml">
<div translate="no" data-loc="10" class="notranslate codeblock codeblock-length-md codeblock-yaml">
<div class="codeblock-scroll">
<pre class="codeblock-lines">1
2
3
4
5
6</pre>
6
7
8
9
10</pre>
<pre class="codeblock-code">
<code>
<span class="hljs-comment"># some code</span>
Expand All @@ -18,6 +22,14 @@
<span class="hljs-number">3.14159_26535_89793</span>
<span class="hljs-attr">hex_words:</span>
<span class="hljs-number">0x_CAFE_F00D</span>
<span class="hljs-attr">canonical:</span>
<span class="hljs-number">2001-12-15T02:59:43.1Z</span>
<span class="hljs-attr">iso8601:</span>
<span class="hljs-number">2001-12-14t21:59:43.10-05:00</span>
<span class="hljs-attr">spaced:</span>
<span class="hljs-number">2001-12-14 21:59:43.10 -5</span>
<span class="hljs-attr">date:</span>
<span class="hljs-number">2002-12-14</span>
</code>
</pre>
</div>
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/source/blocks/code-blocks/yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
long_number: 10_000_000_000
pi: 3.14159_26535_89793
hex_words: 0x_CAFE_F00D
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

0 comments on commit e45266b

Please sign in to comment.