mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-18 10:50:32 +03:00
chore: fix lint errors and test
This commit is contained in:
parent
32cd670a89
commit
f31a031a63
|
@ -1,9 +1,9 @@
|
||||||
import * as Remarkable from 'remarkable';
|
import * as Remarkable from 'remarkable';
|
||||||
|
|
||||||
|
import slugify from 'slugify';
|
||||||
import { MDComponent } from '../components/Markdown/Markdown';
|
import { MDComponent } from '../components/Markdown/Markdown';
|
||||||
import { highlight, html2Str } from '../utils';
|
import { highlight, html2Str } from '../utils';
|
||||||
import { SECTION_ATTR } from './MenuStore';
|
import { SECTION_ATTR } from './MenuStore';
|
||||||
import slugify from 'slugify';
|
|
||||||
|
|
||||||
const md = new Remarkable('default', {
|
const md = new Remarkable('default', {
|
||||||
html: true,
|
html: true,
|
||||||
|
@ -47,6 +47,7 @@ export class MarkdownRenderer {
|
||||||
const item = {
|
const item = {
|
||||||
id: 'section' + '/' + slugify(name),
|
id: 'section' + '/' + slugify(name),
|
||||||
name,
|
name,
|
||||||
|
items: [],
|
||||||
};
|
};
|
||||||
container.push(item);
|
container.push(item);
|
||||||
return item;
|
return item;
|
||||||
|
@ -139,8 +140,8 @@ export class MarkdownRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
extractHeadings(rawText: string): MarkdownHeading[] {
|
extractHeadings(rawText: string): MarkdownHeading[] {
|
||||||
const md = this.renderMd(rawText, false);
|
const text = this.renderMd(rawText, false);
|
||||||
this.attachHeadingsDescriptions(md);
|
this.attachHeadingsDescriptions(text);
|
||||||
const res = this.headings;
|
const res = this.headings;
|
||||||
this.headings = [];
|
this.headings = [];
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -12,10 +12,10 @@ describe('Markdown renderer', () => {
|
||||||
expect(renderer.headings[0].name).toEqual('Sub Intro');
|
expect(renderer.headings[0].name).toEqual('Sub Intro');
|
||||||
});
|
});
|
||||||
test('should return a level-2 heading as a child of level-1', () => {
|
test('should return a level-2 heading as a child of level-1', () => {
|
||||||
renderer.renderMd('# Introduction \n ## Sub Intro', false);
|
const headings = renderer.extractHeadings('# Introduction \n ## Sub Intro', false);
|
||||||
expect(renderer.headings).toHaveLength(1);
|
expect(headings).toHaveLength(1);
|
||||||
expect(renderer.headings[0].name).toEqual('Introduction');
|
expect(headings[0].name).toEqual('Introduction');
|
||||||
expect(renderer.headings[0].items).toBeDefined();
|
expect(headings[0].items).toBeDefined();
|
||||||
expect(renderer.headings[0].items).toHaveLength(1);
|
expect(headings[0].items).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
const throttle = function(func, wait) {
|
function throttle(func, wait) {
|
||||||
var context, args, result;
|
let context;
|
||||||
var timeout: any = null;
|
let args;
|
||||||
var previous = 0;
|
let result;
|
||||||
var later = function() {
|
let timeout: any = null;
|
||||||
(previous = new Date().getTime()), (timeout = null);
|
let previous = 0;
|
||||||
|
const later = () => {
|
||||||
|
previous = new Date().getTime();
|
||||||
|
timeout = null;
|
||||||
result = func.apply(context, args);
|
result = func.apply(context, args);
|
||||||
if (!timeout) context = args = null;
|
if (!timeout) {
|
||||||
|
context = args = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return function() {
|
return function() {
|
||||||
var now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
var remaining = wait - (now - previous);
|
const remaining = wait - (now - previous);
|
||||||
context = this;
|
context = this;
|
||||||
args = arguments;
|
args = arguments;
|
||||||
if (remaining <= 0 || remaining > wait) {
|
if (remaining <= 0 || remaining > wait) {
|
||||||
|
@ -19,13 +24,15 @@ const throttle = function(func, wait) {
|
||||||
}
|
}
|
||||||
previous = now;
|
previous = now;
|
||||||
result = func.apply(context, args);
|
result = func.apply(context, args);
|
||||||
if (!timeout) context = args = null;
|
if (!timeout) {
|
||||||
|
context = args = null;
|
||||||
|
}
|
||||||
} else if (!timeout) {
|
} else if (!timeout) {
|
||||||
timeout = setTimeout(later, remaining);
|
timeout = setTimeout(later, remaining);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export function Throttle(delay: number) {
|
export function Throttle(delay: number) {
|
||||||
return (_, _2, desc: PropertyDescriptor) => {
|
return (_, _2, desc: PropertyDescriptor) => {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"quotemark": [true, "single", "avoid-template", "jsx-double"],
|
"quotemark": [true, "single", "avoid-template", "jsx-double"],
|
||||||
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
||||||
"arrow-parens": [true, "ban-single-arg-parens"],
|
"arrow-parens": [true, "ban-single-arg-parens"],
|
||||||
"no-submodule-imports": [true, "prismjs", "perfect-scrollbar"],
|
"no-submodule-imports": [true, "prismjs", "perfect-scrollbar", "react-tippy"],
|
||||||
"object-literal-key-quotes": [true, "as-needed"],
|
"object-literal-key-quotes": [true, "as-needed"],
|
||||||
"no-unused-expression": [true, "allow-tagged-template"],
|
"no-unused-expression": [true, "allow-tagged-template"],
|
||||||
"semicolon": [true, "always", "ignore-bound-class-methods"],
|
"semicolon": [true, "always", "ignore-bound-class-methods"],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user