-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure Markdown formatted to HTML
- Loading branch information
Showing
5 changed files
with
52 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
import showdown from 'showdown'; | ||
|
||
export const markdownToHTML = (html: string) => { | ||
export const markdownToHTML = ( | ||
html: string, | ||
trimWhitespace: boolean = false | ||
) => { | ||
const converter = new showdown.Converter({ | ||
noHeaderId: true, | ||
disableForced4SpacesIndentedSublists: true, | ||
simpleLineBreaks: true, | ||
}); | ||
converter.setFlavor('github'); | ||
return converter.makeHtml(html); | ||
|
||
let processedHtml = html; | ||
|
||
if (trimWhitespace) { | ||
processedHtml = html.replace(/^\s+|\s+$/g, ''); | ||
} | ||
|
||
const htmlWithoutPreTags = converter | ||
.makeHtml(processedHtml) | ||
.replace(/<pre><code>|<\/code><\/pre>/g, ''); | ||
return htmlWithoutPreTags; | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
# Simple deck | ||
# Simple Deck | ||
|
||
- What is the capital of Kenya? | ||
|
||
Nairobi | ||
|
||
- What is the capital of Norway | ||
|
||
Oslo | ||
|
||
- What is the capital of Sweden | ||
|
||
Stockholm | ||
|
||
Stockholm | ||
|
||
- What is the capital of Finland | ||
|
||
**Helsinki** |