mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-23 00:56:33 +03:00
fix: preserve md heading level in description
This commit is contained in:
parent
97e16208d5
commit
23559fbece
|
@ -4,10 +4,10 @@ import * as React from 'react';
|
||||||
import { SECTION_ATTR } from '../../services/MenuStore';
|
import { SECTION_ATTR } from '../../services/MenuStore';
|
||||||
import { Markdown } from '../Markdown/Markdown';
|
import { Markdown } from '../Markdown/Markdown';
|
||||||
|
|
||||||
import { H1, MiddlePanel, Row, ShareLink } from '../../common-elements';
|
import { H1, H2, MiddlePanel, Row, ShareLink } from '../../common-elements';
|
||||||
import { MDXComponentMeta } from '../../services/MarkdownRenderer';
|
import { MDXComponentMeta } from '../../services/MarkdownRenderer';
|
||||||
import { ContentItemModel } from '../../services/MenuBuilder';
|
import { ContentItemModel } from '../../services/MenuBuilder';
|
||||||
import { OperationModel } from '../../services/models';
|
import { GroupModel, OperationModel } from '../../services/models';
|
||||||
import { Operation } from '../Operation/Operation';
|
import { Operation } from '../Operation/Operation';
|
||||||
import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes';
|
import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes';
|
||||||
import { StoreConsumer } from '../StoreBuilder';
|
import { StoreConsumer } from '../StoreBuilder';
|
||||||
|
@ -79,15 +79,16 @@ export class ContentItem extends React.Component<ContentItemProps> {
|
||||||
@observer
|
@observer
|
||||||
export class SectionItem extends React.Component<ContentItemProps> {
|
export class SectionItem extends React.Component<ContentItemProps> {
|
||||||
render() {
|
render() {
|
||||||
const { name, description } = this.props.item;
|
const { name, description, level } = this.props.item as GroupModel;
|
||||||
const components = this.props.allowedMdComponents;
|
const components = this.props.allowedMdComponents;
|
||||||
|
const Header = level === 2 ? H2 : H1;
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<MiddlePanel>
|
<MiddlePanel>
|
||||||
<H1>
|
<Header>
|
||||||
<ShareLink href={'#' + this.props.item.id} />
|
<ShareLink href={'#' + this.props.item.id} />
|
||||||
{name}
|
{name}
|
||||||
</H1>
|
</Header>
|
||||||
{components ? (
|
{components ? (
|
||||||
<StoreConsumer>
|
<StoreConsumer>
|
||||||
{store => (
|
{store => (
|
||||||
|
|
|
@ -25,6 +25,7 @@ export interface MDXComponentMeta {
|
||||||
export interface MarkdownHeading {
|
export interface MarkdownHeading {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
level: number;
|
||||||
items?: MarkdownHeading[];
|
items?: MarkdownHeading[];
|
||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
@ -50,12 +51,14 @@ export class MarkdownRenderer {
|
||||||
|
|
||||||
saveHeading(
|
saveHeading(
|
||||||
name: string,
|
name: string,
|
||||||
|
level: number,
|
||||||
container: MarkdownHeading[] = this.headings,
|
container: MarkdownHeading[] = this.headings,
|
||||||
parentId?: string,
|
parentId?: string,
|
||||||
): MarkdownHeading {
|
): MarkdownHeading {
|
||||||
const item = {
|
const item = {
|
||||||
id: parentId ? `${parentId}/${safeSlugify(name)}` : `section/${safeSlugify(name)}`,
|
id: parentId ? `${parentId}/${safeSlugify(name)}` : `section/${safeSlugify(name)}`,
|
||||||
name,
|
name,
|
||||||
|
level,
|
||||||
items: [],
|
items: [],
|
||||||
};
|
};
|
||||||
container.push(item);
|
container.push(item);
|
||||||
|
@ -105,10 +108,11 @@ export class MarkdownRenderer {
|
||||||
|
|
||||||
headingRule = (text: string, level: number, raw: string) => {
|
headingRule = (text: string, level: number, raw: string) => {
|
||||||
if (level === 1) {
|
if (level === 1) {
|
||||||
this.currentTopHeading = this.saveHeading(text);
|
this.currentTopHeading = this.saveHeading(text, level);
|
||||||
} else if (level === 2) {
|
} else if (level === 2) {
|
||||||
this.saveHeading(
|
this.saveHeading(
|
||||||
text,
|
text,
|
||||||
|
level,
|
||||||
this.currentTopHeading && this.currentTopHeading.items,
|
this.currentTopHeading && this.currentTopHeading.items,
|
||||||
this.currentTopHeading && this.currentTopHeading.id,
|
this.currentTopHeading && this.currentTopHeading.id,
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,6 +25,7 @@ export class GroupModel implements IMenuItem {
|
||||||
@observable expanded: boolean = false;
|
@observable expanded: boolean = false;
|
||||||
|
|
||||||
depth: number;
|
depth: number;
|
||||||
|
level: number;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -36,6 +37,7 @@ export class GroupModel implements IMenuItem {
|
||||||
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + safeSlugify(tagOrGroup.name);
|
this.id = (tagOrGroup as MarkdownHeading).id || type + '/' + safeSlugify(tagOrGroup.name);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
this.name = tagOrGroup['x-displayName'] || tagOrGroup.name;
|
||||||
|
this.level = (tagOrGroup as MarkdownHeading).level || 1;
|
||||||
this.description = tagOrGroup.description || '';
|
this.description = tagOrGroup.description || '';
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
this.externalDocs = (tagOrGroup as OpenAPITag).externalDocs;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user