Skip to content

Commit

Permalink
Render unknown tags (verbatim: true) as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
sax committed May 16, 2023
1 parent 86d7239 commit 8f18327
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- Unknown tags which are parsed with `verbatim: true` are rendered as-is.
- Handle image links with titles.

## 0.5.0
Expand Down
3 changes: 3 additions & 0 deletions lib/markdown_formatter/renderer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ defmodule MarkdownFormatter.Renderer do
doc
|> push([with_depth(opts.prefix, opts.depth - 1), render(contents, Q.new(), opts)])

defp render({tag, [], [contents], %{verbatim: true}}, doc, _opts) when is_binary(contents),
do: push(doc, ["<#{tag}>\n#{contents}\n</#{tag}>"])

# text node
defp render([text], @empty_queue, opts) when is_binary(text), do: text |> reformat(opts)
defp render(text, @empty_queue, opts) when is_binary(text), do: text |> reformat(opts)
Expand Down
19 changes: 19 additions & 0 deletions test/markdown_formatter/renderer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,25 @@ defmodule MarkdownFormatter.RendererTest do
> You should read me.
""")
end

test "renders collapsible items" do
"""
<details>
<summary>Preview title</summary>
Some extra content.
</details>
"""
|> parse!()
|> Renderer.to_markdown()
|> assert_eq("""
<details>
<summary>Preview title</summary>
Some extra content.
</details>
""")
end
end

describe "to_markdown documents" do
Expand Down

0 comments on commit 8f18327

Please sign in to comment.