Skip to content

Commit

Permalink
Render JSDoc examples as typescript code
Browse files Browse the repository at this point in the history
Currently `@example` produces Markdown code blocks for code examples,
but they are not annotated with a programming language. This commit
annotates those code blocks as `typescript`, allowing for better
highlighting for JS/TS when using Markdown renderers that recognize
these languages.
  • Loading branch information
ribru17 committed Nov 19, 2024
1 parent bb9597e commit 1f025e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getTagBodyText(
if (/^\s*[~`]{3}/m.test(text)) {
return text;
}
return '```\n' + text + '\n```';
return '```tsx\n' + text + '\n```';
}

let text = convertLinkTags(tag.text, filePathConverter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite('typescript.previewer', () => {
text: 'code();'
}
], noopToResource),
'*@example* \n```\ncode();\n```'
'*@example* \n```tsx\ncode();\n```'
);
});

Expand All @@ -101,7 +101,7 @@ suite('typescript.previewer', () => {
text: 'Not code\n```\ncode();\n```'
}
], noopToResource),
'*@example* \nNot code\n```\ncode();\n```'
'*@example* \nNot code\n```tsx\ncode();\n```'
);
});

Expand All @@ -113,7 +113,7 @@ suite('typescript.previewer', () => {
text: '<caption>Not code</caption>\ncode();'
}
], noopToResource),
'*@example* \nNot code\n```\ncode();\n```'
'*@example* \nNot code\n```tsx\ncode();\n```'
);
});

Expand All @@ -125,7 +125,7 @@ suite('typescript.previewer', () => {
text: '<caption>Not code</caption>\n```\ncode();\n```'
}
], noopToResource),
'*@example* \nNot code\n```\ncode();\n```'
'*@example* \nNot code\n```tsx\ncode();\n```'
);
});

Expand Down Expand Up @@ -154,7 +154,7 @@ suite('typescript.previewer', () => {
]
}
], noopToResource),
'*@example* \n```\n1 + 1 {@link foo}\n```');
'*@example* \n```tsx\n1 + 1 {@link foo}\n```');
});

test('Should render @linkcode symbol name as code', () => {
Expand Down

0 comments on commit 1f025e6

Please sign in to comment.