fix: python comment stripped in headings

fixes #1116
This commit is contained in:
Roman Hotsiy 2019-12-12 16:39:56 +02:00
parent 7ed1a7ef0e
commit 4a25aaef69
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 14 additions and 4 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;