mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-26 10:33:44 +03:00
fix(heading): fix for headings render making failsafe, adding test, adjusting some commentary and spelling/typos
This commit is contained in:
parent
c4f25cc53d
commit
d9bec1bd6a
|
@ -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(() => {
|
||||
|
|
23
lib/utils/md-renderer.spec.ts
Normal file
23
lib/utils/md-renderer.spec.ts
Normal 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']);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user