Skip to content

Commit

Permalink
Break up into search sections by <h2> (##) only
Browse files Browse the repository at this point in the history
Closes #1875
  • Loading branch information
wojtekmach committed Mar 6, 2024
1 parent 91d9000 commit 8a8e780
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html/search_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule ExDoc.Formatter.HTML.SearchData do
end

defp extract_sections_from_markdown(string) do
[intro | sections] = Regex.split(~r/## (?<header>\b.+)/, string, include_captures: true)
[intro | sections] = Regex.split(~r/(?<!#)## (?<header>\b.+)/, string, include_captures: true)

sections =
for [header, section] <- Enum.chunk_every(sections, 2) do
Expand Down
15 changes: 13 additions & 2 deletions test/ex_doc/formatter/html/search_data_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ defmodule ExDoc.Formatter.HTML.SearchDataTest do
## Section 1
Section Content 1.
### Section 1a
Section Content 1a.
"""
end
''')
Expand All @@ -32,7 +36,14 @@ defmodule ExDoc.Formatter.HTML.SearchDataTest do
assert item2["ref"] == "SearchFoo.html#module-section-1"
assert item2["type"] == "module"
assert item2["title"] == "Section 1 - SearchFoo"
assert item2["doc"] == "Section Content 1."

assert item2["doc"] == """
Section Content 1.
### Section 1a
Section Content 1a.\
"""
end

test "Mix task", c do
Expand All @@ -54,7 +65,7 @@ defmodule ExDoc.Formatter.HTML.SearchDataTest do

assert item1["ref"] == "Mix.Tasks.SearchItemTest.html"
assert item1["type"] == "task"
# assert item1["title"] == "mix search_item_test"
assert item1["title"] == "mix search_item_test"
assert item1["doc"] == "Test task."

assert item2["ref"] == "Mix.Tasks.SearchItemTest.html#module-section-1"
Expand Down

0 comments on commit 8a8e780

Please sign in to comment.