Skip to content

Commit 8a5df41

Browse files
committed
Skip blockquotes from snippets
1 parent 6cf7878 commit 8a5df41

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/hexdocs/services/hexdocs.gleam

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)