@@ -59,7 +59,6 @@ defmodule ExDoc.Formatter.HTML.Templates do
5959 defp sidebar_extras ( extras ) do
6060 for extra <- extras do
6161 % { id: id , title: title , group: group } = extra
62-
6362 item = % { id: to_string ( id ) , title: to_string ( title ) , group: to_string ( group ) }
6463
6564 case extra do
@@ -74,14 +73,14 @@ defmodule ExDoc.Formatter.HTML.Templates do
7473 end )
7574
7675 item
77- |> Map . put ( :headers , extract_headers ( extra . content ) )
76+ |> Map . put ( :headers , headers_to_id_and_anchors ( extra . headers ) )
7877 |> Map . put ( :searchData , search_data )
7978
8079 % { url: url } when is_binary ( url ) ->
8180 Map . put ( item , :url , url )
8281
8382 _ ->
84- Map . put ( item , :headers , extract_headers ( extra . content ) )
83+ Map . put ( item , :headers , headers_to_id_and_anchors ( extra . headers ) )
8584 end
8685 end
8786 end
@@ -140,8 +139,9 @@ defmodule ExDoc.Formatter.HTML.Templates do
140139
141140 defp module_sections ( module ) do
142141 { sections , _ } =
143- module . rendered_doc
144- |> extract_headers ( )
142+ module . doc
143+ |> ExDoc.DocAST . extract_headers ( )
144+ |> headers_to_id_and_anchors ( )
145145 |> Enum . map_reduce ( % { } , fn header , acc ->
146146 # TODO Duplicates some of the logic of link_headings/3
147147 case Map . fetch ( acc , header . id ) do
@@ -156,14 +156,10 @@ defmodule ExDoc.Formatter.HTML.Templates do
156156 [ sections: sections ]
157157 end
158158
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 )
167163 end
168164
169165 def module_summary ( module_node ) do
0 commit comments