Skip to content

Commit 95de2af

Browse files
authored
feat: update to MDEx 0.11 (#172)
1 parent a2a1cbf commit 95de2af

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
lines changed

lib/tableau.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ defmodule Tableau do
99
* `:url` - string (required) - The URL of your website.
1010
* `:converters` - mapping of file extensions to converter module. Defaults to `[md: Tableau.MDExConverter]`
1111
* `:markdown` - keyword
12-
* `:mdex` - keyword - Options to pass to `MDEx.to_html/2`. See `MDEx` documentation for list of options, as options listed here are non-standard and specific to Tableau.
13-
* `:plugins` - module list - MDEx plugin modules to attach to the processing pipeline
12+
* `:mdex` - keyword - Options to pass to `MDEx.to_html/2`
1413
* `:slug` - keyword - Options to pass to `Slug.slugify/2`
1514
1615
### Example
@@ -63,5 +62,9 @@ defmodule Tableau do
6362
6463
Will use the globally configured options, but you can also pass it overrides.
6564
"""
66-
defdelegate markdown(content, overrides \\ []), to: Tableau.MDExConverter
65+
def markdown(content, overrides \\ []) do
66+
{:ok, config} = Tableau.Config.get()
67+
68+
MDEx.to_html!(content, Keyword.merge(config.markdown[:mdex], overrides))
69+
end
6770
end
Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,8 @@
11
defmodule Tableau.MDExConverter do
22
@moduledoc """
3-
Converter to parse markdown content with `MDEx` with support for MDEx plugins.
3+
Converter to parse markdown content with `MDEx`
44
"""
5-
6-
@doc """
7-
Convert markdown content to HTML using `MDEx.to_html!/2`.
8-
9-
Will use the globally configured options, but you can also pass it overrides.
10-
"""
11-
def markdown(content, overrides \\ []) do
12-
{:ok, config} = Tableau.Config.get()
13-
14-
{plugins, mdex_config} =
15-
config.markdown[:mdex]
16-
|> Keyword.merge(overrides)
17-
|> Keyword.pop(:plugins, [])
18-
19-
render!(content, mdex_config, plugins)
20-
end
21-
225
def convert(_filepath, _front_matter, body, %{site: %{config: config}}) do
23-
{plugins, mdex_config} = Keyword.pop(config.markdown[:mdex], :plugins, [])
24-
render!(body, mdex_config, plugins)
25-
end
26-
27-
defp render!(content, mdex_config, plugins) do
28-
mdex_config
29-
|> Keyword.put(:markdown, content)
30-
|> MDEx.new()
31-
|> attach_plugins(plugins)
32-
|> MDEx.to_html!()
33-
end
34-
35-
defp attach_plugins(mdex, plugins) do
36-
Enum.reduce(plugins, mdex, fn mod, mdex ->
37-
Code.ensure_loaded!(mod)
38-
mod.attach(mdex)
39-
end)
6+
MDEx.to_html!(body, config.markdown[:mdex])
407
end
418
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule Tableau.MixProject do
3737
{:date_time_parser, "~> 1.2"},
3838
{:html_entities, "~> 0.5.2"},
3939
{:libgraph, "~> 0.16.0"},
40-
{:mdex, "~> 0.10.0"},
40+
{:mdex, "~> 0.11.1"},
4141
{:schematic, "~> 0.5.1"},
4242
{:slugify, "~> 1.3"},
4343
{:tz, "~> 0.28.1"},

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
"autumn": {:hex, :autumn, "0.5.7", "f6bfdc30d3f8d5e82ba5648489db7a7b6b7479d7be07a8288d4db2437434e26d", [:mix], [{:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:rustler, "~> 0.29", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.6", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "d272bfddeeea863420a8eb994d42af219ca5391191dd765bf045fbacf56a28d1"},
2+
"autumn": {:hex, :autumn, "0.6.0", "56cba6145da885262ef705e6e7a83d981e1f756d629a6d0e10b79a79243b702b", [:mix], [{:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:rustler, "~> 0.29", [hex: :rustler, repo: "hexpm", optional: false]}, {:rustler_precompiled, "~> 0.6", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "d9f7bad90b462e2e3ae3ce3a6d0dcd128230fec2a276cba0af18ce26165b54ce"},
33
"bandit": {:hex, :bandit, "1.5.7", "6856b1e1df4f2b0cb3df1377eab7891bec2da6a7fd69dc78594ad3e152363a50", [:mix], [{:hpax, "~> 1.0.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "f2dd92ae87d2cbea2fa9aa1652db157b6cba6c405cb44d4f6dd87abba41371cd"},
44
"castore": {:hex, :castore, "1.0.17", "4f9770d2d45fbd91dcf6bd404cf64e7e58fed04fadda0923dc32acca0badffa2", [:mix], [], "hexpm", "12d24b9d80b910dd3953e165636d68f147a31db945d2dcb9365e441f8b5351e5"},
55
"date_time_parser": {:hex, :date_time_parser, "1.2.0", "3d5a816b91967f51e0f94dcb16a34b2cb780f22cd48931779e81d72f7d3eadb1", [:mix], [{:kday, "~> 1.0", [hex: :kday, repo: "hexpm", optional: false]}], "hexpm", "0cf09ada9f42c0b3bfba02dc0ea2e4b4d2f543d9d2bf99b831a29e6b4a4160e5"},
@@ -15,7 +15,7 @@
1515
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
1616
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
1717
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
18-
"mdex": {:hex, :mdex, "0.10.0", "eae4d3bd4c0b77d6d959146a2d6faaec045686548ad1468630130095dbd93def", [:mix], [{:autumn, ">= 0.5.4", [hex: :autumn, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:rustler, "~> 0.32", [hex: :rustler, repo: "hexpm", optional: false]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "6ad76e32056c44027fe985da7da506e033b07037896d1f130f7d5c332b0d0ac0"},
18+
"mdex": {:hex, :mdex, "0.11.2", "7b01f784f38b0dfea92af164b8d1dae6f31f77e344da821b852be7bd8cd67484", [:mix], [{:autumn, ">= 0.6.0", [hex: :autumn, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:rustler, "~> 0.32", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "3a9d3f7049be6e37793cbe533bc6eea2e4df572aca32a67a857a2e8921964c00"},
1919
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
2020
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
2121
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},

0 commit comments

Comments
 (0)