Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/elements/src/lib/code-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum ProgrammingLanguage {
gherkin = 'gherkin',
svelte = 'svelte',
rust = 'rust',
python = 'python',
}

/**
Expand Down Expand Up @@ -59,6 +60,8 @@ export function determineLanguage(fileName: string): ProgrammingLanguage | undef
return ProgrammingLanguage.svelte;
case 'rs':
return ProgrammingLanguage.rust;
case 'py':
return ProgrammingLanguage.python;
default:
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions packages/elements/src/style/prism-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'prismjs/components/prism-java';
import 'prismjs/components/prism-scala';
import 'prismjs/components/prism-gherkin';
import 'prismjs/components/prism-rust';
import 'prismjs/components/prism-python';
// Markup and markup-templating are needed for php
import 'prismjs/components/prism-markup';
import 'prismjs/components/prism-markup-templating';
Expand Down
2 changes: 2 additions & 0 deletions packages/elements/test/unit/lib/code-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe(highlightCode.name, () => {
['foo.feature', ProgrammingLanguage.gherkin, 'Feature: foo'],
['foo.scala', ProgrammingLanguage.scala, 'object Foo { def main(args: Array[String]) = println("Hello, world!") }'],
['foo.rs', ProgrammingLanguage.rust, 'fn main() { println!("Hello, world!"); }'],
['foo.py', ProgrammingLanguage.python, 'a = 10'],
])(`should parse %s as %s`, (fileName, language, code) => {
const highlightedCode = highlightCode(code, fileName);
expect(highlightedCode).contains('<span'); // actual highlighting is not tested, in prism we trust
Expand Down Expand Up @@ -197,6 +198,7 @@ describe(determineLanguage.name, () => {
['php', ProgrammingLanguage.php],
['vue', ProgrammingLanguage.vue],
['feature', ProgrammingLanguage.gherkin],
['py', ProgrammingLanguage.python],
] as const)(`should recognize file.%s as language %s`, (extension, expected) => {
expect(determineLanguage(`file.${extension}`)).eq(expected);
});
Expand Down
Loading