@@ -59,7 +59,6 @@ defmodule ExDoc.Formatter.HTML.Templates do
59
59
defp sidebar_extras ( extras ) do
60
60
for extra <- extras do
61
61
% { id: id , title: title , group: group } = extra
62
-
63
62
item = % { id: to_string ( id ) , title: to_string ( title ) , group: to_string ( group ) }
64
63
65
64
case extra do
@@ -74,14 +73,14 @@ defmodule ExDoc.Formatter.HTML.Templates do
74
73
end )
75
74
76
75
item
77
- |> Map . put ( :headers , extract_headers ( extra . content ) )
76
+ |> Map . put ( :headers , headers_to_id_and_anchors ( extra . headers ) )
78
77
|> Map . put ( :searchData , search_data )
79
78
80
79
% { url: url } when is_binary ( url ) ->
81
80
Map . put ( item , :url , url )
82
81
83
82
_ ->
84
- Map . put ( item , :headers , extract_headers ( extra . content ) )
83
+ Map . put ( item , :headers , headers_to_id_and_anchors ( extra . headers ) )
85
84
end
86
85
end
87
86
end
@@ -140,8 +139,9 @@ defmodule ExDoc.Formatter.HTML.Templates do
140
139
141
140
defp module_sections ( module ) do
142
141
{ sections , _ } =
143
- module . rendered_doc
144
- |> extract_headers ( )
142
+ module . doc
143
+ |> ExDoc.DocAST . extract_headers ( )
144
+ |> headers_to_id_and_anchors ( )
145
145
|> Enum . map_reduce ( % { } , fn header , acc ->
146
146
# TODO Duplicates some of the logic of link_headings/3
147
147
case Map . fetch ( acc , header . id ) do
@@ -156,14 +156,10 @@ defmodule ExDoc.Formatter.HTML.Templates do
156
156
[ sections: sections ]
157
157
end
158
158
159
- # TODO: split into sections in Formatter.HTML instead (possibly via DocAST)
160
- defp extract_headers ( content ) do
161
- ~r/ <h2.*?>(.*?)<\/ h2>/ m
162
- |> Regex . scan ( content , capture: :all_but_first )
163
- |> List . flatten ( )
164
- |> Enum . filter ( & ( & 1 != "" ) )
165
- |> Enum . map ( & ExDoc.Utils . strip_tags / 1 )
166
- |> Enum . map ( & % { id: & 1 , anchor: URI . encode ( text_to_id ( & 1 ) ) } )
159
+ defp headers_to_id_and_anchors ( headers ) do
160
+ Enum . map ( headers , fn text ->
161
+ % { id: text , anchor: URI . encode ( text_to_id ( text ) ) }
162
+ end )
167
163
end
168
164
169
165
def module_summary ( module_node ) do
0 commit comments