Skip to content

Commit 53874f8

Browse files
authored
Add headings (#497)
* Add headings * Update docs
1 parent 3219502 commit 53874f8

File tree

9 files changed

+180
-36
lines changed

9 files changed

+180
-36
lines changed

docs/docset.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ external_hosts:
2626
- atlassian.net
2727
- elastic.dev
2828
- visualstudio.com
29+
- wikipedia.org
2930
exclude:
3031
- '_*.md'
3132
subs:
@@ -81,6 +82,7 @@ toc:
8182
- folder: syntax
8283
children:
8384
- file: index.md
85+
- file: headings.md
8486
- file: admonitions.md
8587
- file: applies.md
8688
- file: automated_settings.md
@@ -126,4 +128,4 @@ toc:
126128
- file: bar.md
127129
- folder: baz
128130
children:
129-
- file: qux.md
131+
- file: qux.md

docs/syntax/headings.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Headings
2+
3+
You create a heading by adding number signs `#` in front of a word or phrase. The number of number signs you use should correspond to the heading level. For example, to create a heading level three `<h3>`, use three number signs (e.g., `### My Header`).
4+
5+
## Basics
6+
7+
::::{tab-set}
8+
9+
:::{tab-item} Markdown
10+
11+
```markdown
12+
# Heading 1
13+
## Heading 2
14+
### Heading 3
15+
#### Heading 4
16+
##### Heading 5
17+
###### Heading 6
18+
19+
```
20+
21+
:::
22+
23+
:::{tab-item} Output
24+
25+
# Heading 1
26+
27+
## Heading 2
28+
29+
### Heading 3
30+
31+
#### Heading 4
32+
33+
##### Heading 5
34+
35+
###### Heading 6
36+
37+
:::
38+
39+
::::
40+
41+
:::{note}
42+
43+
- Every page has to start with a level 1 heading.
44+
- You should use only one level 1 heading per page.
45+
- Headings inside directives like tabs or dropdowns causes the table of contents indicator to behave unexpectedly.
46+
- If you are using the same heading text multiple times you should use a custom [anchor link](#anchor-links) to avoid conflicts.
47+
48+
:::
49+
50+
## Anchor Links
51+
52+
By default, the anchor links are generated based on the heading text.
53+
You will get a hyphened, lowercase, alphanumeric version of any string you please, with any [diacritics](https://en.wikipedia.org/wiki/Diacritic) removed, whitespace and dashes collapsed, and whitespace trimmed.
54+
55+
### Default Anchor Links
56+
57+
::::{tab-set}
58+
59+
:::{tab-item} Markdown
60+
61+
```markdown
62+
63+
#### Hello-World
64+
65+
```
66+
67+
:::
68+
69+
:::{tab-item} Output
70+
71+
#### Hello-World
72+
73+
:::
74+
75+
::::
76+
77+
78+
### Custom Anchor Links
79+
80+
You can also specify a custom anchor link using the following syntax.
81+
82+
::::{tab-set}
83+
84+
:::{tab-item} Markdown
85+
86+
```markdown
87+
88+
#### Heading [#custom-anchor]
89+
90+
```
91+
92+
:::
93+
94+
:::{tab-item} Output
95+
96+
#### Heading [#custom-anchor]
97+
98+
:::
99+
100+
::::

src/Elastic.Markdown/Assets/markdown/list.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#elastic-docs-v3 {
1+
.markdown-content {
22
ol,ul {
33
font-family: "Inter", sans-serif;
44
@apply text-base text-body mb-6;

src/Elastic.Markdown/Assets/markdown/tabs.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616

1717
.tabs-content {
18-
@apply w-full order-99 border-t-1 border-gray-300 pl-6 pt-4 z-0 hidden;
18+
@apply w-full order-99 border-t-1 border-gray-300 px-6 pt-4 z-0 hidden;
1919
transform: translateY(-1px);
2020
}
2121

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
1-
#elastic-docs-v3 {
1+
.markdown-content {
2+
3+
font-size: 16px;
24

35
h1 {
46
font-family: "Mier B", "Inter", sans-serif;
5-
@apply text-4xl text-black mb-6 mt-4;
7+
@apply text-5xl text-black mb-6 mt-5;
68
line-height: 1.2em;
79
letter-spacing: -0.04em;
810
}
911

1012
h2 {
1113
font-family: "Mier B", "Inter", sans-serif;
12-
@apply text-2xl text-black mb-6 mt-4;
14+
@apply text-4xl text-black mb-6 mt-8;
1315
line-height: 1.2em;
14-
letter-spacing: -0.02em;
16+
letter-spacing: -0.04em;
1517
}
1618

1719
h3 {
1820
font-family: "Mier B", "Inter", sans-serif;
19-
@apply text-xl text-black font-bold mb-6 mt-4;
21+
@apply text-2xl text-black mb-6 mt-6;
22+
line-height: 1.2em;
23+
letter-spacing: -0.02em;
24+
}
25+
26+
h4 {
27+
font-family: "Mier B", "Inter", sans-serif;
28+
@apply text-base text-black font-bold mb-5 mt-5;
29+
line-height: 1.2em;
30+
letter-spacing: -0.02em;
31+
}
32+
33+
h5 {
34+
font-family: "Mier B", "Inter", sans-serif;
35+
@apply text-sm text-black font-bold mb-4 mt-5;
36+
line-height: 1.2em;
37+
letter-spacing: -0.02em;
38+
}
39+
40+
h6 {
41+
font-family: "Mier B", "Inter", sans-serif;
42+
@apply text-xs text-black font-bold mb-3 mt-3;
2043
line-height: 1.2em;
2144
letter-spacing: -0.02em;
2245
}
2346

47+
h1, h2, h3, h4, h5, h6 {
48+
a {
49+
font-family: "Mier B", "Inter", sans-serif;
50+
@apply text-black hover:text-black no-underline;
51+
}
52+
}
53+
2454
p {
2555
font-family: "Inter", sans-serif;
2656
@apply text-base text-ink text-body mb-6;
@@ -30,6 +60,6 @@
3060

3161
a {
3262
font-family: "Inter", sans-serif;
33-
@apply text-blue-elastic underline hover:text-blue-800;
63+
@apply text-blue-elastic hover:text-blue-800 underline;
3464
}
3565
}

src/Elastic.Markdown/Assets/toc-nav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function findCurrentTocLinks(elements: TocElements): HTMLAnchorElement[] {
3232
}
3333
currentTop = rect.top;
3434
const foundLink = elements.tocLinks.find(link =>
35-
link.getAttribute('href') === `#${heading.closest('section')?.id}`
35+
link.getAttribute('href') === `#${heading.closest('.heading-wrapper')?.id}`
3636
);
3737
if (foundLink) {
3838
currentTocLinks.push(foundLink);

src/Elastic.Markdown/Myst/SectionedHeadingRenderer.cs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,43 @@ protected override void Write(HtmlRenderer renderer, HeadingBlock obj)
3838

3939
var slug = slugTarget.Slugify();
4040

41-
renderer.Write(@"<section id=""");
42-
renderer.Write(slug);
43-
renderer.Write(@""">");
41+
var isRedesign = Environment.GetEnvironmentVariable("REDESIGN") == "true";
4442

45-
renderer.Write('<');
46-
renderer.Write(headingText);
47-
renderer.WriteAttributes(obj);
48-
renderer.Write('>');
49-
50-
renderer.WriteLeafInline(obj);
51-
52-
53-
// language=html
54-
renderer.WriteLine($@"<a class=""headerlink"" href=""#{slug}"" title=""Link to this heading"">¶</a>");
55-
56-
renderer.Write("</");
57-
renderer.Write(headingText);
58-
renderer.WriteLine('>');
59-
60-
renderer.Write("</section>");
61-
62-
renderer.EnsureLine();
43+
if (isRedesign)
44+
{
45+
renderer.Write(@"<div class=""heading-wrapper"" id=""");
46+
renderer.Write(slug);
47+
renderer.Write(@""">");
48+
renderer.Write('<');
49+
renderer.Write(headingText);
50+
renderer.WriteAttributes(obj);
51+
renderer.Write('>');
52+
renderer.Write($"""<a class="headerlink" href="#{slug}">""");
53+
renderer.WriteLeafInline(obj);
54+
renderer.Write("</a>");
55+
renderer.Write("</");
56+
renderer.Write(headingText);
57+
renderer.WriteLine('>');
58+
renderer.Write("</div>");
59+
renderer.EnsureLine();
60+
}
61+
else
62+
{
63+
renderer.Write(@"<section id=""");
64+
renderer.Write(slug);
65+
renderer.Write(@""">");
66+
renderer.Write('<');
67+
renderer.Write(headingText);
68+
renderer.WriteAttributes(obj);
69+
renderer.Write('>');
70+
renderer.WriteLeafInline(obj);
71+
// language=html
72+
renderer.WriteLine($@"<a class=""headerlink"" href=""#{slug}"" title=""Link to this heading"">¶</a>");
73+
renderer.Write("</");
74+
renderer.Write(headingText);
75+
renderer.WriteLine('>');
76+
renderer.Write("</section>");
77+
renderer.EnsureLine();
78+
}
6379
}
6480
}

src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,5 @@
1818
}
1919
<li class="inline text-gray-500 text-sm leading-[1.2em] tracking-[-0.02em]" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem">
2020
<span class="px-1">/</span>
21-
<a itemprop="item" href="@Model.CurrentDocument.Url" class="pointer-events-none">
22-
<span itemprop="name" class="hover:text-ink">@Model.CurrentDocument.NavigationTitle</span>
23-
</a>
24-
<meta itemprop="position" content="1">
2521
</li>
2622
</ol>

src/Elastic.Markdown/Slices/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="content-container">
2121
@await RenderPartialAsync(_Breadcrumbs.Create(Model))
2222
</div>
23-
<article class="content-container">
23+
<article class="content-container markdown-content">
2424
@await RenderBodyAsync()
2525
</article>
2626
<footer class="content-container mt-20">

0 commit comments

Comments
 (0)