fix markdown code block without language attribute

This commit is contained in:
Sebastian Sdorra
2019-10-25 15:06:34 +02:00
parent 3522daae21
commit 162dbc421f
5 changed files with 69 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import styled from "styled-components";
import { MemoryRouter } from "react-router-dom"; import { MemoryRouter } from "react-router-dom";
import TestPage from "./__resources__/test-page.md"; import TestPage from "./__resources__/test-page.md";
import MarkdownWithoutLang from "./__resources__/markdown-without-lang.md";
const Spacing = styled.div` const Spacing = styled.div`
padding: 2em; padding: 2em;
@@ -16,4 +17,9 @@ storiesOf("MarkdownView", module)
<Spacing> <Spacing>
<MarkdownView content={TestPage} skipHtml={false} /> <MarkdownView content={TestPage} skipHtml={false} />
</Spacing> </Spacing>
))
.add("Code without Lang", () => (
<Spacing>
<MarkdownView content={MarkdownWithoutLang} skipHtml={false} />
</Spacing>
)); ));

View File

@@ -5,14 +5,29 @@ import { LightAsync as ReactSyntaxHighlighter } from "react-syntax-highlighter";
import { arduinoLight } from "react-syntax-highlighter/dist/cjs/styles/hljs"; import { arduinoLight } from "react-syntax-highlighter/dist/cjs/styles/hljs";
type Props = { type Props = {
language: string; language?: string;
value: string; value: string;
}; };
const defaultLanguage = "text";
class SyntaxHighlighter extends React.Component<Props> { class SyntaxHighlighter extends React.Component<Props> {
static defaultProps: Partial<Props> = {
language: defaultLanguage
};
getLanguage = () => {
const { language } = this.props;
if (language) {
return language;
}
return defaultLanguage;
};
render() { render() {
const language = this.getLanguage();
return ( return (
<ReactSyntaxHighlighter showLineNumbers={false} language={this.props.language} style={arduinoLight}> <ReactSyntaxHighlighter showLineNumbers={false} language={language} style={arduinoLight}>
{this.props.value} {this.props.value}
</ReactSyntaxHighlighter> </ReactSyntaxHighlighter>
); );

View File

@@ -0,0 +1,7 @@
export default `
Here is markdown with code, but without Language.
\`\`\`
Code without Language!
\`\`\`
`;

View File

@@ -484,6 +484,39 @@ exports[`Storyshots Logo Default 1`] = `
</div> </div>
`; `;
exports[`Storyshots MarkdownView Code without Lang 1`] = `
<div
className="sc-EHOje lbpDzp"
>
<div
className="sc-ifAKCX frmxmY"
>
<div
className="content"
>
<p>
Here is markdown with code, but without Language.
</p>
<pre
style={
Object {
"background": "#FFFFFF",
"color": "#434f54",
"display": "block",
"overflowX": "auto",
"padding": "0.5em",
}
}
>
<code>
Code without Language!
</code>
</pre>
</div>
</div>
</div>
`;
exports[`Storyshots MarkdownView Default 1`] = ` exports[`Storyshots MarkdownView Default 1`] = `
<div <div
className="sc-EHOje lbpDzp" className="sc-EHOje lbpDzp"

View File

@@ -3595,6 +3595,11 @@ babel-code-frame@^6.22.0:
esutils "^2.0.2" esutils "^2.0.2"
js-tokens "^3.0.2" js-tokens "^3.0.2"
babel-core@7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
babel-eslint@^10.0.3: babel-eslint@^10.0.3:
version "10.0.3" version "10.0.3"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a"
@@ -7235,7 +7240,7 @@ gitconfiglocal@^1.0.0:
dependencies: dependencies:
ini "^1.3.2" ini "^1.3.2"
gitdiff-parser@^0.1.2: gitdiff-parser@^0.1.2, "gitdiff-parser@https://github.com/scm-manager/gitdiff-parser#6baa7278824ecd17a199d842ca720d0453f68982":
version "0.1.2" version "0.1.2"
resolved "https://github.com/scm-manager/gitdiff-parser#6baa7278824ecd17a199d842ca720d0453f68982" resolved "https://github.com/scm-manager/gitdiff-parser#6baa7278824ecd17a199d842ca720d0453f68982"