Skip to content

Commit 88f7292

Browse files
authored
feat(elements): python code highlighting support (#3860)
1 parent fdf3a92 commit 88f7292

File tree

9 files changed

+406
-0
lines changed

9 files changed

+406
-0
lines changed

packages/elements/src/components/app/theme.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
--mut-file-gherkin-color: #00a818;
109109
--mut-file-svelte-color: #b8383d;
110110
--mut-file-rust-color: #627379;
111+
--mut-file-python-color: #498ba7;
111112
}
112113
:host([theme='dark']) {
113114
--mut-file-ts-color: #519aba;
@@ -123,6 +124,7 @@
123124
--mut-file-gherkin-color: #10b828;
124125
--mut-file-svelte-color: #cc3e44;
125126
--mut-file-rust-color: #6d8086;
127+
--mut-file-python-color: #519aba;
126128
}
127129

128130
/* Mutation testing elements custom theming ================================ */

packages/elements/src/components/file-icon/file-icon.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export class MutationTestReportFileIconComponent extends BaseElement {
6464
return svg`<svg class="${this.cssClass}" aria-label="svelte" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M10.617 10.473L14.809 7.8c2.387-1.52 5.688-.812 7.359 1.58a5.123 5.123 0 01.876 3.876 4.821 4.821 0 01-.72 1.798c.524.998.7 2.142.5 3.251a4.808 4.808 0 01-1.963 3.081l-.21.14-4.192 2.672c-2.386 1.52-5.688.812-7.36-1.58a5.125 5.125 0 01-.875-3.876c.116-.642.36-1.253.72-1.798a5.065 5.065 0 01-.5-3.251 4.81 4.81 0 011.962-3.081l.21-.14L14.81 7.8l-4.192 2.672zm9.825.008a3.33 3.33 0 00-3.573-1.324c-.226.06-.444.146-.65.256l-.202.118-4.192 2.671a2.891 2.891 0 00-1.306 1.937 3.081 3.081 0 00.526 2.33 3.33 3.33 0 003.574 1.326c.226-.06.444-.147.65-.256l.201-.118 1.6-1.02a.923.923 0 01.257-.113c.407-.105.837.054 1.077.4a.931.931 0 01.158.702.873.873 0 01-.295.512l-.099.072-4.192 2.671a.923.923 0 01-.257.113 1.003 1.003 0 01-1.076-.4.94.94 0 01-.171-.49l.002-.132.014-.156-.156-.047a5.407 5.407 0 01-1.387-.645l-.252-.174-.215-.158-.08.24a2.923 2.923 0 00-.1.392 3.082 3.082 0 00.527 2.33 3.33 3.33 0 003.38 1.37l.194-.045c.226-.06.444-.146.65-.256l.202-.118 4.192-2.671a2.892 2.892 0 001.306-1.937 3.081 3.081 0 00-.526-2.331 3.33 3.33 0 00-3.574-1.325 3.05 3.05 0 00-.65.257l-.201.117-1.6 1.02a.927.927 0 01-.257.113 1.003 1.003 0 01-1.077-.4.93.93 0 01-.158-.702.871.871 0 01.295-.512l.098-.072 4.192-2.671a.923.923 0 01.258-.113c.407-.106.836.053 1.076.399a.942.942 0 01.171.49l-.002.133-.014.156.155.047c.492.148.959.365 1.388.645l.252.175.215.157.079-.24c.042-.129.076-.26.1-.392a3.082 3.082 0 00-.526-2.33z"/></svg>`;
6565
case ProgrammingLanguage.rust:
6666
return svg`<svg class="${this.cssClass}" aria-label="rust" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M21.7 8.4V9l.1.1h.1c.3-.1.6-.1.9-.2.2-.1.4.1.3.3-.1.3-.1.6-.2.9v.1l.1.1c0 .1.1.1.2.1h.9c.2 0 .3.1.3.3v.2c-.1.3-.3.6-.4.8v.1s.1.1.1.2h.1c.3.1.6.1.9.2.2 0 .3.3.2.5-.2.3-.4.5-.5.7v.2c0 .1.1.1.2.2.3.1.5.2.8.3.2.1.3.3.1.5-.2.2-.4.4-.7.6v.3s.1.1.2.1c.2.1.4.3.7.4.2.1.2.4 0 .5-.3.2-.5.3-.8.5v.1c0 .2 0 .2.1.3.2.2.4.4.6.5.2.2.1.4-.1.5-.3.1-.6.2-.8.3 0 0-.1 0-.1.1-.1.1 0 .2 0 .3.2.2.3.4.5.7.1.1.1.3-.1.4-.1 0-.1 0-.2.1-.3 0-.5.1-.8.1h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.9 0-1.6-.4-2-1.2-.3-.6-.5-1.2-.5-1.8-.1-1.1-.1-2.2.3-3.3.3-.9.9-1.6 1.9-1.8h5.8c.1 0 .3 0 .3-.1v-.5s-.2-.1-.3-.1h-3.4c-.3 0-.4-.1-.4-.4V9.4c0-.7.3-1.2.9-1.4.5-.2 1-.4 1.5-.5 1.2-.2 2.4-.2 3.6.1.5.1 1 .3 1.4.6.4.4.7.8.6 1.4v3.6c0 1.4-.8 2.2-2.2 2.2-.7.1-1.4.1-2 .1zm-2.8-6c0 .4.3.8.8.8.4 0 .8-.4.8-.8s-.4-.7-.8-.8c-.5 0-.8.4-.8.8zm3.6 7h2c1.4 0 2.3-.9 2.3-2.3v-1.8c0-.2.1-.3.3-.3h.9c.9 0 1.6.4 2 1.2.3.6.5 1.2.5 1.8.1 1.1.1 2.2-.3 3.3-.3.9-.9 1.6-1.9 1.8h-5.8c-.1 0-.3 0-.3.1v.5s.2.1.3.1h3.4c.3 0 .4.1.4.4v1.3c0 .7-.3 1.2-.9 1.4-.5.2-1 .4-1.5.5-1.2.2-2.4.2-3.6-.1-.5-.1-1-.3-1.4-.6-.4-.4-.7-.8-.6-1.4v-3.6c0-1.4.8-2.2 2.2-2.2.7-.1 1.4-.1 2-.1zm2.8 6c0-.4-.3-.8-.8-.8-.4 0-.8.4-.8.8s.4.7.8.8c.5 0 .8-.4.8-.8z"/></svg>`;
6769
}
6870
}
6971
}

packages/elements/src/components/file-icon/file-icon.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ svg.svelte {
4444
svg.rust {
4545
fill: var(--mut-file-rust-color);
4646
}
47+
svg.python {
48+
fill: var(--mut-file-python-color);
49+
}
4750

4851
svg {
4952
width: 20px;

packages/elements/src/lib/code-helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum ProgrammingLanguage {
1414
gherkin = 'gherkin',
1515
svelte = 'svelte',
1616
rust = 'rust',
17+
python = 'python',
1718
}
1819

1920
/**
@@ -59,6 +60,8 @@ export function determineLanguage(fileName: string): ProgrammingLanguage | undef
5960
return ProgrammingLanguage.svelte;
6061
case 'rs':
6162
return ProgrammingLanguage.rust;
63+
case 'py':
64+
return ProgrammingLanguage.python;
6265
default:
6366
return undefined;
6467
}

packages/elements/src/style/prism-plugins.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'prismjs/components/prism-java';
88
import 'prismjs/components/prism-scala';
99
import 'prismjs/components/prism-gherkin';
1010
import 'prismjs/components/prism-rust';
11+
import 'prismjs/components/prism-python';
1112
// Markup and markup-templating are needed for php
1213
import 'prismjs/components/prism-markup';
1314
import 'prismjs/components/prism-markup-templating';

packages/elements/test/unit/lib/code-helpers.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe(highlightCode.name, () => {
1818
['foo.feature', ProgrammingLanguage.gherkin, 'Feature: foo'],
1919
['foo.scala', ProgrammingLanguage.scala, 'object Foo { def main(args: Array[String]) = println("Hello, world!") }'],
2020
['foo.rs', ProgrammingLanguage.rust, 'fn main() { println!("Hello, world!"); }'],
21+
['foo.py', ProgrammingLanguage.python, 'a = 10'],
2122
])(`should parse %s as %s`, (fileName, language, code) => {
2223
const highlightedCode = highlightCode(code, fileName);
2324
expect(highlightedCode).contains('<span'); // actual highlighting is not tested, in prism we trust
@@ -197,6 +198,7 @@ describe(determineLanguage.name, () => {
197198
['php', ProgrammingLanguage.php],
198199
['vue', ProgrammingLanguage.vue],
199200
['feature', ProgrammingLanguage.gherkin],
201+
['py', ProgrammingLanguage.python],
200202
] as const)(`should recognize file.%s as language %s`, (extension, expected) => {
201203
expect(determineLanguage(`file.${extension}`)).eq(expected);
202204
});

packages/elements/testResources/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ <h1 class="display-1">Test resources</h1>
2525
<a class="list-group-item list-group-item-action" href="/testResources/rust-example/">Rust example</a>
2626
<a class="list-group-item list-group-item-action" href="/testResources/deep-dir-example/">Deep dir example</a>
2727
<a class="list-group-item list-group-item-action" href="/testResources/pitest-example/">Pitest example</a>
28+
<a class="list-group-item list-group-item-action" href="/testResources/python-example/">Python example</a>
2829
<a class="list-group-item list-group-item-action" href="/testResources/infection-php-example/">InfectionPHP example</a>
2930
<a class="list-group-item list-group-item-action" href="/testResources/tests-example/">Tests example</a>
3031
<a class="list-group-item list-group-item-action" href="/testResources/test-files-example/">Test files example</a>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
<a href="/">Back</a>
6+
<mutation-test-report-app title-postfix="Stryker report"></mutation-test-report-app>
7+
<script type="module" src="/mutation-test-elements.js"></script>
8+
<script src="report.js"></script>
9+
<script>
10+
const app = document.getElementsByTagName('mutation-test-report-app').item(0);
11+
function updateTheme() {
12+
document.body.style.backgroundColor = app.themeBackgroundColor;
13+
}
14+
app.addEventListener('theme-changed', updateTheme);
15+
updateTheme();
16+
</script>
17+
</body>
18+
19+
</html>

0 commit comments

Comments
 (0)