mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-23 00:56:33 +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;
|
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 = {
|
const item = {
|
||||||
id: 'section' + '/' + slugify(name),
|
id: parentId ? `${parentId}/${slugify(name)}` : `section/${slugify(name)}`,
|
||||||
name,
|
name,
|
||||||
items: [],
|
items: [],
|
||||||
};
|
};
|
||||||
|
@ -95,7 +99,11 @@ export class MarkdownRenderer {
|
||||||
`<a class="share-link" href="#${id}"></a>${text}</h${level}>`
|
`<a class="share-link" href="#${id}"></a>${text}</h${level}>`
|
||||||
);
|
);
|
||||||
} else if (level === 2) {
|
} 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 (
|
return (
|
||||||
`<a name="${id}"></a>` +
|
`<a name="${id}"></a>` +
|
||||||
`<h${level} ${SECTION_ATTR}="${id}" id="${id}">` +
|
`<h${level} ${SECTION_ATTR}="${id}" id="${id}">` +
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { action, observable } from 'mobx';
|
||||||
import slugify from 'slugify';
|
import slugify from 'slugify';
|
||||||
|
|
||||||
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
import { OpenAPIExternalDocumentation, OpenAPITag } from '../../types';
|
||||||
|
import { MarkdownHeading } from '../MarkdownRenderer';
|
||||||
import { ContentItemModel } from '../MenuBuilder';
|
import { ContentItemModel } from '../MenuBuilder';
|
||||||
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
import { IMenuItem, MenuItemGroupType } from '../MenuStore';
|
||||||
|
|
||||||
|
@ -25,13 +26,18 @@ export class GroupModel implements IMenuItem {
|
||||||
depth: number;
|
depth: number;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
constructor(type: MenuItemGroupType, tagOrGroup: OpenAPITag, parent?: GroupModel) {
|
constructor(
|
||||||
this.id = type + '/' + slugify(tagOrGroup.name);
|
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.type = type;
|
||||||
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
||||||
this.description = tagOrGroup.description || '';
|
this.description = tagOrGroup.description || '';
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.externalDocs = tagOrGroup.externalDocs;
|
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
||||||
|
|
||||||
// groups are active (expanded) by default
|
// groups are active (expanded) by default
|
||||||
if (this.type === 'group') {
|
if (this.type === 'group') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user