Skip to content

Commit dd0b230

Browse files
authored
Refactor plugin resolution
Refactor `MDExConverter.markdown/2` and `MDExConverter.convert/4` functions to use Keyword.pop for plugins. `MDExConverter.markdown/2` no longer tries to *merge* `:plugins`.
1 parent 1666e2a commit dd0b230

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

lib/tableau/converters/mdex_converter.ex

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,19 @@ defmodule Tableau.MDExConverter do
1111
def markdown(content, overrides \\ []) do
1212
{:ok, config} = Tableau.Config.get()
1313

14-
{plugins, mdex_config} = resolve_plugins(config, overrides)
14+
{plugins, mdex_config} =
15+
config.markdown[:mdex]
16+
|> Keyword.merge(overrides)
17+
|> Keyword.pop(:plugins, [])
1518

1619
render!(content, mdex_config, plugins)
1720
end
1821

1922
def convert(_filepath, _front_matter, body, %{site: %{config: config}}) do
20-
{plugins, mdex_config} = resolve_plugins(config)
21-
23+
{plugins, mdex_config} = Keyword.pop(:plugins, config.markdown[:mdex])
2224
render!(body, mdex_config, plugins)
2325
end
2426

25-
defp resolve_plugins(config, overrides \\ []) do
26-
config.markdown[:mdex]
27-
|> Keyword.merge(overrides, fn
28-
:plugins, left, right -> List.wrap(right) ++ List.wrap(left)
29-
_, _, v -> v
30-
end)
31-
|> Keyword.pop(:plugins, [])
32-
end
33-
3427
defp render!(content, mdex_config, plugins) do
3528
mdex_config
3629
|> Keyword.put(:markdown, content)

0 commit comments

Comments
 (0)