Skip to content

Commit

Permalink
Merge branch 'master' into yaml_highlight_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pplantinga authored Apr 18, 2020
2 parents a2a2c16 + c7c561d commit 15a45b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Language Improvements:
- enh(plaintext) added `text` and `txt` as alias (#2360) [Taufik Nurrohman][]
- enh(powershell) added PowerShell v5.1/v7 default aliases as "built_in"s (#2423) [Sean Williams][]
- fix(yaml) Fix tags to include non-word characters (#2486) [Peter Plantinga][]
- enh(yaml) added support for timestamps (#2475) [Peter Plantinga][]

Developer Tools:

Expand Down
2 changes: 2 additions & 0 deletions SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Languages that listed a **Package** below are 3rd party languages and are not bu
| Cap’n Proto | capnproto, capnp | |
| Clojure | clojure, clj | |
| CoffeeScript | coffeescript, coffee, cson, iced | |
| CpcdosC+ | cpc | [highlightjs-cpcdos](https://github.com/SPinti-Software/highlightjs-cpcdos) |
| Crmsh | crmsh, crm, pcmk | |
| Crystal | crystal, cr | |
| Cypher (Neo4j) | cypher | [highlightjs-cypher](https://github.com/highlightjs/highlightjs-cypher) |
Expand Down Expand Up @@ -177,6 +178,7 @@ Languages that listed a **Package** below are 3rd party languages and are not bu
| Test Anything Protocol | tap | |
| Thrift | thrift | |
| TP | tp | |
| Transact-SQL | tsql | [highlightjs-tsql](https://github.com/highlightjs/highlightjs-tsql) |
| Twig | twig, craftcms | |
| TypeScript | typescript, ts | |
| VB.Net | vbnet, vb | |
Expand Down
10 changes: 10 additions & 0 deletions src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export default function(hljs) {
]
};

var DATE_RE = '[0-9]{4}(-[0-9][0-9]){0,2}';
var TIME_RE = '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?';
var FRACTION_RE = '(\\.[0-9]*)?';
var ZONE_RE = '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?';
var TIMESTAMP = {
className: 'number',
begin: '\\b' + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + '\\b',
}

return {
name: 'YAML',
case_insensitive: true,
Expand Down Expand Up @@ -104,6 +113,7 @@ export default function(hljs) {
beginKeywords: LITERALS,
keywords: {literal: LITERALS}
},
TIMESTAMP,
// numbers are any valid C-style number that
// sit isolated from other words
{
Expand Down
6 changes: 6 additions & 0 deletions test/markup/yaml/numbers.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
<span class="hljs-attr">hex:</span> <span class="hljs-number">0x999fff</span>
<span class="hljs-attr">numkey999:</span> <span class="hljs-number">1234</span>
<span class="hljs-attr">exp:</span> <span class="hljs-number">-2.3e-5</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">space:</span> <span class="hljs-number">2001-12-14 21:59:43.10 -5</span>
<span class="hljs-attr">nozone:</span> <span class="hljs-number">2001-12-15 2:59:43.10</span>
<span class="hljs-attr">date:</span> <span class="hljs-number">2002-12-14</span>

5 changes: 5 additions & 0 deletions test/markup/yaml/numbers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ not_hex: 999fff
hex: 0x999fff
numkey999: 1234
exp: -2.3e-5
canonical: 2001-12-15T02:59:43.1Z
iso8601: 2001-12-14t21:59:43.10-05:00
space: 2001-12-14 21:59:43.10 -5
nozone: 2001-12-15 2:59:43.10
date: 2002-12-14

0 comments on commit 15a45b4

Please sign in to comment.