Skip to content

Commit 8611a16

Browse files
authored
Improve word-breaking of module names and sizing of main page titles (#2190)
1 parent 1b1fe51 commit 8611a16

7 files changed

Lines changed: 37 additions & 11 deletions

File tree

assets/css/content/general.css

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,35 @@
7474
/* Headings
7575
Summary, Callbacks and Functions sections output h1 and h2,
7676
which we style as h2 and h3. */
77-
7877
.content-inner {
78+
--h1-size: 1.5rem;
79+
--h2-size: 1.35rem;
80+
--h3-size: 1.25rem;
81+
--h4-h5-size: 1.15rem;
82+
--h6-size: 1rem;
83+
7984
& h1 {
80-
font-size: 2rem;
85+
font-size: var(--h1-size);
8186
margin-top: 1.75em;
8287
}
8388

8489
& h2,
8590
& :is(#summary, #callbacks, #functions) > h1.section-heading {
86-
font-size: 1.75rem;
91+
font-size: var(--h2-size);
8792
margin-top: 1.5em;
8893
margin-bottom: 0.5em;
8994
}
9095

9196
& h3,
9297
& :is(#summary, #callbacks, #functions) > h2.section-heading,
9398
& #summary :is(.summary-callbacks, .summary-functions) h2 {
94-
font-size: 1.45rem;
99+
font-size: var(--h3-size);
95100
margin-top: 1.5em;
96101
margin-bottom: 0.5em;
97102
}
98103

99104
& :is(h4, h5, h6) {
100-
font-size: 1.15rem;
105+
font-size: var(--h4-h5-size);
101106
margin-top: 1.25em;
102107
margin-bottom: 0.5em;
103108
}
@@ -107,7 +112,14 @@ which we style as h2 and h3. */
107112
}
108113

109114
& h6 {
110-
font-size: 1rem;
115+
font-size: var(--h6-size);
116+
}
117+
}
118+
@container content (width > 600px) {
119+
.content-inner {
120+
--h1-size: 2rem;
121+
--h2-size: 1.75rem;
122+
--h3-size: 1.45rem;
111123
}
112124
}
113125

assets/css/layout.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/* Layout container contexts */
2+
3+
#main {
4+
container: content / inline-size;
5+
}
6+
7+
/* Layout styles */
8+
19
html,
210
body {
311
box-sizing: border-box;
@@ -62,7 +70,6 @@ body {
6270
}
6371

6472
.content .content-inner {
65-
container: content / inline-size;
6673
max-width: var(--content-width);
6774
min-height: 100%;
6875
margin: 0 auto;

lib/ex_doc/formatter/epub/templates/module_template.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= head_template(config, module.title) %>
22
<h1 id="content">
3-
<%= module.title %> <%= H.module_type(module) %>
3+
<%= H.breakable_module_title(module.title) %> <%= H.module_type(module) %>
44
</h1>
55

66
<%= if deprecated = module.deprecated do %>

lib/ex_doc/formatter/html/templates.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ defmodule ExDoc.Formatter.HTML.Templates do
1414
Atom.to_string(t)
1515
end
1616

17+
@doc """
18+
Returns the title with `<wbr>` after each fullstop, allowing word breaks in long module names.
19+
"""
20+
def breakable_module_title(title) when is_binary(title) do
21+
String.replace(title, ".", ".<wbr>")
22+
end
23+
1724
@doc """
1825
Returns the HTML formatted title for the module page.
1926
"""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="summary-row">
22
<div class="summary-signature">
3-
<a href="<%=enc module_node.id %>.html" translate="no"><%=h module_node.title %></a>
3+
<a href="<%=enc module_node.id %>.html" translate="no"><%= breakable_module_title(h module_node.title) %></a>
44
<%= if deprecated = module_node.deprecated do %>
55
<span class="deprecated" title="<%= h(deprecated) %>">deprecated</span>
66
<% end %>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div id="top-content">
55
<div class="heading-with-actions top-heading">
66
<h1>
7-
<span translate="no"><%= module.title %></span> <%= module_type(module) %>
7+
<span translate="no"><%= breakable_module_title(module.title) %></span> <%= module_type(module) %>
88
<small class="app-vsn" translate="no">(<%= config.project %> v<%= config.version %>)</small>
99
<%= for annotation <- module.annotations do %>
1010
<span class="note">(<%= annotation %>)</span>

test/ex_doc/formatter/html_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ defmodule ExDoc.Formatter.HTMLTest do
117117
assert content =~ ~r{<p>moduledoc</p>}
118118

119119
assert content =~
120-
~r{<a href="CompiledWithDocs.Nested.html" translate="no">CompiledWithDocs.Nested</a>}
120+
~r{<a href="CompiledWithDocs.Nested.html" translate="no">CompiledWithDocs.<wbr>Nested</a>}
121121

122122
assert content =~
123123
~r{<a href="Mix.Tasks.TaskWithDocs.html" translate="no">mix task_with_docs</a>}

0 commit comments

Comments
 (0)