Skip to content

Commit 42d39f2

Browse files
committed
highlight ts and env
1 parent 563ef10 commit 42d39f2

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

dist/action.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21579,6 +21579,49 @@ Prism.languages.js = Prism.languages.javascript;
2157921579

2158021580
}(Prism));
2158121581

21582+
(function (Prism) {
21583+
21584+
Prism.languages.typescript = Prism.languages.extend('javascript', {
21585+
'class-name': {
21586+
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
21587+
lookbehind: true,
21588+
greedy: true,
21589+
inside: null // see below
21590+
},
21591+
// From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
21592+
'keyword': /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/,
21593+
'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
21594+
});
21595+
21596+
// doesn't work with TS because TS is too complex
21597+
delete Prism.languages.typescript['parameter'];
21598+
21599+
// a version of typescript specifically for highlighting types
21600+
var typeInside = Prism.languages.extend('typescript', {});
21601+
delete typeInside['class-name'];
21602+
21603+
Prism.languages.typescript['class-name'].inside = typeInside;
21604+
21605+
Prism.languages.insertBefore('typescript', 'function', {
21606+
'generic-function': {
21607+
// e.g. foo<T extends "bar" | "baz">( ...
21608+
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
21609+
greedy: true,
21610+
inside: {
21611+
'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
21612+
'generic': {
21613+
pattern: /<[\s\S]+/, // everything after the first <
21614+
alias: 'class-name',
21615+
inside: typeInside
21616+
}
21617+
}
21618+
}
21619+
});
21620+
21621+
Prism.languages.ts = Prism.languages.typescript;
21622+
21623+
}(Prism));
21624+
2158221625
const blocks = '(if|else if|await|then|catch|each|html|debug)';
2158321626

2158421627
Prism.languages.svelte = Prism.languages.extend('markup', {
@@ -21724,6 +21767,7 @@ Prism.languages.svelte.tag.addInlined('script', 'javascript');
2172421767

2172521768
var LanguageMap; (function (LanguageMap) {
2172621769
const bash = "bash"; LanguageMap["bash"] = bash;
21770+
const env = "bash"; LanguageMap["env"] = env;
2172721771
const html = "markup"; LanguageMap["html"] = html;
2172821772
const sv = "svelte"; LanguageMap["sv"] = sv;
2172921773
const js = "javascript"; LanguageMap["js"] = js;

dist/cli.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20342,6 +20342,49 @@ Prism.languages.js = Prism.languages.javascript;
2034220342

2034320343
}(Prism));
2034420344

20345+
(function (Prism) {
20346+
20347+
Prism.languages.typescript = Prism.languages.extend('javascript', {
20348+
'class-name': {
20349+
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,
20350+
lookbehind: true,
20351+
greedy: true,
20352+
inside: null // see below
20353+
},
20354+
// From JavaScript Prism keyword list and TypeScript language spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
20355+
'keyword': /\b(?:abstract|as|asserts|async|await|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|is|keyof|let|module|namespace|new|null|of|package|private|protected|public|readonly|return|require|set|static|super|switch|this|throw|try|type|typeof|undefined|var|void|while|with|yield)\b/,
20356+
'builtin': /\b(?:string|Function|any|number|boolean|Array|symbol|console|Promise|unknown|never)\b/,
20357+
});
20358+
20359+
// doesn't work with TS because TS is too complex
20360+
delete Prism.languages.typescript['parameter'];
20361+
20362+
// a version of typescript specifically for highlighting types
20363+
var typeInside = Prism.languages.extend('typescript', {});
20364+
delete typeInside['class-name'];
20365+
20366+
Prism.languages.typescript['class-name'].inside = typeInside;
20367+
20368+
Prism.languages.insertBefore('typescript', 'function', {
20369+
'generic-function': {
20370+
// e.g. foo<T extends "bar" | "baz">( ...
20371+
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,
20372+
greedy: true,
20373+
inside: {
20374+
'function': /^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,
20375+
'generic': {
20376+
pattern: /<[\s\S]+/, // everything after the first <
20377+
alias: 'class-name',
20378+
inside: typeInside
20379+
}
20380+
}
20381+
}
20382+
});
20383+
20384+
Prism.languages.ts = Prism.languages.typescript;
20385+
20386+
}(Prism));
20387+
2034520388
const blocks = '(if|else if|await|then|catch|each|html|debug)';
2034620389

2034720390
Prism.languages.svelte = Prism.languages.extend('markup', {
@@ -20487,6 +20530,7 @@ Prism.languages.svelte.tag.addInlined('script', 'javascript');
2048720530

2048820531
var LanguageMap; (function (LanguageMap) {
2048920532
const bash = "bash"; LanguageMap["bash"] = bash;
20533+
const env = "bash"; LanguageMap["env"] = env;
2049020534
const html = "markup"; LanguageMap["html"] = html;
2049120535
const sv = "svelte"; LanguageMap["sv"] = sv;
2049220536
const js = "javascript"; LanguageMap["js"] = js;

src/format/code.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ _highlight("highlights javascript", () => {
5757
);
5858
});
5959

60+
_highlight("highlights typescript", () => {
61+
const highlighted = highlight(`console.log('boo')`, "ts");
62+
assert.snapshot(
63+
highlighted,
64+
`<div class="code-block"><pre class='language-typescript'><code><span class="token builtin">console</span><span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'boo'</span><span class="token punctuation">)</span></code></pre></div>`
65+
);
66+
});
67+
6068
_highlight("highlights css", () => {
6169
const highlighted = highlight(`.thing { color: pink; }`, "css");
6270
assert.snapshot(

src/format/code.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import visit from "unist-util-visit";
55
import PrismJS from "prismjs";
66
import "prismjs/components/prism-bash.js";
77
import "prismjs/components/prism-diff.js";
8+
import "prismjs/components/prism-typescript.js";
9+
810
import "prism-svelte";
911

1012
export type language = keyof typeof LanguageMap;
1113

1214
enum LanguageMap {
1315
bash = "bash",
16+
env = "bash",
1417
html = "markup",
1518
sv = "svelte",
1619
js = "javascript",

0 commit comments

Comments
 (0)