diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b140e5226..4ed668b487 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Handling of snapshot plugin dependencies ([#1384](https://github.com/scm-manager/scm-manager/pull/1384))
+- SyntaxHighlighting for GoLang ([#1386](https://github.com/scm-manager/scm-manager/pull/1386))
## [2.6.3] - 2020-10-16
### Fixed
diff --git a/scm-ui/ui-components/src/SyntaxHighlighter.stories.tsx b/scm-ui/ui-components/src/SyntaxHighlighter.stories.tsx
index 7f458e4784..16331dcfd2 100644
--- a/scm-ui/ui-components/src/SyntaxHighlighter.stories.tsx
+++ b/scm-ui/ui-components/src/SyntaxHighlighter.stories.tsx
@@ -43,7 +43,7 @@ storiesOf("SyntaxHighlighter", module)
))
.add("Go", () => (
-
+
))
.add("Javascript", () => (
diff --git a/scm-ui/ui-components/src/SyntaxHighlighter.tsx b/scm-ui/ui-components/src/SyntaxHighlighter.tsx
index 852335e161..b665041913 100644
--- a/scm-ui/ui-components/src/SyntaxHighlighter.tsx
+++ b/scm-ui/ui-components/src/SyntaxHighlighter.tsx
@@ -24,6 +24,7 @@
import React from "react";
import { PrismAsyncLight as ReactSyntaxHighlighter } from "react-syntax-highlighter";
+import { defaultLanguage, determineLanguage } from "./languages";
// eslint-disable-next-line no-restricted-imports
import highlightingTheme from "./syntax-highlighting";
@@ -33,27 +34,20 @@ type Props = {
showLineNumbers?: boolean;
};
-const defaultLanguage = "text";
-
class SyntaxHighlighter extends React.Component {
static defaultProps: Partial = {
language: defaultLanguage,
showLineNumbers: true
};
- getLanguage = () => {
- const { language } = this.props;
- if (language) {
- return language;
- }
- return defaultLanguage;
- };
-
render() {
- const { showLineNumbers } = this.props;
- const language = this.getLanguage();
+ const { showLineNumbers, language } = this.props;
return (
-
+
{this.props.value}
);
diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
index 2129da9f5e..3963db2a91 100644
--- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
+++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
@@ -39,7 +39,6 @@ exports[`Storyshots Annotate Default 1`] = `
}
>
-
- 1
-
+
+ 1
+
+
+
@@ -47680,7 +47695,6 @@ Deserunt officia esse aliquip consectetur duis ut labore laborum commodo aliquip
-
- 1
-
+
+ 1
+
+
+
+ 2
+
+
+
+ 3
+
+
+
+ 4
+
+
+
+ 5
+
+
+
+ 6
+
+
+
+ 7
+
+
+
+ 8
+
+
+
+ 9
+
+
+
+ 10
+
+
+
+ 11
+
+
+
+ 12
+
+
+
+ 13
+
+
+
+ 14
+
+
+
+ 15
+
+
+
+ 16
+
+
+
+ 17
+
+
+
+ 18
+
+
+
+ 19
+
+
+
+ 20
+
+
+
+ 21
+
+
+
+ 22
+
+
+
+ 23
+
+
+
-
- 2
-
-
- 3
-
[...]
-
- 4
-
-
- 5
-
-
-
- 6
-
- 7
-
-
- 8
-
[...]
-
- 9
-
-
- 10
-
-
-
- 11
-
-
- 12
-
-
- 13
-
-
- 14
-
-
- 15
-
-
- 16
-
-
- 17
-
-
- 18
-
-
- 19
-
- 20
-
-
- 21
-
[...]
-
- 22
-
-
- 23
-
-
- 1
-
+
+ 1
+
+
+
+ 2
+
+
+
+ 3
+
+
+
+ 4
+
+
+
+ 5
+
+
+
+ 6
+
+
+
+ 7
+
+
+
+ 8
+
+
+
+ 9
+
+
+
+ 10
+
+
+
+ 11
+
+
+
+ 12
+
+
+
+ 13
+
+
+
+ 14
+
+
+
+ 15
+
+
+
+ 16
+
+
+
+ 17
+
+
+
-
- 2
-
-
- 3
-
@@ -50198,21 +50152,6 @@ exports[`Storyshots SyntaxHighlighter Go 1`] = `
>
-
-
- 4
-
-
- 5
-
-
- 6
-
- 7
-
-
- 8
-
@@ -50409,21 +50288,6 @@ exports[`Storyshots SyntaxHighlighter Go 1`] = `
>
-
-
- 9
-
-
- 10
-
-
- 11
-
- 12
-
-
- 13
-
@@ -50900,21 +50704,6 @@ exports[`Storyshots SyntaxHighlighter Go 1`] = `
>
-
-
- 14
-
- 15
-
-
- 16
-
@@ -51174,21 +50933,6 @@ exports[`Storyshots SyntaxHighlighter Go 1`] = `
>
-
-
- 17
-
- 18
-
@@ -51265,7 +50994,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
}
>
-
- 1
-
+
+ 1
+
+
+
+ 2
+
+
+
+ 3
+
+
+
+ 4
+
+
+
+ 5
+
+
+
+ 6
+
+
+
+ 7
+
+
+
+ 8
+
+
+
+ 9
+
+
+
+ 10
+
+
+
+ 11
+
+
+
+ 12
+
+
+
+ 13
+
+
+
+ 14
+
+
+
+ 15
+
+
+
+ 16
+
+
+
+ 17
+
+
+
+ 18
+
+
+
+ 19
+
+
+
+ 20
+
+
+
+ 21
+
+
+
+ 22
+
+
+
+ 23
+
+
+
+ 24
+
+
+
+ 25
+
+
+
+ 26
+
+
+
+ 27
+
+
+
+ 28
+
+
+
+ 29
+
+
+
+ 30
+
+
+
+ 31
+
+
+
com
example
@@ -51356,38 +51312,8 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
-
- 2
-
-
- 3
-
@@ -51409,13 +51335,13 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
java
io
@@ -51461,21 +51387,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 4
java
io
@@ -51550,21 +51461,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 5
java
net
@@ -51640,38 +51536,8 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
-
- 6
-
-
- 7
-
@@ -51693,13 +51559,13 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
com
sun
net
httpserver
@@ -51777,21 +51643,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 8
com
sun
net
httpserver
@@ -51898,21 +51749,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 9
com
sun
net
httpserver
@@ -52020,38 +51856,8 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
-
- 10
-
-
- 11
-
@@ -52114,38 +51920,8 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
-
- 12
-
-
- 13
-
@@ -52303,21 +52079,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 14
-
-
- 15
-
-
- 16
-
-
- 17
-
-
- 18
-
- 19
-
-
- 20
-
@@ -52962,21 +52633,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
>
-
-
- 21
-
-
- 22
-
-
- 23
-
-
- 24
-
-
- 25
-
-
- 26
-
-
- 27
-
-
- 28
-
-
- 29
-
- 30
-
-
- 31
-
@@ -53774,21 +53280,6 @@ exports[`Storyshots SyntaxHighlighter Java 1`] = `
-
- 32
-
@@ -53828,7 +53319,6 @@ exports[`Storyshots SyntaxHighlighter Javascript 1`] = `
}
>
-
- 1
-
+
+ 1
+
+
+
+ 2
+
+
+
+ 3
+
+
+
+ 4
+
+
+
+ 5
+
+
+
+ 6
+
+
+
+ 7
+
+
+
-
- 2
-
-
- 3
-
@@ -54051,7 +53571,7 @@ exports[`Storyshots SyntaxHighlighter Javascript 1`] = `
req
-
-
- 4
@@ -54252,21 +53757,6 @@ exports[`Storyshots SyntaxHighlighter Javascript 1`] = `
>
-
-
- 5
-
-
- 6
-
-
- 7
-
- 8
-
@@ -54575,7 +54020,6 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
}
>
-
- 1
-
+
+ 1
+
+
+
+ 2
+
+
+
+ 3
+
+
+
+ 4
+
+
+
+ 5
+
+
+
+ 6
+
+
+
+ 7
+
+
+
+ 8
+
+
+
+ 9
+
+
+
+ 10
+
+
+
+ 11
+
+
+
+ 12
+
+
+
+ 13
+
+
+
+ 14
+
+
+
+ 15
+
+
+
+ 16
+
+
+
+ 17
+
+
+
+ 18
+
+
+
+ 19
+
+
+
+ 20
+
+
+
-
- 2
-
-
- 3
-
@@ -54727,38 +54292,8 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
-
- 4
-
-
- 5
-
@@ -54826,38 +54361,8 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
-
- 6
-
-
- 7
-
@@ -54928,21 +54433,6 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
>
-
-
- 8
-
-
- 9
-
-
- 10
-
-
- 11
-
-
- 12
-
- 13
-
-
- 14
-
@@ -55336,21 +54736,6 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
>
-
-
- 15
-
-
- 16
-
- 17
-
@@ -55584,21 +54939,6 @@ exports[`Storyshots SyntaxHighlighter Python 1`] = `
>
-
-
- 18
-
-
- 19
-
-
- 20
-
- 21
-
@@ -55817,7 +55112,6 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
}
>
com
example
@@ -55916,13 +55210,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
java
io
@@ -55990,13 +55284,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
java
io
@@ -56064,13 +55358,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
java
net
@@ -56140,13 +55434,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
com
sun
net
httpserver
@@ -56246,13 +55540,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
com
sun
net
httpserver
@@ -56352,13 +55646,13 @@ exports[`Storyshots SyntaxHighlighter Without line numbers 1`] = `
com
sun
net
httpserver
diff --git a/scm-ui/ui-components/src/languages.test.ts b/scm-ui/ui-components/src/languages.test.ts
new file mode 100644
index 0000000000..61a6214065
--- /dev/null
+++ b/scm-ui/ui-components/src/languages.test.ts
@@ -0,0 +1,52 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import { determineLanguage } from "./languages";
+
+describe("syntax highlighter", () => {
+ it("should return the language as it is", () => {
+ const java = determineLanguage("java");
+ expect(java).toBe("java");
+ });
+
+ it("should lower case the language", () => {
+ const java = determineLanguage("Java");
+ expect(java).toBe("java");
+ });
+
+ it("should return text if language is undefied", () => {
+ const lang = determineLanguage();
+ expect(lang).toBe("text");
+ });
+
+ it("should return text if language is an empty string", () => {
+ const lang = determineLanguage("");
+ expect(lang).toBe("text");
+ });
+
+ it("should use alias go for golang", () => {
+ const go = determineLanguage("golang");
+ expect(go).toBe("go");
+ });
+});
diff --git a/scm-ui/ui-components/src/languages.ts b/scm-ui/ui-components/src/languages.ts
new file mode 100644
index 0000000000..f895d9d946
--- /dev/null
+++ b/scm-ui/ui-components/src/languages.ts
@@ -0,0 +1,41 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+// this aliases are only to map from spotter detection to prismjs
+const languageAliases: { [key: string]: string } = {
+ golang: "go"
+};
+
+export const defaultLanguage = "text";
+
+export const determineLanguage = (language?: string) => {
+ if (!language) {
+ return defaultLanguage;
+ }
+ const lang = language.toLowerCase();
+ if (languageAliases[lang]) {
+ return languageAliases[lang];
+ }
+ return lang;
+};
diff --git a/scm-ui/ui-components/src/repos/TokenizedDiffView.tsx b/scm-ui/ui-components/src/repos/TokenizedDiffView.tsx
index dcd1d65616..26e1d36455 100644
--- a/scm-ui/ui-components/src/repos/TokenizedDiffView.tsx
+++ b/scm-ui/ui-components/src/repos/TokenizedDiffView.tsx
@@ -26,6 +26,7 @@ import styled from "styled-components";
// @ts-ignore we have no typings for react-diff-view
import { Diff, useTokenizeWorker } from "react-diff-view";
import { File } from "./DiffTypes";
+import { determineLanguage } from "../languages";
// styling for the diff tokens
// this must be aligned with th style, which is used in the SyntaxHighlighter component
@@ -86,17 +87,10 @@ type Props = {
className?: string;
};
-const determineLanguage = (file: File) => {
- if (file.language) {
- return file.language.toLowerCase();
- }
- return "text";
-};
-
const TokenizedDiffView: FC = ({ file, viewType, className, children }) => {
const { tokens } = useTokenizeWorker(tokenize, {
hunks: file.hunks,
- language: determineLanguage(file)
+ language: determineLanguage(file.language)
});
return (
diff --git a/scm-ui/ui-components/src/repos/annotate/Annotate.stories.tsx b/scm-ui/ui-components/src/repos/annotate/Annotate.stories.tsx
index 41345b2744..2da808c387 100644
--- a/scm-ui/ui-components/src/repos/annotate/Annotate.stories.tsx
+++ b/scm-ui/ui-components/src/repos/annotate/Annotate.stories.tsx
@@ -67,7 +67,7 @@ const commitImplementMain = {
};
const source: AnnotatedSource = {
- language: "go",
+ language: "golang",
lines: [
{
lineNumber: 1,
diff --git a/scm-ui/ui-components/src/repos/annotate/Annotate.tsx b/scm-ui/ui-components/src/repos/annotate/Annotate.tsx
index 9aeb36dd55..7ed489af25 100644
--- a/scm-ui/ui-components/src/repos/annotate/Annotate.tsx
+++ b/scm-ui/ui-components/src/repos/annotate/Annotate.tsx
@@ -35,6 +35,7 @@ import { DateInput } from "../../useDateFormatter";
import Popover from "./Popover";
import AnnotateLine from "./AnnotateLine";
import { Action } from "./actions";
+import { determineLanguage } from "../../languages";
type Props = {
source: AnnotatedSource;
@@ -147,7 +148,7 @@ const Annotate: FC = ({ source, repository, baseDate }) => {
{popover}