forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Books now render Markdown, fixing paper importing (tgstation#74902)
## About The Pull Request Books didn't render markdown and instead just dumped the raw contents, (after a html encode), into the window. Changes them to use tgui and support markdown rendering. ## Why It's Good For The Game Books should should look the same as the paper used to make them. ## Changelog :cl: fix: Book's no longer take your formatting and throw it out the window. refactor: Book display and rendering /:cl: --------- Co-authored-by: GoldenAlpharex <[email protected]> Co-authored-by: Mothblocks <[email protected]>
- Loading branch information
1 parent
88cb28b
commit 548fc4a
Showing
4 changed files
with
95 additions
and
18 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
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
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
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,42 @@ | ||
import { marked } from 'marked'; | ||
import { useBackend } from '../backend'; | ||
import { Window } from '../layouts'; | ||
import { sanitizeText } from '../sanitize'; | ||
|
||
type MarkdownViewerData = { | ||
title: string; | ||
content: string; | ||
author: string; | ||
}; | ||
|
||
export const MarkdownViewer = (_: any, context: any) => { | ||
const { data } = useBackend<MarkdownViewerData>(context); | ||
return ( | ||
<Window theme="paper" title={data.title}> | ||
<Window.Content scrollable backgroundColor={'#FFFFFF'}> | ||
<MarkdownRenderer content={data.content} /> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; | ||
|
||
type MarkdownRendererProps = { | ||
content: string; | ||
sanitize?: boolean; | ||
}; | ||
|
||
export const MarkdownRenderer = (props: MarkdownRendererProps) => { | ||
let { content, sanitize } = props; | ||
|
||
content = marked(content); | ||
if (sanitize) { | ||
content = sanitizeText(content, /* advHtml = */ false); | ||
} | ||
|
||
// eslint-disable-next-line react/no-danger | ||
return <div dangerouslySetInnerHTML={{ __html: content }} />; | ||
}; | ||
|
||
MarkdownRenderer.defaultProps = { | ||
sanitize: true, | ||
}; |