Skip to content

Commit fedf76e

Browse files
committed
Remove heading paragraphs
1 parent cf9d9f0 commit fedf76e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/hexdocs/services/hexdocs.gleam

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,20 @@ fn add_filter_by_packages_param(
180180
}
181181

182182
pub fn snippet(doc: String, search_input: String) -> String {
183-
// Extract first paragraph
184-
let first_paragraph = case string.split(doc, on: "\r\n\r\n") {
185-
[single] ->
186-
case string.split(single, on: "\n\n") {
187-
[first, ..] -> first
188-
[] -> doc
183+
// Extract all paragraphs by splitting on both possible line endings
184+
let paragraphs =
185+
doc
186+
|> string.split(on: "\r\n\r\n")
187+
|> list.flat_map(string.split(_, on: "\n\n"))
188+
189+
// Get first usable paragraph (skip if starts with "#")
190+
let first_paragraph = case paragraphs {
191+
[first, second, ..] ->
192+
case string.starts_with(string.trim(first), "#") {
193+
True -> second
194+
False -> first
189195
}
190-
[first, ..] -> first
196+
[first] -> first
191197
[] -> doc
192198
}
193199

0 commit comments

Comments
 (0)