@@ -6,7 +6,7 @@ defmodule ExDoc.Formatter.HTML do
66  alias  ExDoc.Formatter.HTML.Templates 
77  alias  ExDoc.Formatter.HTML.Autolink 
88
9-   @ main  "extra- api-reference" 
9+   @ main  "api-reference" 
1010
1111  @ doc  """ 
1212  Generate HTML documentation for the given modules 
@@ -56,7 +56,7 @@ defmodule ExDoc.Formatter.HTML do
5656
5757  defp  generate_api_reference ( modules ,  exceptions ,  protocols ,  output ,  config )  do 
5858    content  =  Templates . api_reference_template ( config ,  modules ,  exceptions ,  protocols ) 
59-     File . write! ( "#{ output } extra- api-reference.html" ,  content ) 
59+     File . write! ( "#{ output }  ,  content ) 
6060  end 
6161
6262  defp  generate_not_found ( modules ,  exceptions ,  protocols ,  output ,  config )  do 
@@ -100,35 +100,74 @@ defmodule ExDoc.Formatter.HTML do
100100          generate_extra ( & 1 ,  output ,  module_nodes ,  modules ,  exceptions ,  protocols ,  config ) 
101101         end ) ) 
102102      |>  Enum . map ( & Task . await / 1 ) 
103-     [ { "extra-api-reference" ,  "API Reference" ,  [ ] } | extras ] 
103+     [ { "api-reference" ,  "API Reference" ,  [ ] } | extras ] 
104+   end 
105+ 
106+   defp  generate_extra ( { input_file ,  output_file_name } ,  output ,  module_nodes ,  modules ,  exceptions ,  protocols ,  config )  do 
107+     title  =  input_to_title ( output_file_name ) 
108+ 
109+     options  =  % { 
110+       title:  title , 
111+       output_file_name:  title , 
112+       input:  to_string ( input_file ) , 
113+       output:  output 
114+     } 
115+ 
116+     create_extra_files ( module_nodes ,  modules ,  exceptions ,  protocols ,  config ,  options ) 
104117  end 
105118
106119  defp  generate_extra ( input ,  output ,  module_nodes ,  modules ,  exceptions ,  protocols ,  config )  do 
107-     file_ext  = 
108-       input 
109-       |>  Path . extname ( ) 
110-       |>  String . downcase ( ) 
120+     title  =  input_to_title ( input ) 
121+     output_file_name  =  title_to_filename ( title ) 
122+ 
123+     options  =  % { 
124+       title:  title , 
125+       output_file_name:  output_file_name , 
126+       input:  input , 
127+       output:  output 
128+     } 
111129
112-     if  file_ext  in  [ ".md" ]  do 
113-       title  =  Path . rootname ( Path . basename ( input ) ) 
114-       file_name  =  title_to_filename ( title ) 
130+     create_extra_files ( module_nodes ,  modules ,  exceptions ,  protocols ,  config ,  options ) 
131+   end 
115132
133+   defp  create_extra_files ( module_nodes ,  modules ,  exceptions ,  protocols ,  config ,  options )  do 
134+     if  valid_extension_name? ( options . input )  do 
116135      content  = 
117-         input 
136+         options . input 
118137        |>  File . read! ( ) 
119138        |>  Autolink . project_doc ( module_nodes ) 
120139
121-       html  =  Templates . extra_template ( config ,  title ,  modules , 
140+       html  =  Templates . extra_template ( config ,  options . title ,  modules , 
122141                                      exceptions ,  protocols ,  link_headers ( content ) ) 
123142
124-       File . write! ( "#{ output } #{ file_name }  ,  html ) 
125-       { file_name ,  title ,  extract_headers ( content ) } 
143+       output  =  "#{ options . output } #{ options . output_file_name }  
144+ 
145+       if  File . regular?  output  do 
146+         IO . puts  "warning: file #{ Path . basename  output }  
147+       end 
148+ 
149+       File . write! ( output ,  html ) 
150+ 
151+       { options . output_file_name ,  options . title ,  extract_headers ( content ) } 
126152    else 
127153      raise  ArgumentError ,  "file format not recognized, allowed format is: .md" 
128154    end 
129155  end 
130156
131-   @ h2_regex  ~r/ ^##([^#].*)$/ m 
157+   defp  valid_extension_name? ( input )  do 
158+     file_ext  = 
159+       input 
160+       |>  Path . extname ( ) 
161+       |>  String . downcase ( ) 
162+ 
163+       if  file_ext  in  [ ".md" ]  do 
164+         true 
165+       else 
166+         false 
167+       end 
168+   end 
169+ 
170+   @ h2_regex  ~r/ ^##([^#].*)\n $/ m 
132171
133172  defp  extract_headers ( content )  do 
134173    @ h2_regex 
@@ -143,8 +182,12 @@ defmodule ExDoc.Formatter.HTML do
143182    end ) 
144183  end 
145184
185+   defp  input_to_title ( input )  do 
186+     input  |>  Path . basename ( )  |>  Path . rootname ( ) 
187+   end 
188+ 
146189  defp  title_to_filename ( title )  do 
147-     "extra-"   <>   ( title  |>  String . replace ( " " ,  "-" )  |>  String . downcase ) 
190+     title  |>  String . replace ( " " ,  "-" )  |>  String . downcase ( ) 
148191  end 
149192
150193  defp  header_to_id ( header )  do 
0 commit comments