mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
Add a Markdown component and a SyntaxHighlighter
This commit is contained in:
46
scm-ui-components/packages/ui-components/src/MarkdownView.js
Normal file
46
scm-ui-components/packages/ui-components/src/MarkdownView.js
Normal file
@@ -0,0 +1,46 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import SyntaxHighlighter from "./SyntaxHighlighter";
|
||||
import Markdown from "react-markdown/with-html";
|
||||
import {binder} from "@scm-manager/ui-extensions";
|
||||
|
||||
type Props = {
|
||||
content: string,
|
||||
className : string,
|
||||
renderContext? : Object,
|
||||
renderers?: Object,
|
||||
};
|
||||
|
||||
class MarkdownView extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const {content, className, renderers, renderContext} = this.props;
|
||||
|
||||
const rendererFactory = binder.getExtension("markdown-renderer-factory");
|
||||
let rendererList = renderers;
|
||||
|
||||
if (rendererFactory){
|
||||
rendererList = rendererFactory(renderContext);
|
||||
}
|
||||
|
||||
if (!rendererList){
|
||||
rendererList = {};
|
||||
}
|
||||
|
||||
if (!rendererList.code){
|
||||
rendererList.code = SyntaxHighlighter;
|
||||
}
|
||||
|
||||
return (
|
||||
<Markdown
|
||||
className={className}
|
||||
skipHtml={true}
|
||||
escapeHtml={true}
|
||||
source={content}
|
||||
renderers={rendererList}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default MarkdownView;
|
||||
@@ -0,0 +1,26 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import ReactSyntaxHighlighter from "react-syntax-highlighter";
|
||||
import { arduinoLight } from "react-syntax-highlighter/dist/styles/hljs";
|
||||
|
||||
type Props = {
|
||||
language: string,
|
||||
value: string
|
||||
};
|
||||
|
||||
class SyntaxHighlighter extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ReactSyntaxHighlighter
|
||||
showLineNumbers="false"
|
||||
language={this.props.language}
|
||||
style={arduinoLight}
|
||||
>
|
||||
{this.props.value}
|
||||
</ReactSyntaxHighlighter>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default SyntaxHighlighter;
|
||||
@@ -1,20 +0,0 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
content: string
|
||||
};
|
||||
|
||||
class MarkdownView extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const {content } = this.props;
|
||||
return (
|
||||
<div>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default MarkdownView;
|
||||
@@ -11,5 +11,4 @@ export { default as Textarea } from "./Textarea.js";
|
||||
export { default as PasswordConfirmation } from "./PasswordConfirmation.js";
|
||||
export { default as LabelWithHelpIcon } from "./LabelWithHelpIcon.js";
|
||||
export { default as DropDown } from "./DropDown.js";
|
||||
export { default as MarkdownView } from "./MarkdownView.js";
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ export { default as Tooltip } from "./Tooltip";
|
||||
export { getPageFromMatch } from "./urls";
|
||||
export { default as Autocomplete} from "./Autocomplete";
|
||||
export { default as BranchSelector } from "./BranchSelector";
|
||||
export { default as MarkdownView } from "./MarkdownView";
|
||||
export { default as SyntaxHighlighter } from "./SyntaxHighlighter";
|
||||
|
||||
export { apiClient } from "./apiclient.js";
|
||||
export * from "./errors";
|
||||
|
||||
Reference in New Issue
Block a user