Skip to content

Commit b14ba47

Browse files
authored
Merge 73e0cd0 into 15172ea
2 parents 15172ea + 73e0cd0 commit b14ba47

19 files changed

+51
-64
lines changed

templates/modern/src/docfx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ async function init() {
2727

2828
initTheme()
2929
enableSearch()
30-
renderInThisArticle()
3130

3231
await Promise.all([
32+
renderInThisArticle(),
3333
renderMarkdown(),
3434
renderNav(),
3535
highlight()

templates/modern/src/markdown.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import { breakWord, meta, loc, options } from './helper'
5-
import AnchorJs from 'anchor-js'
65
import { html, render } from 'lit-html'
76
import { getTheme, onThemeChange } from './theme'
87

@@ -19,7 +18,6 @@ export async function renderMarkdown() {
1918
renderClickableImage()
2019

2120
await Promise.all([
22-
renderAnchor(),
2321
renderMath(),
2422
renderMermaid()
2523
])
@@ -168,25 +166,6 @@ function renderLinks() {
168166
})
169167
}
170168

171-
/**
172-
* Render anchor # for headings
173-
*/
174-
async function renderAnchor() {
175-
const anchors = new AnchorJs()
176-
const { anchors: anchorsOptions } = await options()
177-
anchors.options = Object.assign({
178-
visible: 'hover',
179-
icon: '#'
180-
}, anchorsOptions)
181-
182-
anchors.add('article h2:not(.no-anchor), article h3:not(.no-anchor), article h4:not(.no-anchor)')
183-
184-
/* eslint-disable no-self-assign */
185-
if (location.hash) {
186-
location.href = location.href
187-
}
188-
}
189-
190169
/**
191170
* Render code copy button.
192171
*/

templates/modern/src/nav.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
import AnchorJs from 'anchor-js'
45
import { render, html, TemplateResult } from 'lit-html'
56
import { breakWordLit, meta, isExternalHref, loc, options } from './helper'
67
import { themePicker } from './theme'
@@ -95,34 +96,41 @@ export function renderBreadcrumb(breadcrumb: (NavItem | TocNode)[]) {
9596
}
9697
}
9798

98-
export function renderInThisArticle() {
99+
export async function renderInThisArticle() {
100+
await renderAnchors()
99101
const affix = document.getElementById('affix')
100102
if (affix) {
101-
render(document.body.getAttribute('data-yaml-mime') === 'ManagedReference' ? inThisArticleForManagedReference() : inThisArticleForConceptual(), affix)
103+
render(inThisArticle(), affix)
102104
}
103105
}
104106

105-
function inThisArticleForConceptual() {
106-
const headings = document.querySelectorAll<HTMLHeadingElement>('article h2')
107-
if (headings.length > 0) {
108-
return html`
109-
<h5 class="border-bottom">${loc('inThisArticle')}</h5>
110-
<ul>${Array.from(headings).map(h => html`<li><a class="link-secondary" href="#${h.id}">${breakWordLit(h.innerText)}</a></li>`)}</ul>`
107+
async function renderAnchors() {
108+
const anchors = new AnchorJs()
109+
const { anchors: anchorsOptions } = await options()
110+
anchors.options = Object.assign({
111+
visible: 'hover',
112+
icon: '#'
113+
}, anchorsOptions)
114+
115+
anchors.add('article h2:not(.no-anchor), article h3:not(.no-anchor), article h4:not(.no-anchor)')
116+
117+
/* eslint-disable no-self-assign */
118+
if (location.hash) {
119+
location.href = location.href
111120
}
112121
}
113122

114-
function inThisArticleForManagedReference(): TemplateResult {
115-
let headings = Array.from(document.querySelectorAll<HTMLHeadingElement>('article h2, article h3'))
116-
headings = headings.filter((h, i) => h.tagName === 'H3' || headings[i + 1]?.tagName === 'H3')
123+
function inThisArticle(): TemplateResult {
124+
const headings = Array.from(document.querySelectorAll<HTMLHeadingElement>('article h2, article h3'))
125+
console.log(headings)
117126

118127
if (headings.length > 0) {
119128
return html`
120129
<h5 class="border-bottom">${loc('inThisArticle')}</h5>
121-
<ul>${headings.map(h => {
122-
return h.tagName === 'H2'
123-
? html`<li><h6>${breakWordLit(h.innerText)}</h6></li>`
130+
<ul>${headings.map(h => h.tagName === 'H2'
131+
? html`<li><a class="link-body-emphasis" href="#${h.id}">${breakWordLit(h.innerText)}</a></li>`
124132
: html`<li><a class="link-secondary" href="#${h.id}">${breakWordLit(h.innerText)}</a></li>`
125-
})}</ul>`
133+
)}</ul>`
126134
}
127135
}
128136

Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)