1
- defmodule ExDoc.Formatter.Markdown do
1
+ defmodule ExDoc.Formatter.MARKDOWN do
2
2
@ moduledoc false
3
3
4
- @ mimetype "text/markdown"
5
4
@ assets_dir "MD/assets"
6
5
alias __MODULE__ . { Assets , Templates }
7
6
alias ExDoc.Formatter.HTML
@@ -28,24 +27,24 @@ defmodule ExDoc.Formatter.Markdown do
28
27
29
28
extras =
30
29
config
31
- |> HTML . build_extras ( ".xhtml " )
30
+ |> HTML . build_extras ( ".md " )
32
31
|> Enum . chunk_by ( & & 1 . group )
33
32
|> Enum . map ( & { hd ( & 1 ) . group , & 1 } )
34
33
35
34
config = % { config | extras: extras }
36
35
37
- static_files = HTML . generate_assets ( "MD" , default_assets ( config ) , config )
38
- HTML . generate_logo ( @ assets_dir , config )
39
- HTML . generate_cover ( @ assets_dir , config )
40
-
41
- # generate_nav(config, nodes_map)
36
+ generate_nav ( config , nodes_map )
42
37
generate_extras ( config )
43
38
generate_list ( config , nodes_map . modules )
44
39
generate_list ( config , nodes_map . tasks )
45
40
46
- { :ok , epub } = generate_zip ( config . output )
47
- File . rm_rf! ( config . output )
48
- Path . relative_to_cwd ( epub )
41
+ # if config[:generate_zip] do # TODO: add a command line flag?
42
+ # {:ok, zip} = generate_zip(config.output)
43
+ # File.rm_rf!(config.output)
44
+ # Path.relative_to_cwd(zip)
45
+ # else
46
+ config . output |> Path . join ( "index.md" ) |> Path . relative_to_cwd ( )
47
+ # end
49
48
end
50
49
51
50
defp normalize_config ( config ) do
@@ -57,6 +56,23 @@ defmodule ExDoc.Formatter.Markdown do
57
56
% { config | output: output }
58
57
end
59
58
59
+ defp normalize_output ( output ) do
60
+ output
61
+ |> String . replace ( ~r/ \r \n |\r |\n / , "\n " )
62
+ |> String . replace ( ~r/ \n {2,}/ , "\n " )
63
+ end
64
+
65
+ defp generate_nav ( config , nodes ) do
66
+ nodes =
67
+ Map . update! ( nodes , :modules , fn modules ->
68
+ modules |> Enum . chunk_by ( & & 1 . group ) |> Enum . map ( & { hd ( & 1 ) . group , & 1 } )
69
+ end )
70
+
71
+ content = Templates . nav_template ( config , nodes )
72
+ |> normalize_output ( )
73
+ File . write ( "#{ config . output } /MD/index.md" , content )
74
+ end
75
+
60
76
defp generate_extras ( config ) do
61
77
for { _title , extras } <- config . extras do
62
78
Enum . each ( extras , fn % { id: id , title: title , title_content: _title_content , source: content } ->
@@ -66,6 +82,7 @@ defmodule ExDoc.Formatter.Markdown do
66
82
67
83
#{ content }
68
84
"""
85
+ |> normalize_output ( )
69
86
70
87
if File . regular? ( output ) do
71
88
Utils . warn ( "file #{ Path . relative_to_cwd ( output ) } already exists" , [ ] )
@@ -77,8 +94,6 @@ defmodule ExDoc.Formatter.Markdown do
77
94
end
78
95
79
96
80
-
81
-
82
97
defp generate_list ( config , nodes ) do
83
98
nodes
84
99
|> Task . async_stream ( & generate_module_page ( & 1 , config ) , timeout: :infinity )
@@ -99,13 +114,6 @@ defmodule ExDoc.Formatter.Markdown do
99
114
100
115
## Helpers
101
116
102
- defp default_assets ( config ) do
103
- [
104
- { Assets . dist ( config . proglang ) , "MD/dist" } ,
105
- { Assets . metainfo ( ) , "META-INF" }
106
- ]
107
- end
108
-
109
117
defp files_to_add ( path ) do
110
118
Enum . reduce ( Path . wildcard ( Path . join ( path , "**/*" ) ) , [ ] , fn file , acc ->
111
119
case File . read ( file ) do
@@ -120,6 +128,7 @@ defmodule ExDoc.Formatter.Markdown do
120
128
121
129
defp generate_module_page ( module_node , config ) do
122
130
content = Templates . module_page ( config , module_node )
131
+ |> normalize_output ( )
123
132
File . write ( "#{ config . output } /MD/#{ module_node . id } .md" , content )
124
133
end
125
134
0 commit comments