Skip to content

Commit 7e5c7f4

Browse files
authored
Merge pull request sveltejs#5 from sveltejs/header-markup
Header markup
2 parents 321fe3a + b770467 commit 7e5c7f4

File tree

8 files changed

+48
-70
lines changed

8 files changed

+48
-70
lines changed

src/format/fixtures/api-docs-html.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/format/headings.test.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
linkify_headings,
1616
strip_h1,
1717
increment_headings,
18-
validate_headings,
1918
} from "./headings";
2019

2120
const { process: linkify_only } = unified()
@@ -53,7 +52,7 @@ _headings("transforms and formats headings", async () => {
5352

5453
assert.equal(
5554
output.contents,
56-
`<h3><span id="section-hello" class="offset-anchor"></span><a href="http://github.com/blog#section-hello" class="anchor" aria-hidden></a>hello</h3>`
55+
`<h3 id="section-hello">hello</h3>`
5756
);
5857
});
5958

@@ -81,8 +80,8 @@ _headings("transforms and formats multi-level headings", async () => {
8180

8281
assert.equal(
8382
output.contents,
84-
`<h3><span id="subsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection" class="anchor" aria-hidden></a>subsection</h3>
85-
<h4><span id="subsection-subsubsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection-subsubsection" class="anchor" aria-hidden></a>subsubsection</h4>`
83+
`<h3 id="subsection">subsection</h3>
84+
<h4 id="subsection-subsubsection">subsubsection</h4>`
8685
);
8786
});
8887

@@ -113,9 +112,9 @@ _headings("transforms and formats multi-level headings", async () => {
113112

114113
assert.equal(
115114
output.contents,
116-
`<h3><span id="subsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection" class="anchor" aria-hidden></a>subsection</h3>
117-
<h4><span id="subsection-subsubsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection-subsubsection" class="anchor" aria-hidden></a>subsubsection</h4>
118-
<h5><span id="subsection-subsubsection-subsubsubsection" class="offset-anchor" data-scrollignore></span><a href="http://github.com/blog#subsection-subsubsection-subsubsubsection" class="anchor" aria-hidden></a>subsubsubsection</h5>`
115+
`<h3 id="subsection">subsection</h3>
116+
<h4 id="subsection-subsubsection">subsubsection</h4>
117+
<h5 id="subsection-subsubsection-subsubsubsection">subsubsubsection</h5>`
119118
);
120119
});
121120

@@ -154,13 +153,13 @@ _headings("transforms and formats multi-level headings", async () => {
154153

155154
assert.equal(
156155
output.contents,
157-
`<h3><span id="subsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection" class="anchor" aria-hidden></a>subsection</h3>
158-
<h4><span id="subsection-subsubsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection-subsubsection" class="anchor" aria-hidden></a>subsubsection</h4>
159-
<h5><span id="subsection-subsubsection-subsubsubsection" class="offset-anchor" data-scrollignore></span><a href="http://github.com/blog#subsection-subsubsection-subsubsubsection" class="anchor" aria-hidden></a>subsubsubsection</h5>
160-
<h3><span id="one" class="offset-anchor"></span><a href="http://github.com/blog#one" class="anchor" aria-hidden></a>one</h3>
161-
<h4><span id="one-two" class="offset-anchor"></span><a href="http://github.com/blog#one-two" class="anchor" aria-hidden></a>two</h4>
162-
<h5><span id="one-two-three" class="offset-anchor" data-scrollignore></span><a href="http://github.com/blog#one-two-three" class="anchor" aria-hidden></a>three</h5>
163-
<h4><span id="one-four" class="offset-anchor"></span><a href="http://github.com/blog#one-four" class="anchor" aria-hidden></a>four</h4>`
156+
`<h3 id="subsection">subsection</h3>
157+
<h4 id="subsection-subsubsection">subsubsection</h4>
158+
<h5 id="subsection-subsubsection-subsubsubsection">subsubsubsection</h5>
159+
<h3 id="one">one</h3>
160+
<h4 id="one-two">two</h4>
161+
<h5 id="one-two-three">three</h5>
162+
<h4 id="one-four">four</h4>`
164163
);
165164
});
166165

@@ -201,13 +200,13 @@ _headings(
201200

202201
assert.equal(
203202
output.contents,
204-
`<h2><span id="subsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection" class="anchor" aria-hidden></a>subsection</h2>
205-
<h3><span id="subsection-subsubsection" class="offset-anchor"></span><a href="http://github.com/blog#subsection-subsubsection" class="anchor" aria-hidden></a>subsubsection</h3>
206-
<h4><span id="subsection-subsubsection-subsubsubsection" class="offset-anchor" data-scrollignore></span><a href="http://github.com/blog#subsection-subsubsection-subsubsubsection" class="anchor" aria-hidden></a>subsubsubsection</h4>
207-
<h2><span id="one" class="offset-anchor"></span><a href="http://github.com/blog#one" class="anchor" aria-hidden></a>one</h2>
208-
<h3><span id="one-two" class="offset-anchor"></span><a href="http://github.com/blog#one-two" class="anchor" aria-hidden></a>two</h3>
209-
<h4><span id="one-two-three" class="offset-anchor" data-scrollignore></span><a href="http://github.com/blog#one-two-three" class="anchor" aria-hidden></a>three</h4>
210-
<h3><span id="one-four" class="offset-anchor"></span><a href="http://github.com/blog#one-four" class="anchor" aria-hidden></a>four</h3>`
203+
`<h2 id="subsection">subsection</h2>
204+
<h3 id="subsection-subsubsection">subsubsection</h3>
205+
<h4 id="subsection-subsubsection-subsubsubsection">subsubsubsection</h4>
206+
<h2 id="one">one</h2>
207+
<h3 id="one-two">two</h3>
208+
<h4 id="one-two-three">three</h4>
209+
<h3 id="one-four">four</h3>`
211210
);
212211
}
213212
);
@@ -242,10 +241,10 @@ _headings(
242241

243242
assert.equal(
244243
output.contents,
245-
`<h3><span id="component-format-script" class="offset-anchor"></span><a href="http://github.com/docs#component-format-script" class="anchor" aria-hidden></a>script</h3>
246-
<h4><span id="component-format-script-one" class="offset-anchor"></span><a href="http://github.com/docs#component-format-script-one" class="anchor" aria-hidden></a>one</h4>
247-
<h5><span id="component-format-script-one-two" class="offset-anchor" data-scrollignore></span><a href="http://github.com/docs#component-format-script-one-two" class="anchor" aria-hidden></a>two</h5>
248-
<h3><span id="component-format-style" class="offset-anchor"></span><a href="http://github.com/docs#component-format-style" class="anchor" aria-hidden></a>style</h3>`
244+
`<h3 id="component-format-script">script</h3>
245+
<h4 id="component-format-script-one">one</h4>
246+
<h5 id="component-format-script-one-two">two</h5>
247+
<h3 id="component-format-style">style</h3>`
249248
);
250249

251250
//@ts-ignore

src/format/headings.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,7 @@ export function linkify_headings(): Transformer {
131131
if (!node.data.hProperties) node.data.hProperties = {};
132132
if (!node.data.hChildren) node.data.hChildren = [];
133133

134-
const span_node = {
135-
type: "element",
136-
tagName: "span",
137-
properties: { id: [slug], className: ["offset-anchor"] },
138-
};
139-
140-
const a_node = {
141-
type: "element",
142-
tagName: "a",
143-
properties: {
144-
href: `${data.dir}#${slug}`,
145-
className: ["anchor"],
146-
"aria-hidden": true,
147-
},
148-
};
149-
150-
if (node.depth > data.base_level + 1)
151-
//@ts-ignore
152-
span_node.properties["data-scrollignore"] = true;
153-
154-
node.data.hChildren = [span_node, a_node];
155-
134+
node.data.hProperties.id = slug;
156135
children.forEach((v) => node.data.hChildren.push(v));
157136
});
158137
};

src/fs/fixtures/output-repo-1.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)