-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support markdown for description
- Loading branch information
Showing
4 changed files
with
141 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/components/model/panels/left/DescriptionPreview.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { marked } from "marked"; | ||
import DOMPurify from "dompurify"; | ||
import Box from "@mui/material/Box"; | ||
import Typography from "@mui/material/Typography"; | ||
|
||
marked.use({ | ||
extensions: [ | ||
{ | ||
name: "heading", | ||
renderer({ text, depth }) { | ||
return `<h${depth + 1}>${text}</h${depth + 1}>`; | ||
}, | ||
}, | ||
{ | ||
name: "image", | ||
renderer(_) { | ||
return "Images are not supported"; | ||
}, | ||
}, | ||
{ | ||
name: "list", | ||
renderer(token) { | ||
const itemList = token.items.map((i) => { | ||
return ( | ||
"<li style='margin-bottom:0'>" + i.raw.replace(/\n+$/, "") + "</li>" | ||
); | ||
}); | ||
if (token.ordered) { | ||
return `<ol type="1">${itemList.join("\n")}</ol>`; | ||
} else { | ||
return `<ul>${itemList.join("\n")}</ul>`; | ||
} | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
export const DescriptionPreview = ({ | ||
description, | ||
showDescriptionTextField, | ||
readOnly, | ||
}) => { | ||
const sanitizedHtml = DOMPurify.sanitize(marked.parse(description)); | ||
|
||
if (readOnly) { | ||
return ( | ||
<> | ||
<Typography variant="body1">Description</Typography> | ||
<Box dangerouslySetInnerHTML={{ __html: sanitizedHtml }}></Box> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
<Typography variant="body1">Description</Typography> | ||
<Box | ||
onClick={showDescriptionTextField} | ||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }} | ||
></Box> | ||
</> | ||
); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters