Skip to content

Commit c47807c

Browse files
committed
Extract title even with comments
1 parent 4628900 commit c47807c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/ex_doc/doc_ast.ex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,9 @@ defmodule ExDoc.DocAST do
104104
"""
105105
def extract_title(ast)
106106

107-
def extract_title([{:h1, _attrs, inner, _meta} | ast]) do
108-
{:ok, inner, ast}
109-
end
110-
111-
def extract_title(_ast) do
112-
:error
113-
end
107+
def extract_title([{:comment, _, _, _} | ast]), do: extract_title(ast)
108+
def extract_title([{:h1, _attrs, inner, _meta} | ast]), do: {:ok, inner, ast}
109+
def extract_title(_ast), do: :error
114110

115111
@doc """
116112
Returns text content from the given AST.

test/ex_doc/formatter/html_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ defmodule ExDoc.Formatter.HTMLTest do
421421

422422
content = File.read!(tmp_dir <> "/html/livebookfile.html")
423423

424+
assert content =~ ~r{<span>Title for Livebook Files</span>\s*</h1>}
425+
424426
assert content =~
425427
~s{<a href="https://github.com/elixir-lang/elixir/blob/main/test/fixtures/LivebookFile.livemd#L1" title="View Source"}
426428

test/fixtures/LivebookFile.livemd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# Livebook Files
1+
<!-- foobar -->
2+
3+
# Title for Livebook Files
24

35
Read `.livemd` files generated by [livebook](https://github.com/livebook-dev/livebook).

0 commit comments

Comments
 (0)