Created
December 5, 2023 20:59
-
-
Save dmdboi/5bc2aba2ce8bef65579e2c2a1c591f63 to your computer and use it in GitHub Desktop.
Adonis 5 - Markdown renderer
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
<div class="markdown"> | |
{{ safe(markdown(post.content)) }} | |
</div> |
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
import View from '@ioc:Adonis/Core/View' | |
import showdown from 'showdown' | |
/* | |
|-------------------------------------------------------------------------- | |
| Preloaded File | |
|-------------------------------------------------------------------------- | |
| | |
| Any code written inside this file will be executed during the application | |
| boot. | |
| | |
*/ | |
View.global('markdown', (markdown: string) => { | |
const converter = new showdown.Converter() | |
const edge = View.getRenderer().renderRawSync(markdown) | |
return converter.makeHtml(edge) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm i showdown
node ace make:prldfile View
View.ts
code above to newly created file