File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -191,22 +191,21 @@ pub fn snippet(doc: String, search_input: String) -> String {
191191 doc
192192 |> string . split ( on : "\r \n \r \n " )
193193 |> list . flat_map ( string . split ( _, on : "\n \n " ) )
194+ |> list . map ( string . trim )
194195
195- // Get first usable paragraph (skip if starts with "#")
196- let first_paragraph = case paragraphs {
197- [ first , second , .. ] ->
198- case string . starts_with ( string . trim ( first ) , "#" ) {
199- True -> second
200- False -> first
201- }
202- [ first ] -> first
203- [ ] -> doc
204- }
196+ let trimmed =
197+ list . drop_while ( paragraphs , fn ( paragraph ) {
198+ string . starts_with ( paragraph , "#" ) || string . starts_with ( paragraph , ">" )
199+ } )
200+
201+ let first =
202+ result . or ( list . first ( trimmed ) , list . first ( paragraphs ) )
203+ |> result . unwrap ( doc )
205204
206205 // Truncate to reasonable length (around 200 characters)
207- let truncated = case string . length ( first_paragraph ) > 200 {
208- True -> string . slice ( first_paragraph , 0 , 200 ) <> "..."
209- False -> first_paragraph
206+ let truncated = case string . length ( first ) > 200 {
207+ True -> string . slice ( first , 0 , 200 ) <> "..."
208+ False -> first
210209 }
211210
212211 // Highlight search terms
You can’t perform that action at this time.
0 commit comments