Skip to content

Commit a6e7399

Browse files
committed
Do not add fancy anchors around verbatim headers, closes #2128
1 parent 9b0b2d9 commit a6e7399

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/ex_doc/formatter/html/templates.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ defmodule ExDoc.Formatter.HTML.Templates do
193193

194194
defp add_fancy_anchors(ast) do
195195
ExDoc.DocAST.map_tags(ast, fn
196-
{tag, attrs, inner, meta} = ast when tag in [:h2, :h3] ->
196+
{tag, attrs, inner, meta} = ast
197+
when tag in [:h2, :h3] and not is_map_key(meta, :verbatim) ->
197198
if id = Keyword.get(attrs, :id) do
198199
attrs =
199200
Keyword.update(

test/ex_doc/formatter/html/templates_test.exs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
4242
end
4343

4444
describe "render_doc" do
45+
defp render_doc(doc) do
46+
doc
47+
|> ExDoc.DocAST.parse!("text/markdown")
48+
|> ExDoc.DocAST.add_ids_to_headers([:h2, :h3])
49+
|> Templates.render_doc()
50+
end
51+
4552
test "adds fancy anchors around ids" do
46-
assert """
53+
assert render_doc("""
4754
## Foo
4855
4956
### Bar {:class=wrap}
50-
"""
51-
|> ExDoc.DocAST.parse!("text/markdown")
52-
|> ExDoc.DocAST.add_ids_to_headers([:h2, :h3])
53-
|> Templates.render_doc() ==
57+
""") ==
5458
"""
5559
<h2 id="foo" class="section-heading">
5660
<a href="#foo" class="hover-link">
@@ -67,6 +71,12 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
6771
"""
6872
|> String.replace(~r/\n\s*/, "")
6973
end
74+
75+
test "skips fancy anchors on verbatim" do
76+
assert render_doc("""
77+
<h2>Foo</h2>
78+
""") == "<h2 id=\"foo\">Foo</h2>"
79+
end
7080
end
7181

7282
describe "sidebar" do

0 commit comments

Comments
 (0)