Skip to content

Commit

Permalink
Added support for DNS zone files (#1961)
Browse files Browse the repository at this point in the history
This adds support for DNS zone files.

The highlighting is quite simple as every type and class is highlighted as `keyword`. This is intentional as other token names (e.g. `class-name`, `function`, `builtin`, ...) are not highlighted by every theme resulting in large portions of unstyled text for some themes.
  • Loading branch information
RunDevelopment authored Jul 15, 2019
1 parent 7d05659 commit bb84f98
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@
"alias": "jinja2",
"owner": "romanvm"
},
"dns-zone-file": {
"title": "DNS zone file",
"owner": "RunDevelopment",
"alias": "dns-zone"
},
"docker": {
"title": "Docker",
"alias": "dockerfile",
Expand Down
33 changes: 33 additions & 0 deletions components/prism-dns-zone-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Prism.languages['dns-zone-file'] = {
'comment': /;.*/,
'string': {
pattern: /"(?:\\.|[^"\\\r\n])*"/,
greedy: true
},
'variable': [
{
pattern: /(^\$ORIGIN[ \t]+)\S+/m,
lookbehind: true,
},
{
pattern: /(^|\s)@(?=\s|$)/,
lookbehind: true,
}
],
'keyword': /^\$(?:ORIGIN|INCLUDE|TTL)(?=\s|$)/m,
'class': {
// https://tools.ietf.org/html/rfc1035#page-13
pattern: /(^|\s)(?:IN|CH|CS|HS)(?=\s|$)/,
lookbehind: true,
alias: 'keyword'
},
'type': {
// https://en.wikipedia.org/wiki/List_of_DNS_record_types
pattern: /(^|\s)(?:A|A6|AAAA|AFSDB|APL|ATMA|CAA|CDNSKEY|CDS|CERT|CNAME|DHCID|DLV|DNAME|DNSKEY|DS|EID|GID|GPOS|HINFO|HIP|IPSECKEY|ISDN|KEY|KX|LOC|MAILA|MAILB|MB|MD|MF|MG|MINFO|MR|MX|NAPTR|NB|NBSTAT|NIMLOC|NINFO|NS|NSAP|NSAP-PTR|NSEC|NSEC3|NSEC3PARAM|NULL|NXT|OPENPGPKEY|PTR|PX|RKEY|RP|RRSIG|RT|SIG|SINK|SMIMEA|SOA|SPF|SRV|SSHFP|TA|TKEY|TLSA|TSIG|TXT|UID|UINFO|UNSPEC|URI|WKS|X25)(?=\s|$)/,
lookbehind: true,
alias: 'keyword'
},
'punctuation': /[()]/
};

Prism.languages['dns-zone'] = Prism.languages['dns-zone-file']
1 change: 1 addition & 0 deletions components/prism-dns-zone-file.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/prism-dns-zone-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>Full example</h2>
<pre><code>$TTL 3d
@ IN SOA root.localhost. root.sneaky.net. (
2015050503 ; serial
12h ; refresh
15m ; retry
3w ; expire
3h ; negative response TTL
)
IN NS root.localhost.
IN NS localhost. ; secondary name server is preferably externally maintained

www IN A 3.141.59.26
ww1 IN CNAME www</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"dotnet": "csharp",
"coffee": "coffeescript",
"jinja2": "django",
"dns-zone": "dns-zone-file",
"dockerfile": "docker",
"gamemakerlanguage": "gml",
"hs": "haskell",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"css-extras": "CSS Extras",
"django": "Django/Jinja2",
"jinja2": "Django/Jinja2",
"dns-zone-file": "DNS zone file",
"dns-zone": "DNS zone file",
"dockerfile": "Docker",
"ebnf": "Extended Backus–Naur form",
"ejs": "EJS",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/languages/dns-zone-file/class_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
IN
CH
CS
HS

----------------------------------------------------

[
["class", "IN"],
["class", "CH"],
["class", "CS"],
["class", "HS"]
]

----------------------------------------------------

Checks for all resource record classes.
11 changes: 11 additions & 0 deletions tests/languages/dns-zone-file/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; comment

----------------------------------------------------

[
["comment", "; comment"]
]

----------------------------------------------------

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/dns-zone-file/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"foo"
"\""

----------------------------------------------------

[
["string", "\"foo\""],
["string", "\"\\\"\""]
]

----------------------------------------------------

Checks for strings.
155 changes: 155 additions & 0 deletions tests/languages/dns-zone-file/type_featrue.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
A
A6
AAAA
AFSDB
APL
ATMA
CAA
CDNSKEY
CDS
CERT
CNAME
DHCID
DLV
DNAME
DNSKEY
DS
EID
GID
GPOS
HINFO
HIP
IPSECKEY
ISDN
KEY
KX
LOC
MAILA
MAILB
MB
MD
MF
MG
MINFO
MR
MX
NAPTR
NB
NBSTAT
NIMLOC
NINFO
NS
NSAP
NSAP-PTR
NSEC
NSEC3
NSEC3PARAM
NULL
NXT
OPENPGPKEY
PTR
PX
RKEY
RP
RRSIG
RT
SIG
SINK
SMIMEA
SOA
SPF
SRV
SSHFP
TA
TKEY
TLSA
TSIG
TXT
UID
UINFO
UNSPEC
URI
WKS
X25

----------------------------------------------------

[
["type", "A"],
["type", "A6"],
["type", "AAAA"],
["type", "AFSDB"],
["type", "APL"],
["type", "ATMA"],
["type", "CAA"],
["type", "CDNSKEY"],
["type", "CDS"],
["type", "CERT"],
["type", "CNAME"],
["type", "DHCID"],
["type", "DLV"],
["type", "DNAME"],
["type", "DNSKEY"],
["type", "DS"],
["type", "EID"],
["type", "GID"],
["type", "GPOS"],
["type", "HINFO"],
["type", "HIP"],
["type", "IPSECKEY"],
["type", "ISDN"],
["type", "KEY"],
["type", "KX"],
["type", "LOC"],
["type", "MAILA"],
["type", "MAILB"],
["type", "MB"],
["type", "MD"],
["type", "MF"],
["type", "MG"],
["type", "MINFO"],
["type", "MR"],
["type", "MX"],
["type", "NAPTR"],
["type", "NB"],
["type", "NBSTAT"],
["type", "NIMLOC"],
["type", "NINFO"],
["type", "NS"],
["type", "NSAP"],
["type", "NSAP-PTR"],
["type", "NSEC"],
["type", "NSEC3"],
["type", "NSEC3PARAM"],
["type", "NULL"],
["type", "NXT"],
["type", "OPENPGPKEY"],
["type", "PTR"],
["type", "PX"],
["type", "RKEY"],
["type", "RP"],
["type", "RRSIG"],
["type", "RT"],
["type", "SIG"],
["type", "SINK"],
["type", "SMIMEA"],
["type", "SOA"],
["type", "SPF"],
["type", "SRV"],
["type", "SSHFP"],
["type", "TA"],
["type", "TKEY"],
["type", "TLSA"],
["type", "TSIG"],
["type", "TXT"],
["type", "UID"],
["type", "UINFO"],
["type", "UNSPEC"],
["type", "URI"],
["type", "WKS"],
["type", "X25"]
]

----------------------------------------------------

Checks for all resource record types.
14 changes: 14 additions & 0 deletions tests/languages/dns-zone-file/variable_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$ORIGIN foo.bar.com
@

----------------------------------------------------

[
["keyword", "$ORIGIN"],
["variable", "foo.bar.com"],
["variable", "@"]
]

----------------------------------------------------

Checks for variables.

0 comments on commit bb84f98

Please sign in to comment.