mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-26 02:23:43 +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 slugify from 'slugify';
|
||||
import { MDComponent } from '../components/Markdown/Markdown';
|
||||
import { highlight, html2Str } from '../utils';
|
||||
import { SECTION_ATTR } from './MenuStore';
|
||||
import slugify from 'slugify';
|
||||
|
||||
const md = new Remarkable('default', {
|
||||
html: true,
|
||||
|
@ -47,6 +47,7 @@ export class MarkdownRenderer {
|
|||
const item = {
|
||||
id: 'section' + '/' + slugify(name),
|
||||
name,
|
||||
items: [],
|
||||
};
|
||||
container.push(item);
|
||||
return item;
|
||||
|
@ -139,8 +140,8 @@ export class MarkdownRenderer {
|
|||
}
|
||||
|
||||
extractHeadings(rawText: string): MarkdownHeading[] {
|
||||
const md = this.renderMd(rawText, false);
|
||||
this.attachHeadingsDescriptions(md);
|
||||
const text = this.renderMd(rawText, false);
|
||||
this.attachHeadingsDescriptions(text);
|
||||
const res = this.headings;
|
||||
this.headings = [];
|
||||
return res;
|
||||
|
|
|
@ -12,10 +12,10 @@ describe('Markdown renderer', () => {
|
|||
expect(renderer.headings[0].name).toEqual('Sub Intro');
|
||||
});
|
||||
test('should return a level-2 heading as a child of level-1', () => {
|
||||
renderer.renderMd('# Introduction \n ## Sub Intro', false);
|
||||
expect(renderer.headings).toHaveLength(1);
|
||||
expect(renderer.headings[0].name).toEqual('Introduction');
|
||||
expect(renderer.headings[0].items).toBeDefined();
|
||||
expect(renderer.headings[0].items).toHaveLength(1);
|
||||
const headings = renderer.extractHeadings('# Introduction \n ## Sub Intro', false);
|
||||
expect(headings).toHaveLength(1);
|
||||
expect(headings[0].name).toEqual('Introduction');
|
||||
expect(headings[0].items).toBeDefined();
|
||||
expect(headings[0].items).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
const throttle = function(func, wait) {
|
||||
var context, args, result;
|
||||
var timeout: any = null;
|
||||
var previous = 0;
|
||||
var later = function() {
|
||||
(previous = new Date().getTime()), (timeout = null);
|
||||
function throttle(func, wait) {
|
||||
let context;
|
||||
let args;
|
||||
let result;
|
||||
let timeout: any = null;
|
||||
let previous = 0;
|
||||
const later = () => {
|
||||
previous = new Date().getTime();
|
||||
timeout = null;
|
||||
result = func.apply(context, args);
|
||||
if (!timeout) context = args = null;
|
||||
if (!timeout) {
|
||||
context = args = null;
|
||||
}
|
||||
};
|
||||
return function() {
|
||||
var now = new Date().getTime();
|
||||
var remaining = wait - (now - previous);
|
||||
const now = new Date().getTime();
|
||||
const remaining = wait - (now - previous);
|
||||
context = this;
|
||||
args = arguments;
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
|
@ -19,13 +24,15 @@ const throttle = function(func, wait) {
|
|||
}
|
||||
previous = now;
|
||||
result = func.apply(context, args);
|
||||
if (!timeout) context = args = null;
|
||||
if (!timeout) {
|
||||
context = args = null;
|
||||
}
|
||||
} else if (!timeout) {
|
||||
timeout = setTimeout(later, remaining);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function Throttle(delay: number) {
|
||||
return (_, _2, desc: PropertyDescriptor) => {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
"quotemark": [true, "single", "avoid-template", "jsx-double"],
|
||||
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
|
||||
"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"],
|
||||
"no-unused-expression": [true, "allow-tagged-template"],
|
||||
"semicolon": [true, "always", "ignore-bound-class-methods"],
|
||||
|
|
Loading…
Reference in New Issue
Block a user