Skip to content

Commit

Permalink
fix: broken headings with single quote
Browse files Browse the repository at this point in the history
fixes #955
  • Loading branch information
RomanHotsiy committed Jul 7, 2019
1 parent 4bd499f commit 51d3b9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/services/MarkdownRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as marked from 'marked';

import { highlight, safeSlugify } from '../utils';
import { highlight, safeSlugify, unescapeHTMLChars } from '../utils';
import { AppStore } from './AppStore';
import { RedocNormalizedOptions } from './RedocNormalizedOptions';

Expand Down Expand Up @@ -65,6 +65,7 @@ export class MarkdownRenderer {
container: MarkdownHeading[] = this.headings,
parentId?: string,
): MarkdownHeading {
name = unescapeHTMLChars(name);
const item = {
id: parentId ? `${parentId}/${safeSlugify(name)}` : `section/${safeSlugify(name)}`,
name,
Expand All @@ -88,7 +89,7 @@ export class MarkdownRenderer {
}

attachHeadingsDescriptions(rawText: string) {
const buildRegexp = heading => {
const buildRegexp = (heading: MarkdownHeading) => {
return new RegExp(`##?\\s+${heading.name.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}`);
};

Expand Down
4 changes: 4 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,7 @@ function parseURL(url: string) {
return new URL(url);
}
}

export function unescapeHTMLChars(str: string): string {
return str.replace(/&#(\d+);/g, (_m, code) => String.fromCharCode(parseInt(code, 10)));
}

0 comments on commit 51d3b9b

Please sign in to comment.