Powered by AppSignal & Oban Pro

GitHub Flavored Markdown

books/mdex/mdex_test1.livemd

GitHub Flavored Markdown

Mix.install([
  {:mdex, "~> 0.8"},
  {:mdex_gfm, "~> 0.1"},
  {:kino, "~> 0.16"},
  {:req, "~> 0.5"}
])

Intro

GitHub Flavored Markdown (GFM) extends CommonMark with features commonly used in software documentation. This example shows how to enable GFM extensions like tables, task lists, autolinks, strikethrough, and emoji shortcodes.

Setup

markdown = """
# GitHub Flavored Markdown :eyes:

| Feature | Status |
| ------- | ------ |
| Fast | :white_check_mark: |
| GFM  | :white_check_mark: |

- [x] Task A
- [x] Task B
- [ ] Task C

```elixir
def deps do
  [
    {:mdex, "~> 0.8"}
  ]
end
```

Check out the spec at https://github.github.com/gfm
"""

You can either use the mdex_gfm plugin or set the options yourself. You can find either approaches below.

Plugin

MDEx.new(markdown: markdown)
|> MDExGFM.attach()
|> MDEx.to_html!(syntax_highlight: [formatter: {:html_inline, theme: "github_light"}])
|> Kino.HTML.new()

Manual

options = [
  extension: [
    alerts: true,
    autolink: true,
    footnotes: true,
    shortcodes: true,
    strikethrough: true,
    table: true,
    tagfilter: true,
    tasklist: true
  ],
  parse: [
    relaxed_autolinks: true,
    relaxed_tasklist_matching: true
  ],
  render: [
    github_pre_lang: true,
    full_info_string: true,
    unsafe: true
  ],
  syntax_highlight: [
    formatter: {:html_inline, theme: "github_light"}
  ]
]

markdown
|> MDEx.to_html!(options)
|> Kino.HTML.new()