diff --git a/lib/ex_doc/formatter/html/templates.ex b/lib/ex_doc/formatter/html/templates.ex index 55b30a2ae..357d4623b 100644 --- a/lib/ex_doc/formatter/html/templates.ex +++ b/lib/ex_doc/formatter/html/templates.ex @@ -53,9 +53,10 @@ defmodule ExDoc.Formatter.HTML.Templates do def synopsis(doc) when is_binary(doc) do doc = - case :binary.split(doc, "

") do - [left, _] -> String.trim_trailing(left, ":") <> "

" - [all] -> all + Regex.run(~r|

((?:(?!

).)*?):*

|, doc) + |> case do + nil -> doc + [_, first_paragraph_text] -> "

" <> first_paragraph_text <> "

" end # Remove any anchors found in synopsis. diff --git a/test/ex_doc/formatter/html/templates_test.exs b/test/ex_doc/formatter/html/templates_test.exs index ae4dbbba1..4ec59f0a5 100644 --- a/test/ex_doc/formatter/html/templates_test.exs +++ b/test/ex_doc/formatter/html/templates_test.exs @@ -169,6 +169,9 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do assert Templates.synopsis("

::

") == "

" assert Templates.synopsis("

Description:

") == "

Description

" assert Templates.synopsis("

abcd

") == "

abcd

" + assert Templates.synopsis("

abc

def

") == "

abc

" + assert Templates.synopsis("

title

abc

def

") == "

abc

" + assert Templates.synopsis("
  • abc

  • ") == "

    abc

    " end test "should not end have trailing periods or semicolons" do