mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +03:00
parent
7ed1a7ef0e
commit
4a25aaef69
|
@ -45,6 +45,14 @@ export class MarkdownRenderer {
|
||||||
return compRegexp.test(rawText);
|
return compRegexp.test(rawText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getTextBeforeHading(md: string, heading: string): string {
|
||||||
|
const headingLinePos = md.search(new RegExp(`^##?\s+${heading}`, 'm'));
|
||||||
|
if (headingLinePos > -1) {
|
||||||
|
return md.substring(0, headingLinePos);
|
||||||
|
}
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
|
||||||
headings: MarkdownHeading[] = [];
|
headings: MarkdownHeading[] = [];
|
||||||
currentTopHeading: MarkdownHeading;
|
currentTopHeading: MarkdownHeading;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ export class ApiInfoModel implements OpenAPIInfo {
|
||||||
constructor(private parser: OpenAPIParser) {
|
constructor(private parser: OpenAPIParser) {
|
||||||
Object.assign(this, parser.spec.info);
|
Object.assign(this, parser.spec.info);
|
||||||
this.description = parser.spec.info.description || '';
|
this.description = parser.spec.info.description || '';
|
||||||
|
|
||||||
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
||||||
if (firstHeadingLinePos > -1) {
|
if (firstHeadingLinePos > -1) {
|
||||||
this.description = this.description.substring(0, firstHeadingLinePos);
|
this.description = this.description.substring(0, firstHeadingLinePos);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { action, observable } from 'mobx';
|
||||||
|
|
||||||
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
||||||
import { safeSlugify } from '../../utils';
|
import { safeSlugify } from '../../utils';
|
||||||
import { MarkdownHeading } from '../MarkdownRenderer';
|
import { MarkdownHeading, MarkdownRenderer } from '../MarkdownRenderer';
|
||||||
import { ContentItemModel } from '../MenuBuilder';
|
import { ContentItemModel } from '../MenuBuilder';
|
||||||
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
||||||
|
|
||||||
|
@ -43,9 +43,10 @@ export class GroupModel implements IMenuItem {
|
||||||
|
|
||||||
// remove sections from markdown, same as in ApiInfo
|
// remove sections from markdown, same as in ApiInfo
|
||||||
this.description = tagOrGroup.description || '';
|
this.description = tagOrGroup.description || '';
|
||||||
const firstHeadingLinePos = this.description.search(/^##?\s+/m);
|
|
||||||
if (firstHeadingLinePos > -1) {
|
const items = (tagOrGroup as MarkdownHeading).items;
|
||||||
this.description = this.description.substring(0, firstHeadingLinePos);
|
if (items && items.length) {
|
||||||
|
this.description = MarkdownRenderer.getTextBeforeHading(this.description, items[0].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user