diff --git a/extensions/typescript-language-features/src/utils/previewer.ts b/extensions/typescript-language-features/src/utils/previewer.ts index 0c1e880162d..2b2108ccd57 100644 --- a/extensions/typescript-language-features/src/utils/previewer.ts +++ b/extensions/typescript-language-features/src/utils/previewer.ts @@ -11,19 +11,26 @@ function getTagBodyText(tag: Proto.JSDocTagInfo): string | undefined { return undefined; } + // Convert to markdown code block if it is not already one + function makeCodeblock(text: string): string { + if (text.match(/^\s*[~`]{3}/g)) { + return text; + } + return '```\n' + text + '\n```'; + } + switch (tag.name) { case 'example': // check for caption tags, fix for #79704 - const captionTagMatches = tag.text.match('(.*?)<\/caption>\r'); + const captionTagMatches = tag.text.match(/(.*?)<\/caption>\s*(\r\n|\n)/); if (captionTagMatches && captionTagMatches.index === 0) { - tag.text = captionTagMatches[1] + '\r\r' + tag.text.substr(captionTagMatches[0].length); + return captionTagMatches[1] + '\n\n' + makeCodeblock(tag.text.substr(captionTagMatches[0].length)); + } else { + return makeCodeblock(tag.text); } + case 'default': - // Convert to markdown code block if it is not already one - if (tag.text.match(/^\s*[~`]{3}/g)) { - return tag.text; - } - return '```\n' + tag.text + '\n```'; + return makeCodeblock(tag.text); } return tag.text;