fix(heading): fix for headings render making failsafe, adding test, adjusting some commentary and spelling/typos

This commit is contained in:
jsmartfo 2017-01-30 17:11:01 -07:00 committed by Roman Hotsiy
parent c4f25cc53d
commit d9bec1bd6a
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 30 additions and 3 deletions

View File

@ -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(() => {

View File

@ -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']);
});
});
});

View File

@ -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;

View File

@ -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();
});