fix: add id attr to headers to work before react is loaded if ssr

This commit is contained in:
Roman Hotsiy 2018-01-10 18:23:14 +02:00
parent 7eb477b9de
commit 174345399f
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 9 additions and 8 deletions

View File

@ -59,11 +59,12 @@ export class ContentItem extends React.Component<ContentItemProps> {
export class TagItem extends React.Component<ContentItemProps> {
render() {
const { name, description } = this.props.item;
const hash = this.props.item.getHash();
return (
<Row>
<MiddlePanel key="middle">
<H1>
<ShareLink href={'#' + this.props.item.getHash()} />
<H1 id={hash}>
<ShareLink href={'#' + hash} />
{name}
</H1>
{description !== undefined && <Markdown source={description} />}

View File

@ -44,12 +44,12 @@ export class Operation extends ComponentWithOptions<OperationProps> {
const { name: summary, description, deprecated } = operation;
const pathInMiddle = this.options.pathInMiddlePanel;
const hash = operation.getHash();
return (
<OperationRow>
<MiddlePanel>
<H2>
<ShareLink href={'#' + operation.getHash()} />
<H2 id={hash}>
<ShareLink href={'#' + hash} />
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
</H2>
{pathInMiddle && <Endpoint operation={operation} inverted={true} />}

View File

@ -82,7 +82,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
<div>
{this.props.securitySchemes.schemes.map(scheme => (
<div data-section-id={scheme.sectionId} key={scheme.id}>
<H2>
<H2 id={scheme.sectionId}>
<ShareLink href={'#' + scheme.sectionId} />
{scheme.id}
</H2>

View File

@ -90,14 +90,14 @@ export class MarkdownRenderer {
let id = this.currentTopHeading.id;
return (
`<a name="${id}"></a>` +
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}">` +
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}" id="${id}">` +
`<a class="share-link" href="#${id}"></a>`
);
} else if (tokens[idx].hLevel === 2) {
let { id } = this.saveHeading(content, this.currentTopHeading.items);
return (
`<a name="${id}"></a>` +
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}">` +
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}" id="${id}">` +
`<a class="share-link" href="#${id}"></a>`
);
}