Skip to content

Commit ce4c198

Browse files
committed
hide rules behind [*], if the "margin" is too thin
1 parent 5f19268 commit ce4c198

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

mdbook-spec/src/rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Spec {
105105
}
106106
format!(
107107
"<div class=\"rule\" id=\"r-{rule_id}\">\
108-
<a class=\"rule-link\" href=\"#r-{rule_id}\">[{rule_id_broken}]</a>\
108+
<a class=\"rule-link\" href=\"#r-{rule_id}\"><span>[{rule_id_broken}]<span/></a>\
109109
{test_html}\
110110
</div>\n",
111111
rule_id_broken = rule_id.replace(".", "<wbr>."),

theme/reference.css

+17
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ main > .rule {
278278
max-width: unset;
279279
justify-self: right;
280280
width: 100%;
281+
/* We use a container query to know the size of the "left margin",
282+
so that we can hide rules is there is not enough space. */
283+
container-type: inline-size;
284+
container-name: rule;
281285
}
282286

283287
.rule-link {
@@ -301,6 +305,19 @@ main > .rule {
301305
width: 20px;
302306
}
303307

308+
/* Hide the rules if the width of the container is too small.
309+
The cutoff point is chosen semi-arbitrary, it felt that
310+
when `width < 14em`, there are too many breaks. */
311+
@container rule (width < 14em) {
312+
main > .rule a span {
313+
display: none;
314+
}
315+
316+
main > .rule a::before {
317+
content: "[*]";
318+
}
319+
}
320+
304321
/* Align rules to various siblings */
305322
.rule:has(+ p),
306323
.rule:has(+ ul) {

0 commit comments

Comments
 (0)