Skip to content

Commit e407424

Browse files
committed
Add headings
1 parent 510683f commit e407424

File tree

9 files changed

+188
-36
lines changed

9 files changed

+188
-36
lines changed

docs/docset.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ toc:
7979
- folder: syntax
8080
children:
8181
- file: index.md
82+
- file: headings.md
8283
- file: admonitions.md
8384
- file: applies.md
8485
- file: automated_settings.md
@@ -124,4 +125,4 @@ toc:
124125
- file: bar.md
125126
- folder: baz
126127
children:
127-
- file: qux.md
128+
- file: qux.md

docs/syntax/headings.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Headings
2+
3+
You can have up to 6 levels of headings. But only levels 2 and 3 are displayed in table of contents sidebar.
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} HTML
24+
25+
```html
26+
<div class="heading-wrapper" id="heading-1">
27+
<h1>
28+
<a class="headerlink" href="#heading-1">Heading 1</a>
29+
</h1>
30+
</div>
31+
```
32+
33+
:::
34+
35+
:::{tab-item} Output
36+
37+
# Heading 1
38+
39+
## Heading 2
40+
41+
### Heading 3
42+
43+
#### Heading 4
44+
45+
##### Heading 5
46+
47+
###### Heading 6
48+
49+
:::
50+
51+
::::
52+
53+
:::{note}
54+
55+
- Every page has to start with a level 1 heading.
56+
- You should use only one level 1 heading per page.
57+
- Headings inside directives like tabs or dropdowns causes the table of contents indicator to behave unexpectedly.
58+
- If you are using the same heading text multiple times you should use a custom [anchor link](#anchor-links) to avoid conflicts.
59+
60+
:::
61+
62+
## Anchor Links
63+
64+
By default, the anchor links are generated based on the heading text. You can also specify a custom anchor link using the following syntax:
65+
66+
### Default Anchor Link
67+
68+
::::{tab-set}
69+
70+
:::{tab-item} Markdown
71+
72+
```markdown
73+
74+
## Hello-World
75+
76+
```
77+
78+
:::
79+
80+
:::{tab-item} Output
81+
82+
## Hello-World
83+
84+
:::
85+
86+
::::
87+
88+
89+
### Custom Anchor Link
90+
91+
::::{tab-set}
92+
93+
:::{tab-item} Markdown
94+
95+
```markdown
96+
97+
## Heading [#custom-anchor]
98+
99+
```
100+
101+
:::
102+
103+
:::{tab-item} Output
104+
105+
## Heading [#custom-anchor]
106+
107+
:::
108+
109+
::::

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)