Skip to content

Commit f65d2ff

Browse files
committed
Remove cheatsheets from epub, perform sectionize later
1 parent 3aa792b commit f65d2ff

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/ex_doc/formatter/epub.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ defmodule ExDoc.Formatter.EPUB do
6363
defp generate_extras(config) do
6464
for {_title, extras} <- config.extras,
6565
node <- extras,
66-
not is_map_key(node, :url) do
66+
not is_map_key(node, :url) and node.extension != ".cheatmd" do
6767
output = "#{config.output}/OEBPS/#{node.id}.xhtml"
6868
html = Templates.extra_template(config, node)
6969

lib/ex_doc/formatter/html.ex

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ defmodule ExDoc.Formatter.HTML do
410410
source_file = input_options[:source] || input
411411
opts = [file: source_file, line: 1]
412412

413-
{source, ast} =
413+
{extension, source, ast} =
414414
case extension_name(input) do
415415
extension when extension in ["", ".txt"] ->
416416
source = File.read!(input)
417417
ast = [{:pre, [], ["\n" <> source], %{}}]
418-
{source, ast}
418+
{extension, source, ast}
419419

420420
extension when extension in [".md", ".livemd", ".cheatmd"] ->
421421
source = File.read!(input)
@@ -424,10 +424,9 @@ defmodule ExDoc.Formatter.HTML do
424424
source
425425
|> Markdown.to_ast(opts)
426426
|> ExDoc.DocAST.add_ids_to_headers([:h2, :h3])
427-
|> sectionize(extension)
428427
|> autolink_and_highlight(language, [file: input] ++ autolink_opts, opts)
429428

430-
{source, ast}
429+
{extension, source, ast}
431430

432431
_ ->
433432
raise ArgumentError,
@@ -451,6 +450,7 @@ defmodule ExDoc.Formatter.HTML do
451450
search_data = normalize_search_data!(input_options[:search_data])
452451

453452
%{
453+
extension: extension,
454454
source: source,
455455
group: group,
456456
id: id,
@@ -491,12 +491,6 @@ defmodule ExDoc.Formatter.HTML do
491491
|> String.downcase()
492492
end
493493

494-
defp sectionize(ast, ".cheatmd") do
495-
ExDoc.DocAST.sectionize(ast, [:h2, :h3])
496-
end
497-
498-
defp sectionize(ast, _), do: ast
499-
500494
defp filename_to_title(input) do
501495
input |> Path.basename() |> Path.rootname()
502496
end

lib/ex_doc/formatter/html/templates/extra_template.eex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
</div>
2727
<% end %>
2828

29-
<%= node[:content] || render_doc(node.doc) %>
29+
<%= if type == :cheatmd do %>
30+
<%= node.doc |> ExDoc.DocAST.sectionize([:h2, :h3]) |> render_doc() %>
31+
<% else %>
32+
<%= node[:content] || render_doc(node.doc) %>
33+
<% end %>
3034
</div>
3135

3236
<div class="bottom-actions" id="bottom-actions">

0 commit comments

Comments
 (0)