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