diff --git a/package-lock.json b/package-lock.json index be84e309..6a814215 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "json-pointer": "^0.6.1", "lunr": "^2.3.9", "mark.js": "^8.11.1", - "marked": "^0.7.0", + "marked": "^3.0.4", "mobx-react": "^7.2.0", "openapi-sampler": "^1.0.1", "path-browserify": "^1.0.1", @@ -58,7 +58,7 @@ "@types/lodash": "^4.14.170", "@types/lunr": "^2.3.3", "@types/mark.js": "^8.11.5", - "@types/marked": "^1.1.0", + "@types/marked": "^3.0.1", "@types/node": "^15.6.1", "@types/prismjs": "^1.16.5", "@types/prop-types": "^15.7.3", @@ -3079,9 +3079,9 @@ } }, "node_modules/@types/marked": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@types/marked/-/marked-1.2.2.tgz", - "integrity": "sha512-wLfw1hnuuDYrFz97IzJja0pdVsC0oedtS4QsKH1/inyW9qkLQbXgMUqEQT0MVtUBx3twjWeInUfjQbhBVLECXw==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/marked/-/marked-3.0.3.tgz", + "integrity": "sha512-ZgAr847Wl68W+B0sWH7F4fDPxTzerLnRuUXjUpp1n4NjGSs8hgPAjAp7NQIXblG34MXTrf5wWkAK8PVJ2LIlVg==", "dev": true }, "node_modules/@types/minimatch": { @@ -12792,14 +12792,14 @@ "integrity": "sha1-GA8fnr74sOY45BZq1S24eb6y/8U=" }, "node_modules/marked": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", - "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==", + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/marked/-/marked-3.0.8.tgz", + "integrity": "sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==", "bin": { "marked": "bin/marked" }, "engines": { - "node": ">=0.10.0" + "node": ">= 12" } }, "node_modules/media-typer": { @@ -21064,9 +21064,9 @@ } }, "@types/marked": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@types/marked/-/marked-1.2.2.tgz", - "integrity": "sha512-wLfw1hnuuDYrFz97IzJja0pdVsC0oedtS4QsKH1/inyW9qkLQbXgMUqEQT0MVtUBx3twjWeInUfjQbhBVLECXw==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/marked/-/marked-3.0.3.tgz", + "integrity": "sha512-ZgAr847Wl68W+B0sWH7F4fDPxTzerLnRuUXjUpp1n4NjGSs8hgPAjAp7NQIXblG34MXTrf5wWkAK8PVJ2LIlVg==", "dev": true }, "@types/minimatch": { @@ -28484,9 +28484,9 @@ "integrity": "sha1-GA8fnr74sOY45BZq1S24eb6y/8U=" }, "marked": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", - "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==" + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/marked/-/marked-3.0.8.tgz", + "integrity": "sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==" }, "media-typer": { "version": "0.3.0", diff --git a/package.json b/package.json index d36f207b..14d3f995 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "@types/lodash": "^4.14.170", "@types/lunr": "^2.3.3", "@types/mark.js": "^8.11.5", - "@types/marked": "^1.1.0", + "@types/marked": "^3.0.1", "@types/node": "^15.6.1", "@types/prismjs": "^1.16.5", "@types/prop-types": "^15.7.3", @@ -163,7 +163,7 @@ "json-pointer": "^0.6.1", "lunr": "^2.3.9", "mark.js": "^8.11.1", - "marked": "^0.7.0", + "marked": "^3.0.4", "mobx-react": "^7.2.0", "openapi-sampler": "^1.0.1", "path-browserify": "^1.0.1", diff --git a/src/services/MarkdownRenderer.ts b/src/services/MarkdownRenderer.ts index 9ef98d60..efef59ad 100644 --- a/src/services/MarkdownRenderer.ts +++ b/src/services/MarkdownRenderer.ts @@ -1,3 +1,4 @@ +import * as React from 'react'; import * as marked from 'marked'; import { highlight, safeSlugify, unescapeHTMLChars } from '../utils'; @@ -56,10 +57,12 @@ export class MarkdownRenderer { headings: MarkdownHeading[] = []; currentTopHeading: MarkdownHeading; + public parser: marked.Parser; // required initialization, `parser` is used by `marked.Renderer` instance under the hood private headingEnhanceRenderer: marked.Renderer; private originalHeadingRule: typeof marked.Renderer.prototype.heading; constructor(public options?: RedocNormalizedOptions) { + this.parser = new marked.Parser(); this.headingEnhanceRenderer = new marked.Renderer(); this.originalHeadingRule = this.headingEnhanceRenderer.heading.bind( this.headingEnhanceRenderer, @@ -129,7 +132,7 @@ export class MarkdownRenderer { level: 1 | 2 | 3 | 4 | 5 | 6, raw: string, slugger: marked.Slugger, - ) => { + ): string => { if (level === 1) { this.currentTopHeading = this.saveHeading(text, level); } else if (level === 2) {