-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b0ccb9
commit 4d142c8
Showing
5 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule Test.Acceptance.Earmark.PostprocessorTest do | ||
use ExUnit.Case | ||
|
||
describe "use case from Issue 446" do | ||
@no_code """ | ||
just a line | ||
""" | ||
test "no code" do | ||
assert parse(@no_code) == "<p>\njust a line</p>\n" | ||
end | ||
|
||
@inline_code """ | ||
`alpha` | ||
``beta | ||
` `` | ||
""" | ||
test "inline code" do | ||
expected = "<p>\n<code class=\"inline\">alpha</code>\n<code class=\"inline\">beta `</code></p>\n" | ||
assert parse(@inline_code) == expected | ||
end | ||
|
||
@code_to_be_replaced """ | ||
pre | ||
``` | ||
immaterial | ||
``` | ||
post | ||
""" | ||
test "replacing" do | ||
expected = "<p>\npre</p>\n<pre><code>xxx</code></pre>\n<p>\npost</p>\n" | ||
assert parse(@code_to_be_replaced) == expected | ||
end | ||
end | ||
|
||
defp parse(markdown) do | ||
options = [ | ||
registered_processors: [ | ||
{"code", &render_code_node/1} | ||
] | ||
] | ||
{:ok, post_html, _} = Earmark.as_html(markdown, options) | ||
post_html | ||
end | ||
|
||
defp render_code_node({"code", attrs, _content, meta} = node) do | ||
classes = Earmark.AstTools.find_att_in_node(node, "class") || "" | ||
cond do | ||
classes =~ "inline" -> node | ||
true -> {:replace, {"code", attrs, "xxx", meta}} | ||
end | ||
end | ||
end | ||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters