diff options
author | Sascha <GlancingMind@outlook.com> | 2021-03-31 21:00:36 +0200 |
---|---|---|
committer | Sascha <GlancingMind@outlook.com> | 2021-04-07 19:29:52 +0200 |
commit | 637bce7ba73c6a0a3d898b9b5e7ad13dc992ee35 (patch) | |
tree | 1628e496ade1eda18350c9e8b85e77df97c92280 /webui/src/components/Content | |
parent | c7a441bad6a7ca247d955b63d2ba604435fdaab6 (diff) | |
download | git-bug-637bce7ba73c6a0a3d898b9b5e7ad13dc992ee35.tar.gz |
Fix and improve rendering of markdown elements
- Markdown will no be rendered
- Render text always below an image
- block quotes wont be just indented text
Diffstat (limited to 'webui/src/components/Content')
-rw-r--r-- | webui/src/components/Content/BlockQuoteTag.tsx | 21 | ||||
-rw-r--r-- | webui/src/components/Content/ImageTag.tsx | 9 | ||||
-rw-r--r-- | webui/src/components/Content/index.tsx | 10 |
3 files changed, 33 insertions, 7 deletions
diff --git a/webui/src/components/Content/BlockQuoteTag.tsx b/webui/src/components/Content/BlockQuoteTag.tsx new file mode 100644 index 00000000..18c34d8a --- /dev/null +++ b/webui/src/components/Content/BlockQuoteTag.tsx @@ -0,0 +1,21 @@ +import React from 'react'; + +import { makeStyles } from '@material-ui/core/styles'; + +const useStyles = makeStyles((theme) => ({ + tag: { + color: theme.palette.text.secondary, + borderLeftWidth: '0.5ch', + borderLeftStyle: 'solid', + borderLeftColor: theme.palette.text.secondary, + marginLeft: 0, + paddingLeft: '0.5rem', + }, +})); + +const BlockQuoteTag = (props: React.HTMLProps<HTMLPreElement>) => { + const classes = useStyles(); + return <blockquote className={classes.tag} {...props} />; +}; + +export default BlockQuoteTag; diff --git a/webui/src/components/Content/ImageTag.tsx b/webui/src/components/Content/ImageTag.tsx index 70ee1bc0..29b01da3 100644 --- a/webui/src/components/Content/ImageTag.tsx +++ b/webui/src/components/Content/ImageTag.tsx @@ -14,9 +14,12 @@ const ImageTag = ({ }: React.ImgHTMLAttributes<HTMLImageElement>) => { const classes = useStyles(); return ( - <a href={props.src} target="_blank" rel="noopener noreferrer nofollow"> - <img className={classes.tag} alt={alt} {...props} /> - </a> + <> + <a href={props.src} target="_blank" rel="noopener noreferrer nofollow"> + <img className={classes.tag} alt={alt} {...props} /> + </a> + <br /> + </> ); }; diff --git a/webui/src/components/Content/index.tsx b/webui/src/components/Content/index.tsx index 56e52e1e..75360bb6 100644 --- a/webui/src/components/Content/index.tsx +++ b/webui/src/components/Content/index.tsx @@ -4,23 +4,25 @@ import parse from 'remark-parse'; import remark2react from 'remark-react'; import unified from 'unified'; +import BlockQuoteTag from './BlockQuoteTag'; import ImageTag from './ImageTag'; import PreTag from './PreTag'; type Props = { markdown: string }; const Content: React.FC<Props> = ({ markdown }: Props) => { - const processor = unified() + const content = unified() .use(parse) .use(html) .use(remark2react, { remarkReactComponents: { img: ImageTag, pre: PreTag, + blockquote: BlockQuoteTag, }, - }); + }) + .processSync(markdown).result; - const contents: React.ReactNode = processor.processSync(markdown).contents; - return <>{contents}</>; + return <>{content}</>; }; export default Content; |