Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix yaml number rendering #179

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Renderers/CodeNodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function configureHighlighter()
if (false === self::$isHighlighterConfigured) {
Highlighter::registerLanguage('php', __DIR__.'/../Templates/highlight.php/php.json', true);
Highlighter::registerLanguage('twig', __DIR__.'/../Templates/highlight.php/twig.json', true);
Highlighter::registerLanguage('yaml', __DIR__.'/../Templates/highlight.php/yaml.json', true);
}

self::$isHighlighterConfigured = true;
Expand Down
127 changes: 127 additions & 0 deletions src/Templates/highlight.php/yaml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"case_insensitive": true,
"aliases": [
"yml",
"YAML",
"yaml"
],
"contains": [
{
"className": "attr",
"variants": [
{
"begin": "\\w[\\w :\\\/.-]*:(?=[ \t]|$)"
},
{
"begin": "\"\\w[\\w :\\\/.-]*\":(?=[ \t]|$)"
},
{
"begin": "'\\w[\\w :\\\/.-]*':(?=[ \t]|$)"
}
]
},
{
"className": "meta",
"begin": "^---s*$",
"relevance": 10
},
{
"className": "string",
"begin": "[\\|>]([0-9]?[+-])?[ ]*\\n( *)[\\S ]+\\n(\\2[\\S ]+\\n?)*"
},
{
"begin": "<%[%=-]?",
"end": "[%-]?%>",
"subLanguage": "ruby",
"excludeBegin": true,
"excludeEnd": true,
"relevance": 0
},
{
"className": "type",
"begin": "![a-zA-Z_]\\w*"
},
{
"className": "type",
"begin": "!![a-zA-Z_]\\w*"
},
{
"className": "meta",
"begin": "&[a-zA-Z_]\\w*$"
},
{
"className": "meta",
"begin": "\\*[a-zA-Z_]\\w*$"
},
{
"className": "bullet",
"begin": "\\-(?=[ ]|$)",
"relevance": 0
},
{
"className": "comment",
"begin": "#",
"end": "$",
"contains": [
{
"begin": "\\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\\b"
},
{
"className": "doctag",
"begin": "(?:TODO|FIXME|NOTE|BUG|XXX):",
"relevance": 0
}
]
},
{
"beginKeywords": "true false yes no null",
"keywords": {
"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"
},
{
"className": "string",
"relevance": 0,
"variants": [
{
"begin": "'",
"end": "'"
},
{
"begin": "\"",
"end": "\""
},
{
"begin": "\\S+"
}
],
"contains": [
{
"begin": "\\\\[\\s\\S]",
"relevance": 0
},
{
"className": "template-variable",
"variants": [
{
"begin": "{{",
"end": "}}"
},
{
"begin": "%{",
"end": "}"
}
]
}
]
}
]
}
37 changes: 33 additions & 4 deletions tests/fixtures/expected/blocks/code-blocks/yaml.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
<div translate="no" data-loc="1" 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</pre>
<pre class="codeblock-code"><code><span class="hljs-comment"># some code</span>
</code></pre>
<pre class="codeblock-lines">1
2
3
4
5
6
7
8
9
10</pre>
<pre class="codeblock-code">
<code>
<span class="hljs-comment"># some code</span>
<span class="hljs-attr">parameters:</span>
<span class="hljs-attr">credit_card_number:</span>
<span class="hljs-number">1234_5678_9012_3456</span>
<span class="hljs-attr">long_number:</span>
<span class="hljs-number">10_000_000_000</span>
<span class="hljs-attr">pi:</span>
<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>
</div>
9 changes: 9 additions & 0 deletions tests/fixtures/source/blocks/code-blocks/yaml.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

.. code-block:: yaml
# some code
parameters:
credit_card_number: 1234_5678_9012_3456
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
Loading