Skip to content

Commit

Permalink
fix: add id attr to headers to work before react is loaded if ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 10, 2018
1 parent 7eb477b commit 1743453
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/components/ContentItems/ContentItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Operation/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SecuritySchemes/SecuritySchemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions src/services/MarkdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
);
}
Expand Down

0 comments on commit 1743453

Please sign in to comment.