Skip to content

Commit

Permalink
make recursion generic
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed Oct 1, 2023
1 parent e8afd33 commit fba40c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/fancy_fences.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,6 @@ defmodule FancyFences do
end)
end

defp maybe_apply_fence_processors(
{:blockquote, attrs, content, meta},
opts,
applied_processors
) do
content =
Enum.reduce(content, [], fn block, acc ->
acc ++ maybe_apply_fence_processors(block, opts, applied_processors)
end)

[{:blockquote, attrs, content, meta}]
end

defp maybe_apply_fence_processors(
{:pre, _pre_attrs, [{:code, [class: fence], content, _code_meta}], _pre_meta} = block,
opts,
Expand Down Expand Up @@ -168,5 +155,18 @@ defmodule FancyFences do
end
end

defp maybe_apply_fence_processors(
{type, attrs, content, meta},
opts,
applied_processors
) do
content =
Enum.reduce(content, [], fn block, acc ->
acc ++ maybe_apply_fence_processors(block, opts, applied_processors)
end)

[{type, attrs, content, meta}]
end

defp maybe_apply_fence_processors(block, _opts, _applied_processors), do: [block]
end
50 changes: 50 additions & 0 deletions test/fancy_fences_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ defmodule FancyFencesTest do
```
"""
end

def dummy(_code) do
"""
Dummy text
"""
end
end

describe "to_ast/2" do
Expand Down Expand Up @@ -63,6 +69,50 @@ defmodule FancyFencesTest do
assert FancyFences.to_ast(markdown, opts) == ExDoc.Markdown.to_ast(expected)
end

test "is applied in deeply nested pre code items" do
markdown = """
# A heading
```dummy
```
> A blockquote
>
> ```dummy
> ```
>
>> ```dummy
>> ```
* A list
* sublist
```dummy
```
"""

expected = """
# A heading
Dummy text
> A blockquote
>
> Dummy text
>
>> Dummy text
* A list
* sublist
Dummy text
"""

opts = [fences: %{"dummy" => {Processors, :dummy, []}}]

assert FancyFences.to_ast(markdown, opts) == ExDoc.Markdown.to_ast(expected)
end

test "no recursion allowed" do
markdown = """
```replace
Expand Down

0 comments on commit fba40c0

Please sign in to comment.