Skip to content

Commit

Permalink
Extract title even with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 25, 2023
1 parent 4628900 commit c47807c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lib/ex_doc/doc_ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -421,6 +421,8 @@ defmodule ExDoc.Formatter.HTMLTest do

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

assert content =~ ~r{<span>Title for Livebook Files</span>\s*</h1>}

assert content =~
~s{<a href="https://github.com/elixir-lang/elixir/blob/main/test/fixtures/LivebookFile.livemd#L1" title="View Source"}

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/LivebookFile.livemd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Livebook Files
<!-- foobar -->

# Title for Livebook Files

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

0 comments on commit c47807c

Please sign in to comment.