diff --git a/fe/src/components/common/Markdown.tsx b/fe/src/components/common/Markdown.tsx new file mode 100644 index 000000000..7e8a033a4 --- /dev/null +++ b/fe/src/components/common/Markdown.tsx @@ -0,0 +1,67 @@ +import styled from 'styled-components'; + +const Markdown = ({ string }: { string: string }) => { + const checkHeader = (str: string) => { + const check = str.match(/^[\#]+ |^[\>] /gi); + if (check) + return { key: check[0], str: str.replace(/^[\#]+ |^[\>] /gi, '') }; + else return { key: null, str: str }; + }; + + const headerParser = (key: string | null, str: string | JSX.Element) => { + switch (key) { + case '# ': + return

{str}

; + case '## ': + return

{str}

; + case '### ': + return

{str}

; + case '#### ': + return

{str}

; + case '##### ': + return
{str}
; + case '###### ': + return
{str}
; + case '> ': + return {str}; + case null: + return {str}; + } + }; + + const emphasisParser = (str: string) => { + const arr = str.match(/(\*{2,5})(.*?)\1/g); + let res = []; + let temp; + if (!arr) return str; + else { + temp = arr.map((str) => {str.slice(2, -2)}); + } + let sp = str.replace(/(\*{2,5})(.*?)\1/g, '\n').split('\n'); + let j =0; + for(let i =0; i{res.map((v) => v)}; + }; + + return ( + <> + {string + .split('\n') + .map((v) => headerParser(checkHeader(v).key, emphasisParser(checkHeader(v).str)))} + + ); +}; + +export default Markdown; + +const QuotationStyle = styled.div` + border-left: 4px solid #39a6a3; + background-color: #deedf0; + width: 100%; + padding: 1rem; +`; diff --git a/fe/src/components/new-issue/NewIssueLeft.tsx b/fe/src/components/new-issue/NewIssueLeft.tsx index 197c41e04..14b324ea6 100644 --- a/fe/src/components/new-issue/NewIssueLeft.tsx +++ b/fe/src/components/new-issue/NewIssueLeft.tsx @@ -7,6 +7,7 @@ import CommentTextarea from 'components/common/CommentTextarea'; import IssueTitleInput from 'components/common/IssueTitleInput'; import { newIssuesContentAtom } from 'stores/issueStore'; +import Markdown from 'components/common/Markdown'; const NewIssueLeft = () => { const [newIssuesContent, setNewIssuesContent] =