mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Added ErrorBoundary to MarkdownView to avoid invalid markdown crashes the entire page
This commit is contained in:
@@ -5,19 +5,24 @@ import styled from "styled-components";
|
|||||||
|
|
||||||
import TestPage from "./__resources__/test-page.md";
|
import TestPage from "./__resources__/test-page.md";
|
||||||
import MarkdownWithoutLang from "./__resources__/markdown-without-lang.md";
|
import MarkdownWithoutLang from "./__resources__/markdown-without-lang.md";
|
||||||
|
import MarkdownXmlCodeBlock from "./__resources__/markdown-xml-codeblock.md";
|
||||||
|
import MarkdownInlineXml from "./__resources__/markdown-inline-xml.md";
|
||||||
|
import Title from "./layout/Title";
|
||||||
|
import { Subtitle } from "./layout";
|
||||||
|
|
||||||
const Spacing = styled.div`
|
const Spacing = styled.div`
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
storiesOf("MarkdownView", module)
|
storiesOf("MarkdownView", module)
|
||||||
.add("Default", () => (
|
.addDecorator(story => <Spacing>{story()}</Spacing>)
|
||||||
<Spacing>
|
.add("Default", () => <MarkdownView content={TestPage} skipHtml={false} />)
|
||||||
<MarkdownView content={TestPage} skipHtml={false} />
|
.add("Code without Lang", () => <MarkdownView content={MarkdownWithoutLang} skipHtml={false} />)
|
||||||
</Spacing>
|
.add("Xml Code Block", () => <MarkdownView content={MarkdownXmlCodeBlock} />)
|
||||||
))
|
.add("Inline Xml", () => (
|
||||||
.add("Code without Lang", () => (
|
<>
|
||||||
<Spacing>
|
<Title title="Inline Xml" />
|
||||||
<MarkdownView content={MarkdownWithoutLang} skipHtml={false} />
|
<Subtitle subtitle="Inline xml outside of a code block is not supported" />
|
||||||
</Spacing>
|
<MarkdownView content={MarkdownInlineXml} />
|
||||||
|
</>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { withRouter, RouteComponentProps } from "react-router-dom";
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Markdown from "react-markdown/with-html";
|
import Markdown from "react-markdown/with-html";
|
||||||
import { binder } from "@scm-manager/ui-extensions";
|
import { binder } from "@scm-manager/ui-extensions";
|
||||||
|
import ErrorBoundary from "./ErrorBoundary";
|
||||||
import SyntaxHighlighter from "./SyntaxHighlighter";
|
import SyntaxHighlighter from "./SyntaxHighlighter";
|
||||||
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
|
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ class MarkdownView extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<ErrorBoundary>
|
||||||
<div ref={el => (this.contentRef = el)}>
|
<div ref={el => (this.contentRef = el)}>
|
||||||
<Markdown
|
<Markdown
|
||||||
className="content"
|
className="content"
|
||||||
@@ -73,6 +75,7 @@ class MarkdownView extends React.Component<Props> {
|
|||||||
renderers={rendererList}
|
renderers={rendererList}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export default `# Xml in Markdown
|
||||||
|
<project [...]>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
</project>`;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
export default `# Xml Code Block in Markdown
|
||||||
|
\`\`\`xml
|
||||||
|
<project [...]>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
</project>
|
||||||
|
\`\`\``;
|
||||||
Reference in New Issue
Block a user