diff --git a/lib/ex_doc/formatter/epub.ex b/lib/ex_doc/formatter/epub.ex
index 065b37a4d..6c14b693f 100644
--- a/lib/ex_doc/formatter/epub.ex
+++ b/lib/ex_doc/formatter/epub.ex
@@ -87,6 +87,11 @@ defmodule ExDoc.Formatter.EPUB do
end
defp generate_nav(config, nodes) do
+ nodes =
+ Map.update!(nodes, :modules, fn modules ->
+ modules |> Enum.chunk_by(& &1.group) |> Enum.map(&{hd(&1).group, &1})
+ end)
+
content = Templates.nav_template(config, nodes)
File.write("#{config.output}/OEBPS/nav.xhtml", content)
end
diff --git a/lib/ex_doc/formatter/epub/templates.ex b/lib/ex_doc/formatter/epub/templates.ex
index 57f10dcb2..5762de792 100644
--- a/lib/ex_doc/formatter/epub/templates.ex
+++ b/lib/ex_doc/formatter/epub/templates.ex
@@ -109,6 +109,14 @@ defmodule ExDoc.Formatter.EPUB.Templates do
trim: true
)
+ EEx.function_from_file(
+ :defp,
+ :nav_grouped_item_template,
+ Path.expand("templates/nav_grouped_item_template.eex", __DIR__),
+ [:nodes],
+ trim: true
+ )
+
EEx.function_from_file(
:defp,
:toc_item_template,
diff --git a/lib/ex_doc/formatter/epub/templates/nav_grouped_item_template.eex b/lib/ex_doc/formatter/epub/templates/nav_grouped_item_template.eex
new file mode 100644
index 000000000..67b1d0396
--- /dev/null
+++ b/lib/ex_doc/formatter/epub/templates/nav_grouped_item_template.eex
@@ -0,0 +1,13 @@
+<%= for {title, nodes} <- nodes do %>
+ <%= if title do %>
+
<%=h to_string(title) %>
+
+ <% end %>
+ <%= for node <- nodes do %>
+ - <%=h node.title %>
+ <% end %>
+ <%= if title do %>
+
+
+ <% end %>
+<% end %>
diff --git a/lib/ex_doc/formatter/epub/templates/nav_template.eex b/lib/ex_doc/formatter/epub/templates/nav_template.eex
index 88af07185..52cb08e6c 100644
--- a/lib/ex_doc/formatter/epub/templates/nav_template.eex
+++ b/lib/ex_doc/formatter/epub/templates/nav_template.eex
@@ -2,21 +2,17 @@
Table of contents
diff --git a/test/ex_doc/formatter/html_test.exs b/test/ex_doc/formatter/html_test.exs
index 5bee818b7..1c883cf98 100644
--- a/test/ex_doc/formatter/html_test.exs
+++ b/test/ex_doc/formatter/html_test.exs
@@ -131,7 +131,7 @@ defmodule ExDoc.Formatter.HTMLTest do
generate_docs(doc_config(context, skip_undefined_reference_warnings_on: []))
end)
- assert out =~ ~s| documentation references function \"Warnings.bar/0\" but|
+ assert out =~ ~s|documentation references function "Warnings.bar/0" but|
# TODO: remove check when we require Elixir v1.16
if Version.match?(System.version(), ">= 1.16.0-rc") do