@@ -110,6 +110,37 @@ defmodule ExDoc.DocAST do
110
110
def extract_title ( [ { :h1 , _attrs , inner , _meta } | ast ] ) , do: { :ok , inner , ast }
111
111
def extract_title ( _ast ) , do: :error
112
112
113
+ @ doc """
114
+ Compute a synopsis from a document by looking at its first paragraph.
115
+ """
116
+ def synopsis ( { :p , _attrs , [ _ | _ ] = inner , meta } ) do
117
+ inner =
118
+ case Enum . split ( inner , - 1 ) do
119
+ { pre , [ post ] } when is_binary ( post ) ->
120
+ pre ++ [ String . trim_trailing ( post , ":" ) ]
121
+
122
+ _ ->
123
+ inner
124
+ end
125
+
126
+ ExDoc.DocAST . to_string ( { :p , [ ] , remove_ids ( inner ) , meta } )
127
+ end
128
+
129
+ def synopsis ( [ head | _ ] ) , do: synopsis ( head )
130
+ def synopsis ( _other ) , do: ""
131
+
132
+ @ doc """
133
+ Remove ids from elements.
134
+ """
135
+ def remove_ids ( { tag , attrs , inner , meta } ) ,
136
+ do: { tag , Keyword . delete ( attrs , :href ) , remove_ids ( inner ) , meta }
137
+
138
+ def remove_ids ( list ) when is_list ( list ) ,
139
+ do: Enum . map ( list , & remove_ids / 1 )
140
+
141
+ def remove_ids ( other ) ,
142
+ do: other
143
+
113
144
@ doc """
114
145
Returns text content from the given AST.
115
146
"""
0 commit comments