diff --git a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js index d1b6dadb61..8c0d27661b 100644 --- a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js +++ b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.js @@ -86,10 +86,29 @@ class SourcecodeViewer extends React.Component { } export function getLanguage(contentType: string) { - return contentType.substring( + const language = contentType.substring( contentType.indexOf("/") + 1, contentType.length ); + + let languageType; + + switch (language) { + case "x-go": + languageType = "go"; + break; + case "x-java-source": + languageType = "java"; + break; + case "x-web-markdown": + languageType = "markdown"; + break; + default: + languageType = language; + } + + console.log(languageType); + return languageType; } export function getContent(url: string) { diff --git a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js index a318b8854a..a33dba454b 100644 --- a/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js +++ b/scm-ui/src/repos/sources/components/content/SourcecodeViewer.test.js @@ -20,11 +20,20 @@ describe("get content", () => { }); }); -describe("get correct language Type", () => { +describe("get correct language type", () => { it("should return javascript", () => { expect(getLanguage("application/javascript")).toBe("javascript"); }); it("should return text", () => { expect(getLanguage("text/plain")).toBe("plain"); }); + it("should return go", () => { + expect(getLanguage("text/x-go")).toBe("go"); + }); + it("should return java", () => { + expect(getLanguage("text/x-java-source")).toBe("java"); + }); + it("should return markdown", () => { + expect(getLanguage("text/x-web-markdown")).toBe("markdown"); + }); }); diff --git a/scm-ui/src/repos/sources/containers/Content.js b/scm-ui/src/repos/sources/containers/Content.js index a9f2e46df9..23e33c407d 100644 --- a/scm-ui/src/repos/sources/containers/Content.js +++ b/scm-ui/src/repos/sources/containers/Content.js @@ -152,6 +152,7 @@ export function getContentType(url: string, state: any) { return apiClient .head(url) .then(response => { + console.log(response.headers.get("Content-Type")); return { type: response.headers.get("Content-Type") }; }) .catch(err => {