Skip to content

Commit 8476a9a

Browse files
authoredDec 5, 2021
Added support for go.mod files (#3209)
1 parent 969f152 commit 8476a9a

15 files changed

+241
-3
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+5
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@
495495
"require": "clike",
496496
"owner": "arnehormann"
497497
},
498+
"go-module": {
499+
"title": "Go module",
500+
"alias": "go-mod",
501+
"owner": "RunDevelopment"
502+
},
498503
"graphql": {
499504
"title": "GraphQL",
500505
"optional": "markdown",

‎components/prism-go-module.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://go.dev/ref/mod#go-mod-file-module
2+
3+
Prism.languages['go-mod'] = Prism.languages['go-module'] = {
4+
'comment': {
5+
pattern: /\/\/.*/,
6+
greedy: true
7+
},
8+
'version': {
9+
pattern: /(^|[\s()[\],])v\d+\.\d+\.\d+(?:[+-][-+.\w]*)?(?![^\s()[\],])/,
10+
lookbehind: true,
11+
alias: 'number'
12+
},
13+
'go-version': {
14+
pattern: /((?:^|\s)go\s+)\d+(?:\.\d+){1,2}/,
15+
lookbehind: true,
16+
alias: 'number'
17+
},
18+
'keyword': {
19+
pattern: /^([ \t]*)(?:exclude|go|module|replace|require|retract)\b/m,
20+
lookbehind: true
21+
},
22+
'operator': /=>/,
23+
'punctuation': /[()[\],]/
24+
};

‎components/prism-go-module.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-go-module.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: https://go.dev/doc/modules/gomod-ref#example
3+
4+
module example.com/mymodule
5+
6+
go 1.14
7+
8+
require (
9+
example.com/othermodule v1.2.3
10+
example.com/thismodule v1.2.3
11+
example.com/thatmodule v1.2.3
12+
)
13+
14+
replace example.com/thatmodule => ../thatmodule
15+
exclude example.com/thismodule v1.3.0</code></pre>

‎plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
"xls": "excel-formula",
198198
"gamemakerlanguage": "gml",
199199
"gni": "gn",
200+
"go-mod": "go-module",
200201
"hbs": "handlebars",
201202
"hs": "haskell",
202203
"idr": "idris",

‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
"glsl": "GLSL",
9999
"gn": "GN",
100100
"gni": "GN",
101+
"go-module": "Go module",
102+
"go-mod": "Go module",
101103
"graphql": "GraphQL",
102104
"hbs": "Handlebars",
103105
"hs": "Haskell",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// comment
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "// comment"]
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
module golang.org/x/net
2+
3+
go 1.14
4+
5+
require golang.org/x/net v1.2.3
6+
7+
require (
8+
golang.org/x/crypto v1.4.5 // indirect
9+
golang.org/x/text v1.6.7
10+
)
11+
12+
exclude golang.org/x/net v1.2.3
13+
14+
exclude (
15+
golang.org/x/crypto v1.4.5
16+
golang.org/x/text v1.6.7
17+
)
18+
19+
replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5
20+
21+
replace (
22+
golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5
23+
golang.org/x/net => example.com/fork/net v1.4.5
24+
golang.org/x/net v1.2.3 => ./fork/net
25+
golang.org/x/net => ./fork/net
26+
)
27+
28+
retract (
29+
v1.0.0 // Published accidentally.
30+
v1.0.1 // Contains retractions only.
31+
)
32+
33+
retract v1.0.0
34+
retract [v1.0.0, v1.9.9]
35+
retract (
36+
v1.0.0
37+
[v1.0.0, v1.9.9]
38+
)
39+
40+
----------------------------------------------------
41+
42+
[
43+
["keyword", "module"], " golang.org/x/net\r\n\r\n",
44+
45+
["keyword", "go"], ["go-version", "1.14"],
46+
47+
["keyword", "require"], " golang.org/x/net ", ["version", "v1.2.3"],
48+
49+
["keyword", "require"],
50+
["punctuation", "("],
51+
52+
"\r\n golang.org/x/crypto ",
53+
["version", "v1.4.5"],
54+
["comment", "// indirect"],
55+
56+
"\r\n golang.org/x/text ",
57+
["version", "v1.6.7"],
58+
59+
["punctuation", ")"],
60+
61+
["keyword", "exclude"], " golang.org/x/net ", ["version", "v1.2.3"],
62+
63+
["keyword", "exclude"], ["punctuation", "("],
64+
"\r\n golang.org/x/crypto ", ["version", "v1.4.5"],
65+
"\r\n golang.org/x/text ", ["version", "v1.6.7"],
66+
["punctuation", ")"],
67+
68+
["keyword", "replace"],
69+
" golang.org/x/net ",
70+
["version", "v1.2.3"],
71+
["operator", "=>"],
72+
" example.com/fork/net ",
73+
["version", "v1.4.5"],
74+
75+
["keyword", "replace"],
76+
["punctuation", "("],
77+
78+
"\r\n golang.org/x/net ",
79+
["version", "v1.2.3"],
80+
["operator", "=>"],
81+
" example.com/fork/net ",
82+
["version", "v1.4.5"],
83+
84+
"\r\n golang.org/x/net ",
85+
["operator", "=>"],
86+
" example.com/fork/net ",
87+
["version", "v1.4.5"],
88+
89+
"\r\n golang.org/x/net ",
90+
["version", "v1.2.3"],
91+
["operator", "=>"],
92+
" ./fork/net\r\n golang.org/x/net ",
93+
["operator", "=>"],
94+
" ./fork/net\r\n",
95+
96+
["punctuation", ")"],
97+
98+
["keyword", "retract"], ["punctuation", "("],
99+
["version", "v1.0.0"], ["comment", "// Published accidentally."],
100+
["version", "v1.0.1"], ["comment", "// Contains retractions only."],
101+
["punctuation", ")"],
102+
103+
["keyword", "retract"],
104+
["version", "v1.0.0"],
105+
106+
["keyword", "retract"],
107+
["punctuation", "["],
108+
["version", "v1.0.0"],
109+
["punctuation", ","],
110+
["version", "v1.9.9"],
111+
["punctuation", "]"],
112+
113+
["keyword", "retract"],
114+
["punctuation", "("],
115+
116+
["version", "v1.0.0"],
117+
118+
["punctuation", "["],
119+
["version", "v1.0.0"],
120+
["punctuation", ","],
121+
["version", "v1.9.9"],
122+
["punctuation", "]"],
123+
124+
["punctuation", ")"]
125+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exclude
2+
go
3+
module
4+
replace
5+
require
6+
retract
7+
8+
----------------------------------------------------
9+
10+
[
11+
["keyword", "exclude"],
12+
["keyword", "go"],
13+
["keyword", "module"],
14+
["keyword", "replace"],
15+
["keyword", "require"],
16+
["keyword", "retract"]
17+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["operator", "=>"]
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
( ) [ ]
2+
,
3+
4+
----------------------------------------------------
5+
6+
[
7+
["punctuation", "("],
8+
["punctuation", ")"],
9+
["punctuation", "["],
10+
["punctuation", "]"],
11+
12+
["punctuation", ","]
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
v0.0.0
2+
v1.12.134
3+
v8.0.5-pre
4+
v2.0.9+meta
5+
v1.5.0-beta
6+
v0.0.0-20191109021931-daa7c04131f5
7+
v1.999.999-99999999999999-daa7c04131f5
8+
v1.2.4-0.20191109021931-daa7c04131f5
9+
10+
----------------------------------------------------
11+
12+
[
13+
["version", "v0.0.0"],
14+
["version", "v1.12.134"],
15+
["version", "v8.0.5-pre"],
16+
["version", "v2.0.9+meta"],
17+
["version", "v1.5.0-beta"],
18+
["version", "v0.0.0-20191109021931-daa7c04131f5"],
19+
["version", "v1.999.999-99999999999999-daa7c04131f5"],
20+
["version", "v1.2.4-0.20191109021931-daa7c04131f5"]
21+
]

0 commit comments

Comments
 (0)
Please sign in to comment.