@@ -43,63 +43,35 @@ defmodule ExDoc.Formatter.MARKDOWN.Templates do
43
43
@ spec synopsis ( nil ) :: nil
44
44
def synopsis ( doc ) when is_binary ( doc ) do
45
45
case :binary . split ( doc , "\n \n " ) do
46
- [ left , _ ] -> String . trim_trailing ( left , ": " )
46
+ [ left , _ ] -> String . trim_trailing ( left , ": " ) <> " \n \n "
47
47
[ all ] -> all
48
48
end
49
49
end
50
- def synopsis ( _ ) , do: nil
51
-
52
- @ doc """
53
- Add link headings for the given `content`.
54
50
55
- IDs are prefixed with `prefix`.
56
-
57
- We only link `h2` and `h3` headers. This is kept consistent in ExDoc.SearchData.
58
- """
59
- @ heading_regex ~r/ <(h[23]).*?>(.*?)<\/ \1 >/ m
60
- @ spec link_headings ( String . t ( ) | nil , String . t ( ) ) :: String . t ( ) | nil
61
- def link_headings ( content , prefix \\ "" )
62
- def link_headings ( nil , _ ) , do: nil
51
+ def synopsis ( _ ) , do: nil
63
52
64
- def link_headings ( content , prefix ) do
53
+ @ heading_regex ~r/ ^(\# {1,6})\s +(.*)/ m
54
+ defp rewrite_headings ( content ) when is_binary ( content ) do
65
55
@ heading_regex
66
56
|> Regex . scan ( content )
67
- |> Enum . reduce ( { content , % { } } , fn [ match , tag , title ] , { content , occurrences } ->
68
- possible_id = text_to_id ( title )
69
- id_occurred = Map . get ( occurrences , possible_id , 0 )
70
-
71
- anchor_id = if id_occurred >= 1 , do: "#{ possible_id } -#{ id_occurred } " , else: possible_id
72
- replacement = link_heading ( match , tag , title , anchor_id , prefix )
73
- linked_content = String . replace ( content , match , replacement , global: false )
74
- incremented_occs = Map . put ( occurrences , possible_id , id_occurred + 1 )
75
- { linked_content , incremented_occs }
57
+ |> Enum . reduce ( content , fn [ match , level , title ] , content ->
58
+ replacement = rewrite_heading ( level , title )
59
+ String . replace ( content , match , replacement , global: false )
76
60
end )
77
- |> elem ( 0 )
78
61
end
79
62
80
- defp link_heading ( match , _tag , _title , "" , _prefix ) , do: match
63
+ defp rewrite_headings ( _ ) , do: nil
81
64
82
- defp link_heading ( _match , _tag , title , id , prefix ) do
83
- # The Markdown syntax that we support for the admonition text
84
- # blocks is something like this:
85
- #
86
- # > ### Never open this door! {: .warning}
87
- # >
88
- # > ...
89
- #
65
+ defp rewrite_heading ( "#" , title ) , do: do_rewrite_heading ( "#####" , title )
66
+ defp rewrite_heading ( _ , title ) , do: do_rewrite_heading ( "######" , title )
90
67
68
+ defp do_rewrite_heading ( level , title ) do
91
69
"""
92
- ## [ #{ title } ](# #{ prefix } #{ id } )
70
+ #{ level } #{ title }
93
71
"""
94
72
end
95
73
96
- def link_moduledoc_headings ( content ) do
97
- link_headings ( content , "module-" )
98
- end
99
-
100
- def link_detail_headings ( content , prefix ) do
101
- link_headings ( content , prefix <> "-" )
102
- end
74
+ defp enc ( binary ) , do: URI . encode ( binary ) |> String . replace ( "/" , "-" )
103
75
104
76
@ doc """
105
77
Creates a chapter which contains all the details about an individual module.
0 commit comments