From a260c8414c34a259a70a20ebcd20ecbb06c3d250 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 10 Jan 2020 15:18:32 +0200 Subject: [PATCH] fix: fix duplicated content in tags when using md headings fixes #1150, fixes #1152 --- src/services/MarkdownRenderer.ts | 2 +- src/services/MenuBuilder.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/services/MarkdownRenderer.ts b/src/services/MarkdownRenderer.ts index f551f84c76..9276a09659 100644 --- a/src/services/MarkdownRenderer.ts +++ b/src/services/MarkdownRenderer.ts @@ -46,7 +46,7 @@ export class MarkdownRenderer { } static getTextBeforeHading(md: string, heading: string): string { - const headingLinePos = md.search(new RegExp(`^##?\s+${heading}`, 'm')); + const headingLinePos = md.search(new RegExp(`^##?\\s+${heading}`, 'm')); if (headingLinePos > -1) { return md.substring(0, headingLinePos); } diff --git a/src/services/MenuBuilder.ts b/src/services/MenuBuilder.ts index c5305d5878..f61f61890a 100644 --- a/src/services/MenuBuilder.ts +++ b/src/services/MenuBuilder.ts @@ -66,6 +66,13 @@ export class MenuBuilder { const renderer = new MarkdownRenderer(options); const headings = renderer.extractHeadings(description || ''); + if (headings.length && parent && parent.description) { + parent.description = MarkdownRenderer.getTextBeforeHading( + parent.description, + headings[0].name, + ); + } + const mapHeadingsDeep = (_parent, items, depth = 1) => items.map(heading => { const group = new GroupModel('section', heading, _parent);