diff --git a/lib/ex_doc/doc_ast.ex b/lib/ex_doc/doc_ast.ex
index 874a6cfad..203da21c1 100644
--- a/lib/ex_doc/doc_ast.ex
+++ b/lib/ex_doc/doc_ast.ex
@@ -104,13 +104,9 @@ defmodule ExDoc.DocAST do
"""
def extract_title(ast)
- def extract_title([{:h1, _attrs, inner, _meta} | ast]) do
- {:ok, inner, ast}
- end
-
- def extract_title(_ast) do
- :error
- end
+ def extract_title([{:comment, _, _, _} | ast]), do: extract_title(ast)
+ def extract_title([{:h1, _attrs, inner, _meta} | ast]), do: {:ok, inner, ast}
+ def extract_title(_ast), do: :error
@doc """
Returns text content from the given AST.
diff --git a/test/ex_doc/formatter/html_test.exs b/test/ex_doc/formatter/html_test.exs
index 83e99d4a0..03490d5f4 100644
--- a/test/ex_doc/formatter/html_test.exs
+++ b/test/ex_doc/formatter/html_test.exs
@@ -421,6 +421,8 @@ defmodule ExDoc.Formatter.HTMLTest do
content = File.read!(tmp_dir <> "/html/livebookfile.html")
+ assert content =~ ~r{Title for Livebook Files\s*}
+
assert content =~
~s{
+
+# Title for Livebook Files
Read `.livemd` files generated by [livebook](https://github.com/livebook-dev/livebook).
\ No newline at end of file