mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
fix: fix subsections ids so subsections with the same name are allowed
fixes #529
This commit is contained in:
parent
c8a5f36f17
commit
4c76d52cc6
|
@ -41,9 +41,13 @@ export class MarkdownRenderer {
|
|||
this.headingEnhanceRenderer.heading = this.headingRule;
|
||||
}
|
||||
|
||||
saveHeading(name: string, container: MarkdownHeading[] = this.headings): MarkdownHeading {
|
||||
saveHeading(
|
||||
name: string,
|
||||
container: MarkdownHeading[] = this.headings,
|
||||
parentId?: string,
|
||||
): MarkdownHeading {
|
||||
const item = {
|
||||
id: 'section' + '/' + slugify(name),
|
||||
id: parentId ? `${parentId}/${slugify(name)}` : `section/${slugify(name)}`,
|
||||
name,
|
||||
items: [],
|
||||
};
|
||||
|
@ -95,7 +99,11 @@ export class MarkdownRenderer {
|
|||
`<a class="share-link" href="#${id}"></a>${text}</h${level}>`
|
||||
);
|
||||
} else if (level === 2) {
|
||||
const { id } = this.saveHeading(text, this.currentTopHeading && this.currentTopHeading.items);
|
||||
const { id } = this.saveHeading(
|
||||
text,
|
||||
this.currentTopHeading && this.currentTopHeading.items,
|
||||
this.currentTopHeading && this.currentTopHeading.id,
|
||||
);
|
||||
return (
|
||||
`<a name="${id}"></a>` +
|
||||
`<h${level} ${SECTION_ATTR}="${id}" id="${id}">` +
|
||||
|
|
|
@ -2,6 +2,7 @@ import { action, observable } from 'mobx';
|
|||
import slugify from 'slugify';
|
||||
|
||||
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
||||
import { MarkdownHeading } from '../MarkdownRenderer';
|
||||
import { ContentItemModel } from '../MenuBuilder';
|
||||
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
||||
|
||||
|
@ -25,13 +26,18 @@ export class GroupModel implements IMenuItem {
|
|||
depth: number;
|
||||
//#endregion
|
||||
|
||||
constructor(type: MenuItemGroupType, tagOrGroup: OpenAPITag, parent?: GroupModel) {
|
||||
this.id = type + '/' + slugify(tagOrGroup.name);
|
||||
constructor(
|
||||
type: MenuItemGroupType,
|
||||
tagOrGroup: OpenAPITag | MarkdownHeading,
|
||||
parent?: GroupModel,
|
||||
) {
|
||||
// markdown headings already have ids calculated as they are needed for heading anchors
|
||||
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + slugify(tagOrGroup.name);
|
||||
this.type = type;
|
||||
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
||||
this.description = tagOrGroup.description || '';
|
||||
this.parent = parent;
|
||||
this.externalDocs = tagOrGroup.externalDocs;
|
||||
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
||||
|
||||
// groups are active (expanded) by default
|
||||
if (this.type === 'group') {
|
||||
|
|
Loading…
Reference in New Issue
Block a user