mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
add markdown styling
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import SyntaxHighlighter from "./SyntaxHighlighter";
|
|
||||||
import Markdown from "react-markdown/with-html";
|
|
||||||
import {binder} from "@scm-manager/ui-extensions";
|
|
||||||
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
|
|
||||||
import { withRouter } from "react-router-dom";
|
import { withRouter } from "react-router-dom";
|
||||||
|
import injectSheet from "react-jss";
|
||||||
|
import Markdown from "react-markdown/with-html";
|
||||||
|
import { binder } from "@scm-manager/ui-extensions";
|
||||||
|
import SyntaxHighlighter from "./SyntaxHighlighter";
|
||||||
|
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
content: string,
|
content: string,
|
||||||
@@ -14,11 +14,34 @@ type Props = {
|
|||||||
enableAnchorHeadings: boolean,
|
enableAnchorHeadings: boolean,
|
||||||
|
|
||||||
// context props
|
// context props
|
||||||
|
classes: any,
|
||||||
location: any
|
location: any
|
||||||
};
|
};
|
||||||
|
|
||||||
class MarkdownView extends React.Component<Props> {
|
const styles = {
|
||||||
|
markdown: {
|
||||||
|
"& > .content": {
|
||||||
|
"& > h1, h2, h3, h4, h5, h6": {
|
||||||
|
margin: "0.5rem 0",
|
||||||
|
fontSize: "0.9rem"
|
||||||
|
},
|
||||||
|
"& > h1": {
|
||||||
|
fontWeight: "700"
|
||||||
|
},
|
||||||
|
"& > h2": {
|
||||||
|
fontWeight: "600"
|
||||||
|
},
|
||||||
|
"& > h3, h4, h5, h6": {
|
||||||
|
fontWeight: "500"
|
||||||
|
},
|
||||||
|
"& strong": {
|
||||||
|
fontWeight: "500"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class MarkdownView extends React.Component<Props> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
enableAnchorHeadings: false
|
enableAnchorHeadings: false
|
||||||
};
|
};
|
||||||
@@ -45,16 +68,22 @@ class MarkdownView extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {content, renderers, renderContext, enableAnchorHeadings} = this.props;
|
const {
|
||||||
|
content,
|
||||||
|
renderers,
|
||||||
|
renderContext,
|
||||||
|
enableAnchorHeadings,
|
||||||
|
classes
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
const rendererFactory = binder.getExtension("markdown-renderer-factory");
|
const rendererFactory = binder.getExtension("markdown-renderer-factory");
|
||||||
let rendererList = renderers;
|
let rendererList = renderers;
|
||||||
|
|
||||||
if (rendererFactory){
|
if (rendererFactory) {
|
||||||
rendererList = rendererFactory(renderContext);
|
rendererList = rendererFactory(renderContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rendererList){
|
if (!rendererList) {
|
||||||
rendererList = {};
|
rendererList = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +91,12 @@ class MarkdownView extends React.Component<Props> {
|
|||||||
rendererList.heading = MarkdownHeadingRenderer;
|
rendererList.heading = MarkdownHeadingRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rendererList.code){
|
if (!rendererList.code) {
|
||||||
rendererList.code = SyntaxHighlighter;
|
rendererList.code = SyntaxHighlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={el => (this.contentRef = el)}>
|
<div className={classes.markdown} ref={el => (this.contentRef = el)}>
|
||||||
<Markdown
|
<Markdown
|
||||||
className="content"
|
className="content"
|
||||||
skipHtml={true}
|
skipHtml={true}
|
||||||
@@ -80,4 +109,4 @@ class MarkdownView extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(MarkdownView);
|
export default injectSheet(styles)(withRouter(MarkdownView));
|
||||||
|
|||||||
Reference in New Issue
Block a user