Skip to content

Commit 83b32a0

Browse files
petebacondarwinalexeagle
authored andcommitted
build(aio): render heading anchors on the right
This approach simplifies the styling needed considerably. Previously, we had to make room on the left for heading that are in visual containers. Also we had to apply a `float:right` when on narrow screens as the gutter not available then. This float didn't render nicely if the heading text was longer than could be rendered on a single line. Closes angular#22131
1 parent 8d34364 commit 83b32a0

File tree

4 files changed

+8
-40
lines changed

4 files changed

+8
-40
lines changed
Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
11
.sidenav-content {
22
h1, h2, h3, h4, h5, h6 {
33

4-
&.no-anchor .header-link {
5-
display: none;
6-
}
7-
84
.header-link {
9-
box-sizing: border-box;
105
color: $mediumgray;
11-
display: inline-block;
12-
margin-left: -42px;
13-
padding: 0 8px;
6+
margin-left: 8px;
147
text-decoration: none;
158
user-select: none;
16-
vertical-align: middle;
179
visibility: hidden;
18-
width: 40px;
19-
20-
@media (max-width: 600px) {
21-
float: right;
22-
margin-left: 0;
23-
}
10+
display: inline-block;
11+
vertical-align: text-top;
2412
}
2513

2614
&:hover .header-link {
2715
visibility: visible;
2816
}
2917
}
30-
31-
.l-sub-section {
32-
h1, h2, h3, h4, h5, h6 {
33-
a {
34-
padding-right: 64px;
35-
margin-left: -74px;
36-
}
37-
}
38-
}
39-
40-
.alert {
41-
h1, h2, h3, h4, h5, h6 {
42-
a {
43-
padding-right: 80px;
44-
margin-left: -90px;
45-
}
46-
}
47-
}
4818
}

aio/tools/transforms/angular-base-package/post-processors/autolink-headings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const hasClass = (node, cls) => {
2020
const link = options =>
2121
tree => visit(tree, node => {
2222
if (is(node, HEADINGS) && has(node, 'id') && !hasClass(node, NO_ANCHOR_CLASS)) {
23-
node.children.unshift({
23+
node.children.push({
2424
type: 'element',
2525
tagName: 'a',
2626
properties: Object.assign(clone(options.properties), {href: `#${node.properties.id}`}),

aio/tools/transforms/angular-base-package/post-processors/autolink-headings.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ describe('autolink-headings postprocessor', () => {
2020
<h3>Heading with encoded chars &#x26;</h3>
2121
`;
2222
const processedContent = `
23-
<h1 id="heading-1"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-1"><i class="material-icons">link</i></a>Heading 1</h1>
24-
<h2 id="heading-with-bold"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-bold"><i class="material-icons">link</i></a>Heading with <strong>bold</strong></h2>
25-
<h3 id="heading-with-encoded-chars-"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-encoded-chars-"><i class="material-icons">link</i></a>Heading with encoded chars &#x26;</h3>
23+
<h1 id="heading-1">Heading 1<a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-1"><i class="material-icons">link</i></a></h1>
24+
<h2 id="heading-with-bold">Heading with <strong>bold</strong><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-bold"><i class="material-icons">link</i></a></h2>
25+
<h3 id="heading-with-encoded-chars-">Heading with encoded chars &#x26;<a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-encoded-chars-"><i class="material-icons">link</i></a></h3>
2626
`;
2727

2828
const docs = [{docType: 'a', renderedContent: originalContent}];

aio/tools/transforms/templates/api/base.template.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
{% if doc.experimental !== undefined %}<label class="api-status-label experimental">experimental</label>{% endif %}
3131
{% if doc.stable !== undefined %}<label class="api-status-label stable">stable</label>{% endif %}
3232
<label class="api-type-label {$ doc.docType $}">{$ doc.docType $}</label>
33-
<h1>
34-
{$ doc.name $}
35-
</h1>
33+
<h1>{$ doc.name $}</h1>
3634
<span class="version">{$ version $}</span>
3735
</header>
3836
<div class="page-actions">

0 commit comments

Comments
 (0)