Skip to content

Instantly share code, notes, and snippets.

@dmdboi
Created December 5, 2023 20:59
Show Gist options
  • Save dmdboi/5bc2aba2ce8bef65579e2c2a1c591f63 to your computer and use it in GitHub Desktop.
Save dmdboi/5bc2aba2ce8bef65579e2c2a1c591f63 to your computer and use it in GitHub Desktop.
Adonis 5 - Markdown renderer
<div class="markdown">
{{ safe(markdown(post.content)) }}
</div>
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)
})
@dmdboi
Copy link
Author

dmdboi commented Dec 5, 2023

  1. Install showdown via npm i showdown
  2. Create preload file with node ace make:prldfile View
  3. Add View.ts code above to newly created file
  4. Profit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment