Skip to content

Commit

Permalink
Add spaces on paragraph endings for search results (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinst authored Mar 29, 2021
1 parent b41fd99 commit fd55c41
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ defmodule ExDoc.Formatter.HTML do
@doc """
Strips html tags from text leaving their text content
"""
def strip_tags(text) when is_binary(text) do
String.replace(text, @clean_html_regex, "")
def strip_tags(text, replace_with \\ "") when is_binary(text) do
String.replace(text, @clean_html_regex, replace_with)
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html/search_items.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule ExDoc.Formatter.HTML.SearchItems do
defp clean_doc(doc) do
doc
|> Kernel.||("")
|> HTML.strip_tags()
|> HTML.strip_tags(" ")
|> String.replace(~r/\s+/, " ")
|> String.trim()
end
Expand Down
2 changes: 2 additions & 0 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ defmodule ExDoc.Formatter.HTMLTest do
assert HTML.strip_tags("<em>Hello</em> World!<br/>") == "Hello World!"
assert HTML.strip_tags("Go <a href=\"#top\" class='small' disabled>back</a>") == "Go back"
assert HTML.strip_tags("Git opts (<code class=\"inline\">:git</code>)") == "Git opts (:git)"
assert HTML.strip_tags("<p>P1.</p><p>P2</p>") == "P1.P2"
assert HTML.strip_tags("<p>P1.</p><p>P2</p>", " ") == " P1. P2 "
end
end

Expand Down

0 comments on commit fd55c41

Please sign in to comment.