diff --git a/lib/get-mini-toc-items.js b/lib/get-mini-toc-items.js
index dd17bd8cd8..c2ce162575 100644
--- a/lib/get-mini-toc-items.js
+++ b/lib/get-mini-toc-items.js
@@ -12,7 +12,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope
// return an array of objects containing each heading's contents, level, and optional platform.
// Article layout uses these as follows:
- // - `contents` to render the mini TOC headings
+ // - `title` and `link` to render the mini TOC headings
// - `headingLevel` the `2` in `h2`; used for determining required indentation
// - `platform` to show or hide platform-specific headings via client JS
@@ -38,7 +38,8 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope
// remove any tags but leave content
$('strong', item).map((i, el) => $(el).replaceWith($(el).contents()))
- const contents = `${$(item).html()}`
+ const link = href
+ const title = $(item).html()
const headingLevel = parseInt($(item)[0].name.match(/\d+/)[0], 10) || 0 // the `2` from `h2`
const platform = $(item).parent('.extended-markdown').attr('class') || ''
@@ -48,7 +49,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope
mostImportantHeadingLevel = headingLevel
}
- return { contents, headingLevel, platform }
+ return { link, title, headingLevel, platform }
})
.map((item) => {
// set the indentation level for each item based on the most important
diff --git a/tests/rendering/server.js b/tests/rendering/server.js
index 95a3f80e0f..8e63c21602 100644
--- a/tests/rendering/server.js
+++ b/tests/rendering/server.js
@@ -328,7 +328,7 @@ describe('server', () => {
test('renders mini TOC in articles with more than one heading', async () => {
const $ = await getDOM('/en/github/getting-started-with-github/githubs-products')
expect($('h2#in-this-article').length).toBe(1)
- expect($('h2#in-this-article + ul li a').length).toBeGreaterThan(1)
+ expect($('h2#in-this-article + div div ul').length).toBeGreaterThan(1)
})
test('renders mini TOC in articles that includes h3s when specified by frontmatter', async () => {
@@ -336,8 +336,8 @@ describe('server', () => {
'/en/admin/policies/enforcing-policies-for-your-enterprise/enforcing-policies-for-security-settings-in-your-enterprise'
)
expect($('h2#in-this-article').length).toBe(1)
- expect($('h2#in-this-article + ul li').length).toBeGreaterThan(0) // non-indented items
- expect($('h2#in-this-article + ul li ul.ml-3').length).toBeGreaterThan(0) // indented items
+ expect($('h2#in-this-article + div div ul').length).toBeGreaterThan(0) // non-indented items
+ expect($('h2#in-this-article + div div ul a div div div ul.ml-3').length).toBeGreaterThan(0) // indented items
})
test('does not render mini TOC in articles with only one heading', async () => {
@@ -361,14 +361,14 @@ describe('server', () => {
const $ = await getDOM(
'/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates'
)
- expect($('h2#in-this-article + ul li a[href="#package-ecosystem"]').length).toBe(1)
+ expect($('h2#in-this-article + div div ul a[href="#package-ecosystem"]').length).toBe(1)
})
test('renders mini TOC with correct links when headings contain markup in localized content', async () => {
const $ = await getDOM(
'/ja/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates'
)
- expect($('h2#in-this-article + ul li a[href="#package-ecosystem"]').length).toBe(1)
+ expect($('h2#in-this-article + div div ul a[href="#package-ecosystem"]').length).toBe(1)
})
})
@@ -878,9 +878,15 @@ describe('extended Markdown', () => {
test('renders expected mini TOC headings in platform-specific content', async () => {
const $ = await getDOM('/en/github/using-git/associating-text-editors-with-git')
expect($('h2#in-this-article').length).toBe(1)
- expect($('h2#in-this-article + ul li.extended-markdown.mac').length).toBeGreaterThan(1)
- expect($('h2#in-this-article + ul li.extended-markdown.windows').length).toBeGreaterThan(1)
- expect($('h2#in-this-article + ul li.extended-markdown.linux').length).toBeGreaterThan(1)
+ expect(
+ $('h2#in-this-article + div div ul a div div div.extended-markdown.mac').length
+ ).toBeGreaterThan(1)
+ expect(
+ $('h2#in-this-article + div div ul a div div div.extended-markdown.windows').length
+ ).toBeGreaterThan(1)
+ expect(
+ $('h2#in-this-article + div div ul a div div div.extended-markdown.linux').length
+ ).toBeGreaterThan(1)
})
})