From 4a25aaef69fad814836392ea7e41eb32c182a261 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 12 Dec 2019 16:39:56 +0200 Subject: [PATCH] fix: python comment stripped in headings fixes #1116 --- src/services/MarkdownRenderer.ts | 8 ++++++++ src/services/models/ApiInfo.ts | 1 + src/services/models/Group.model.ts | 9 +++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/services/MarkdownRenderer.ts b/src/services/MarkdownRenderer.ts index 8292961b..f551f84c 100644 --- a/src/services/MarkdownRenderer.ts +++ b/src/services/MarkdownRenderer.ts @@ -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; diff --git a/src/services/models/ApiInfo.ts b/src/services/models/ApiInfo.ts index 4cc831b6..fea480aa 100644 --- a/src/services/models/ApiInfo.ts +++ b/src/services/models/ApiInfo.ts @@ -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); diff --git a/src/services/models/Group.model.ts b/src/services/models/Group.model.ts index bb82e18a..be3fc479 100644 --- a/src/services/models/Group.model.ts +++ b/src/services/models/Group.model.ts @@ -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;