@@ -52,31 +52,36 @@ export class MarkdownFile {
52
52
static parseDocumentationList ( { version, path, doc} ) {
53
53
const glossaryItems = [ ] ;
54
54
const articleElement = html `< markdown-content > ${ doc } </ markdown-content > ` ;
55
- dfs ( doc , null ) ;
55
+ dfs ( toc ( doc ) , null ) ;
56
56
return new MarkdownFile ( version , path , MarkdownFile . Type . DOCUMENTATION_LIST , glossaryItems ) ;
57
57
58
+ function toc ( element ) {
59
+ // Table of contents is an `ol` on the page
60
+ return html `< markdown-content > ${ element . querySelector ( ':scope > ol' ) } </ markdown-content > ` ;
61
+ }
62
+
58
63
function dfs ( element , parentItem ) {
59
- const lists = element . querySelectorAll ( ':scope > ul , :scope > ol ' ) ;
64
+ const lists = element . querySelectorAll ( ':scope > ol , :scope > ul ' ) ;
60
65
for ( const list of lists ) {
61
66
for ( const li of list . querySelectorAll ( ':scope > li' ) ) {
62
- const a = li . querySelector ( ':scope > a' ) ;
63
- if ( ! a || ! a . href )
64
- continue ;
67
+ let el = li . querySelector ( ':scope > a' ) ? li . querySelector ( ':scope > a' ) : li ;
65
68
const parentText = parentItem ? parentItem . name ( ) + ' > ' : '' ;
66
- const nameElement = html `${ parentText } < strong > ${ a . textContent } </ strong > ` ;
69
+ // If el is li, title needs to exclude textContent from child links
70
+ const title = el . childNodes [ 0 ] . textContent . trim ( ) ;
71
+ const nameElement = html `${ parentText } < strong > ${ title } </ strong > ` ;
67
72
const item = new GlossaryItem ( {
68
- githubLink : a . href ,
73
+ githubLink : el . href ,
69
74
parentItem,
70
75
highlightable : false ,
71
76
articleElement,
72
77
element : null ,
73
78
scrollAnchor : null ,
74
- url : a . hash ,
79
+ url : el . hash ,
75
80
name : nameElement . textContent ,
76
81
needleIndexes : computeNeedleIndexes ( nameElement ) ,
77
82
nameElement,
78
83
description : null ,
79
- title : a . textContent ,
84
+ title,
80
85
type : GlossaryItem . Type . Other ,
81
86
} ) ;
82
87
glossaryItems . push ( item ) ;
0 commit comments