diff --git a/lib/services/menu.service.spec.ts b/lib/services/menu.service.spec.ts index 3596fede..20f728eb 100644 --- a/lib/services/menu.service.spec.ts +++ b/lib/services/menu.service.spec.ts @@ -11,7 +11,7 @@ import { Hash } from './hash.service'; import { LazyTasksService } from '../shared/components/LazyFor/lazy-for'; import { ScrollService } from './scroll.service'; import { SchemaHelper } from './schema-helper.service'; -import { SpecManager } from '../utils/spec-manager';; +import { SpecManager } from '../utils/spec-manager'; describe('Menu service', () => { beforeEach(() => { diff --git a/lib/utils/md-renderer.spec.ts b/lib/utils/md-renderer.spec.ts new file mode 100644 index 00000000..ffd1efe4 --- /dev/null +++ b/lib/utils/md-renderer.spec.ts @@ -0,0 +1,23 @@ +'use strict'; + +import { MdRenderer } from '../../lib/utils/md-renderer'; + +describe('Utils', () => { + describe('Markdown renderer', () => { + let mdRender; + beforeEach(() => { + mdRender = new MdRenderer(); + }); + it('should return a level-1 heading even though level-2 is passed', () => { + mdRender.renderMd('## Sub Intro'); + expect(mdRender.firstLevelHeadings.length).toEqual(1); + expect(mdRender.firstLevelHeadings).toEqual(['Sub Intro']); + }); + it('should return a level-1 heading and a level-2', () => { + mdRender.renderMd('# Introduction \n ## Sub Intro'); + expect(mdRender.firstLevelHeadings.length).toEqual(1); + expect(mdRender.firstLevelHeadings).toEqual(['Introduction']); + expect(mdRender.secondLevelHeadings).toEqual(['Introduction/Sub Intro']); + }); + }); +}); diff --git a/lib/utils/md-renderer.ts b/lib/utils/md-renderer.ts index d4c6ab0d..0b9124be 100644 --- a/lib/utils/md-renderer.ts +++ b/lib/utils/md-renderer.ts @@ -14,7 +14,7 @@ const md = new Remarkable({ highlight: (str, lang) => { if (lang === 'json') lang = 'js'; let grammar = Prism.languages[lang]; - //fallback to clike + // fallback to click if (!grammar) return str; return Prism.highlight(str, grammar); } @@ -107,6 +107,10 @@ 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; diff --git a/tests/unit/SpecManager.spec.ts b/tests/unit/SpecManager.spec.ts index 935d73fd..942fd9f8 100644 --- a/tests/unit/SpecManager.spec.ts +++ b/tests/unit/SpecManager.spec.ts @@ -15,7 +15,7 @@ describe('Utils', () => { it('load should reject promise for invalid url', (done)=> { specMgr.load('/nonexisting/schema.json').then(() => { - throw new Error('Succees handler should not be called'); + throw new Error('Success handler should not be called'); }, () => { done(); });