diff --git a/extensions/typescript-language-features/src/test/unit/previewer.test.ts b/extensions/typescript-language-features/src/test/unit/previewer.test.ts
index 040ffcfef66751..764cb1a3f811be 100644
--- a/extensions/typescript-language-features/src/test/unit/previewer.test.ts
+++ b/extensions/typescript-language-features/src/test/unit/previewer.test.ts
@@ -87,6 +87,54 @@ suite('typescript.previewer', () => {
'*@param* `parámetroConDiacríticos` — this will not');
});
+ test('Should render @example blocks as code', () => {
+ assert.strictEqual(
+ tagsMarkdownPreview([
+ {
+ name: 'example',
+ text: 'code();'
+ }
+ ], noopToResource),
+ '*@example* \n```\ncode();\n```'
+ );
+ });
+
+ test('Should not render @example blocks as code as if they contain a codeblock', () => {
+ assert.strictEqual(
+ tagsMarkdownPreview([
+ {
+ name: 'example',
+ text: 'Not code\n```\ncode();\n```'
+ }
+ ], noopToResource),
+ '*@example* \nNot code\n```\ncode();\n```'
+ );
+ });
+
+ test('Should render @example blocks as code if they contain a
', () => {
+ assert.strictEqual(
+ tagsMarkdownPreview([
+ {
+ name: 'example',
+ text: 'Not code\ncode();'
+ }
+ ], noopToResource),
+ '*@example* \nNot code\n```\ncode();\n```'
+ );
+ });
+
+ test('Should not render @example blocks as code if they contain a and a codeblock', () => {
+ assert.strictEqual(
+ tagsMarkdownPreview([
+ {
+ name: 'example',
+ text: 'Not code\n```\ncode();\n```'
+ }
+ ], noopToResource),
+ '*@example* \nNot code\n```\ncode();\n```'
+ );
+ });
+
test('Should render @linkcode symbol name as code', async () => {
assert.strictEqual(
plainWithLinks([
@@ -128,4 +176,3 @@ suite('typescript.previewer', () => {
'a [`husky`](file:///path/file.ts#L7%2C5) b');
});
});
-
diff --git a/extensions/typescript-language-features/src/utils/previewer.ts b/extensions/typescript-language-features/src/utils/previewer.ts
index 93a88382500d46..12449ad43e41d0 100644
--- a/extensions/typescript-language-features/src/utils/previewer.ts
+++ b/extensions/typescript-language-features/src/utils/previewer.ts
@@ -39,9 +39,9 @@ function getTagBodyText(
return undefined;
}
- // Convert to markdown code block if it is not already one
+ // Convert to markdown code block if it does not already contain one
function makeCodeblock(text: string): string {
- if (text.match(/^\s*[~`]{3}/g)) {
+ if (text.match(/^\s*[~`]{3}/m)) {
return text;
}
return '```\n' + text + '\n```';
@@ -53,7 +53,7 @@ function getTagBodyText(
// check for caption tags, fix for #79704
const captionTagMatches = text.match(/(.*?)<\/caption>\s*(\r\n|\n)/);
if (captionTagMatches && captionTagMatches.index === 0) {
- return captionTagMatches[1] + '\n\n' + makeCodeblock(text.substr(captionTagMatches[0].length));
+ return captionTagMatches[1] + '\n' + makeCodeblock(text.substr(captionTagMatches[0].length));
} else {
return makeCodeblock(text);
}
@@ -127,7 +127,7 @@ function convertLinkTags(
const out: string[] = [];
- let currentLink: { name?: string, target?: Proto.FileSpan, text?: string, readonly linkcode: boolean } | undefined;
+ let currentLink: { name?: string, target?: Proto.FileSpan, text?: string, readonly linkcode: boolean; } | undefined;
for (const part of parts) {
switch (part.kind) {
case 'link':