Skip to content

Commit 91c3304

Browse files
committed
Avoid unnecessary work
1 parent 0be766e commit 91c3304

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

lib/ex_doc/formatter/html/search_data.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ defmodule ExDoc.Formatter.HTML.SearchData do
5858
end
5959

6060
defp module(%ExDoc.ModuleNode{} = node) do
61+
# TODO: This should work on DocAST
6162
{intro, sections} = extract_sections(node.doc_format, node)
6263

6364
module =
@@ -132,6 +133,7 @@ defmodule ExDoc.Formatter.HTML.SearchData do
132133
{"", []}
133134
end
134135

136+
# TODO: This should work on DocAST when we prebuild extra.
135137
defp extract_sections_from_markdown(string) do
136138
[intro | sections] =
137139
Regex.split(~r/(?<!#)###? (?<header>\b.+)/, string, include_captures: true)

lib/ex_doc/formatter/html/templates.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ defmodule ExDoc.Formatter.HTML.Templates do
184184
defp sidebar_type(:livemd), do: "extras"
185185
defp sidebar_type(:extra), do: "extras"
186186

187-
# TODO: Move link_headings and friends to html.ex (possibly via DocAST)
188-
# or even to autolinking code, so content is built with it upfront instead
189-
# of added at the template level.
187+
# TODO: Adding the link headings must be done via DocAST instead of using regexes.
190188

191189
@doc """
192190
Add link headings for the given `content`.
@@ -203,7 +201,7 @@ defmodule ExDoc.Formatter.HTML.Templates do
203201
~r/<(h[23]).*?>(.*?)<\/\1>/m
204202
|> Regex.scan(content)
205203
|> Enum.reduce({content, %{}}, fn [match, tag, title], {content, occurrences} ->
206-
possible_id = text_to_id(title)
204+
possible_id = title |> ExDoc.Utils.strip_tags() |> text_to_id()
207205
id_occurred = Map.get(occurrences, possible_id, 0)
208206

209207
anchor_id = if id_occurred >= 1, do: "#{possible_id}-#{id_occurred}", else: possible_id

lib/ex_doc/utils.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ defmodule ExDoc.Utils do
102102

103103
def text_to_id(text) when is_binary(text) do
104104
text
105-
|> strip_tags()
106105
|> String.replace(~r/&#\d+;/, "")
107106
|> String.replace(~r/&[A-Za-z0-9]+;/, "")
108107
|> String.replace(~r/\W+/u, "-")

test/ex_doc/utils_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,5 @@ defmodule ExDoc.UtilsTest do
100100
assert Utils.text_to_id(" ☃ ") == ""
101101
assert Utils.text_to_id(" &sup2; ") == ""
102102
assert Utils.text_to_id(" &#9180; ") == ""
103-
assert Utils.text_to_id("Git opts (<code class=\"inline\">:git</code>)") == "git-opts-git"
104103
end
105104
end

0 commit comments

Comments
 (0)