Skip to content

Commit c1104aa

Browse files
authored
Merge branch 'main' into repo-sync
2 parents 2ac8467 + 5a809be commit c1104aa

4 files changed

Lines changed: 17 additions & 24 deletions

File tree

components/article/ArticlePage.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,16 @@ export const ArticlePage = () => {
4343
const { t } = useTranslation('pages')
4444
const currentPath = router.asPath.split('?')[0]
4545

46-
const RenderHTML = (props: { html: any }) => (
47-
<div dangerouslySetInnerHTML={{ __html: props.html }}></div>
48-
)
49-
5046
const renderTocItem = (item: MiniTocItem) => {
5147
return (
5248
<ActionList.Item
53-
as="a"
54-
href={item.link}
55-
key={item.title}
49+
as="div"
50+
key={item.contents}
51+
className={item.platform}
5652
sx={{ listStyle: 'none', padding: '2px' }}
5753
>
58-
<div className={cx('lh-condensed', item.platform)}>
59-
<RenderHTML html={item.title} />
54+
<div className={cx('lh-condensed')}>
55+
<div dangerouslySetInnerHTML={{ __html: item.contents }} />
6056
{item.items && item.items.length > 0 ? (
6157
<ul className="ml-3">{item.items.map(renderTocItem)}</ul>
6258
) : null}
@@ -126,9 +122,10 @@ export const ArticlePage = () => {
126122
</Heading>
127123

128124
<ActionList
129-
items={miniTocItems.map((items, i) => {
125+
key={title}
126+
items={miniTocItems.map((items) => {
130127
return {
131-
key: title + i,
128+
key: title,
132129
text: title,
133130
renderItem: () => <ul>{renderTocItem(items)}</ul>,
134131
}

components/context/ArticleContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export type LearningTrack = {
99

1010
export type MiniTocItem = {
1111
platform: string
12-
title: string
13-
link: string
12+
contents: string
1413
items?: MiniTocItem[]
1514
}
1615

lib/get-mini-toc-items.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope
3838
// remove any <strong> tags but leave content
3939
$('strong', item).map((i, el) => $(el).replaceWith($(el).contents()))
4040

41-
const link = href
42-
const title = $(item).html()
41+
const contents = `<a href="${href}">${$(item).html()}</a>`
4342
const headingLevel = parseInt($(item)[0].name.match(/\d+/)[0], 10) || 0 // the `2` from `h2`
4443

4544
const platform = $(item).parent('.extended-markdown').attr('class') || ''
@@ -49,7 +48,7 @@ export default function getMiniTocItems(html, maxHeadingLevel = 2, headingScope
4948
mostImportantHeadingLevel = headingLevel
5049
}
5150

52-
return { link, title, headingLevel, platform }
51+
return { contents, headingLevel, platform }
5352
})
5453
.map((item) => {
5554
// set the indentation level for each item based on the most important

tests/rendering/server.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ describe('server', () => {
337337
)
338338
expect($('h2#in-this-article').length).toBe(1)
339339
expect($('h2#in-this-article + div div ul').length).toBeGreaterThan(0) // non-indented items
340-
expect($('h2#in-this-article + div div ul a div div div ul.ml-3').length).toBeGreaterThan(0) // indented items
340+
expect($('h2#in-this-article + div div ul div div div div ul.ml-3').length).toBeGreaterThan(0) // indented items
341341
})
342342

343343
test('does not render mini TOC in articles with only one heading', async () => {
@@ -878,15 +878,13 @@ describe('extended Markdown', () => {
878878
test('renders expected mini TOC headings in platform-specific content', async () => {
879879
const $ = await getDOM('/en/github/using-git/associating-text-editors-with-git')
880880
expect($('h2#in-this-article').length).toBe(1)
881+
expect($('h2#in-this-article + div div ul div.extended-markdown.mac').length).toBeGreaterThan(1)
881882
expect(
882-
$('h2#in-this-article + div div ul a div div div.extended-markdown.mac').length
883-
).toBeGreaterThan(1)
884-
expect(
885-
$('h2#in-this-article + div div ul a div div div.extended-markdown.windows').length
886-
).toBeGreaterThan(1)
887-
expect(
888-
$('h2#in-this-article + div div ul a div div div.extended-markdown.linux').length
883+
$('h2#in-this-article + div div ul div.extended-markdown.windows').length
889884
).toBeGreaterThan(1)
885+
expect($('h2#in-this-article + div div ul div.extended-markdown.linux').length).toBeGreaterThan(
886+
1
887+
)
890888
})
891889
})
892890

0 commit comments

Comments
 (0)