diff --git a/lib/components/Search/redoc-search.ts b/lib/components/Search/redoc-search.ts index 03d6806d..231bbfdc 100644 --- a/lib/components/Search/redoc-search.ts +++ b/lib/components/Search/redoc-search.ts @@ -34,7 +34,8 @@ export class RedocSearch implements OnInit { this.items = Object.keys(searchRes).map(id => ({ menuItem: this.menu.getItemById(id), pointers: searchRes[id].map(el => el.pointer) - })); + })).filter(res => !!res.menuItem); + this.items.sort((a, b) => { if (a.menuItem.depth > b.menuItem.depth) return 1; else if (a.menuItem.depth < b.menuItem.depth) return -1; diff --git a/lib/utils/md-renderer.spec.ts b/lib/utils/md-renderer.spec.ts index ffd1efe4..ec3ea647 100644 --- a/lib/utils/md-renderer.spec.ts +++ b/lib/utils/md-renderer.spec.ts @@ -4,20 +4,21 @@ import { MdRenderer } from '../../lib/utils/md-renderer'; describe('Utils', () => { describe('Markdown renderer', () => { - let mdRender; + let mdRender: MdRenderer; beforeEach(() => { mdRender = new MdRenderer(); }); - it('should return a level-1 heading even though level-2 is passed', () => { + it('should return a level-1 heading even though only level-2 is present', () => { mdRender.renderMd('## Sub Intro'); - expect(mdRender.firstLevelHeadings.length).toEqual(1); - expect(mdRender.firstLevelHeadings).toEqual(['Sub Intro']); + Object.keys(mdRender.headings).length.should.be.equal(1); + should.exist(mdRender.headings['sub-intro']); }); - it('should return a level-1 heading and a level-2', () => { + it('should return a level-2 heading as a child of level-1', () => { mdRender.renderMd('# Introduction \n ## Sub Intro'); - expect(mdRender.firstLevelHeadings.length).toEqual(1); - expect(mdRender.firstLevelHeadings).toEqual(['Introduction']); - expect(mdRender.secondLevelHeadings).toEqual(['Introduction/Sub Intro']); + Object.keys(mdRender.headings).length.should.be.equal(1); + should.exist(mdRender.headings['introduction']); + should.exist(mdRender.headings['introduction'].children); + Object.keys(mdRender.headings['introduction'].children).length.should.be.equal(1); }); }); }); diff --git a/lib/utils/md-renderer.ts b/lib/utils/md-renderer.ts index 0b9124be..5bf333f9 100644 --- a/lib/utils/md-renderer.ts +++ b/lib/utils/md-renderer.ts @@ -107,10 +107,6 @@ export class MdRenderer { return this._origRules.open(tokens, idx); } else { let content = tokens[idx + 1].content; - // if no h1 1st, convert h2 to h1 - if (this.firstLevelHeadings.length === 0 && tokens[idx].hLevel !== 1 ) { - tokens[idx].hLevel = 1; - } if (tokens[idx].hLevel === 1 ) { this.currentTopHeading = this.saveHeading(content);; let id = this.currentTopHeading.id;