diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/createDescription.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/createDescription.ts index bbf66af51..5f5c6c3d7 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/createDescription.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/createDescription.ts @@ -5,13 +5,15 @@ * LICENSE file in the root directory of this source tree. * ========================================================================== */ -import { greaterThan, lessThan } from "./utils"; +import { greaterThan, codeFence } from "./utils"; export function createDescription(description: string | undefined) { if (!description) { return ""; } return `\n\n${description - .replace(lessThan, "<") - .replace(greaterThan, ">")}\n\n`; + .replace(greaterThan, "\\>") + .replace(codeFence, function (match) { + return match.replace(/\\>/g, ">"); + })}\n\n`; } diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts index 207c24844..35fd03765 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts @@ -43,6 +43,7 @@ export function render(children: Children): string { // Regex to selectively URL-encode '>' and '<' chars export const lessThan = - /<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu; + /<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/gu; export const greaterThan = - /(??!=/giu; + /(?/gu; +export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;