Skip to content

Commit e4d496c

Browse files
authored
Fix a bug where markdown files fail to render in the diff view. (#1202)
Motivation: Prism raises an exception if a markdown file is specified in the commit diff view. Because the markdown syntax is not imported from `'prismjs/components/*`. ```js framework-0e8d27528ba61906.js:9 Error: The language "markdown" has no grammar. at Object.highlight (1809-d263923ea021c688.js:8:3755) at [[...path]]-3633ecc2aa697c21.js:1:2753 at Object.renderContent ([[...path]]-3633ecc2aa697c21.js:1:2844) ... ``` Modifications: - Support more widely used languages by declaring `prismjs/components/<lang>` - Fall back to the plantext mode if `Prism` raises an exception. - Minor) Move Java files for test servers to `webapp/javaTest` for easier discovery. Result: Markdown files are now correctly rendered in the diff view. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Expanded syntax highlighting with support for JSON5, Markdown, Python, Sass, XML, and Docker formats. * **Bug Fixes** * Added a fallback to render plain text if syntax highlighting fails. * **Chores** * Adjusted test source locations used by builds. * Added an automated task to install browser testing tooling. * Updated style-check suppressions to include additional internal and test-related paths. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1a5f246 commit e4d496c

File tree

10 files changed

+29
-8
lines changed

10 files changed

+29
-8
lines changed

settings/checkstyle/checkstyle-suppressions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
<suppressions>
77
<!-- Suppress Javadoc-related checks in non-public code. -->
8-
<suppress checks="MissingJavadocPackage|MissingJavadocType|MissingJavadocMethod" files="[\\/](examples|internal|it|jmh|test)[\\/]" />
9-
<suppress checks="JavadocPackage" files="[\\/](examples|it|jmh|test)[\\/]" />
8+
<suppress checks="MissingJavadocPackage|MissingJavadocType|MissingJavadocMethod" files="[\\/](examples|internal|it|jmh|test|javaTest)[\\/]" />
9+
<suppress checks="JavadocPackage" files="[\\/](examples|it|jmh|test|javaTest)[\\/]" />
1010
<!-- Suppress all checks in generated sources. -->
1111
<suppress checks=".*" files="[\\/]gen-src[\\/]" />
1212
<!-- Suppress UncommentedMain for the server entry point -->

webapp/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ dependencies {
2020
testImplementation libs.shiro.core
2121
}
2222

23+
sourceSets {
24+
test {
25+
java {
26+
srcDir 'javaTest/java'
27+
}
28+
resources {
29+
srcDir 'javaTest/resources'
30+
}
31+
}
32+
}
33+
2334
task installPlayWright(type: NpmTask) {
2435
dependsOn tasks.npmInstall
2536
args = ['run', 'playwright:install']
File renamed without changes.

webapp/src/dogma/common/components/DiffView.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import { extensionToLanguageMap } from 'dogma/common/components/editor/FileEdito
88
import Prism from 'prismjs';
99
// Load the language needed
1010
import 'prismjs/components/prism-json';
11+
import 'prismjs/components/prism-json5';
1112
import 'prismjs/components/prism-javascript';
1213
import 'prismjs/components/prism-yaml';
1314
import 'prismjs/components/prism-toml';
15+
import 'prismjs/components/prism-markdown';
16+
import 'prismjs/components/prism-python';
17+
import 'prismjs/components/prism-sass';
18+
import 'prismjs/components/prism-xml-doc';
19+
import 'prismjs/components/prism-docker';
1420
import 'prismjs/themes/prism.css';
1521

1622
function normalize(file: FileDto[]): [string, string][] {
@@ -60,12 +66,16 @@ function highlightSyntax(path: string, str: string): React.JSX.Element {
6066
return <pre style={{ display: 'inline' }}>{str}</pre>;
6167
}
6268

63-
return (
64-
<pre
65-
style={{ display: 'inline' }}
66-
dangerouslySetInnerHTML={{ __html: Prism.highlight(str, Prism.languages[language], language) }}
67-
/>
68-
);
69+
try {
70+
return (
71+
<pre
72+
style={{ display: 'inline' }}
73+
dangerouslySetInnerHTML={{ __html: Prism.highlight(str, Prism.languages[language], language) }}
74+
/>
75+
);
76+
} catch (e) {
77+
return <pre style={{ display: 'inline' }}>{str}</pre>;
78+
}
6979
}
7080

7181
export type DiffMode = 'Split' | 'Unified';

0 commit comments

Comments
 (0)