Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[api-documenter] Do not escape Markdown in doc comments #4940

Open
markus-incisive opened this issue Sep 25, 2024 · 1 comment
Open

[api-documenter] Do not escape Markdown in doc comments #4940

markus-incisive opened this issue Sep 25, 2024 · 1 comment

Comments

@markus-incisive
Copy link

markus-incisive commented Sep 25, 2024

Summary

Most Markdown in the doc comments is escaped, which causes unexpected/unwanted/inconsistent behavior. VSCode allows for Markdown and renders it as expected, but api-documenter doesn't.

Repro steps

Given the following class:

/**
 * I am **bold**.
 *
 * @public
 */
export class MyClass {}

VSCode will render the markdown, but api-documenter emits it with the Markdown escaped as "I am **bold**".

{6598671A-C122-424C-9253-463585D4E2A7}

Putting a backslash in front of the Markdown characters works for VSCode, but only sometimes works with api-documenter. This example throws a tsdoc-unnecessary-backslash warning.

/**
 * I am \_not italic\_.
 *
 * @public
 */
export class MyClass {}

One way to get api-documenter to format text is to use HTML tags, but VSCode will not render HTML tags.

/**
 * I should be <b>bold</b>.
 *
 * @public
 */
export class MyClass {}

{5463356C-0E7C-4892-9F12-AD94BDBD2733}

Details

There doesn't seem to be a way to get both VSCode and api-documenter to both render formatted text. This applies to @example and @remarks blocks as well.

I expected api-documenter to support Markdown in doc comments, and leave it to the user to write proper Markdown (explicitly escaping when needed). This behavior could be turned on via an option, since there may still be situations to disallow Markdown in doc comments especially depending on the intended documentation target.

  • Code and code blocks are supported by both VSCode and api-documenter
    • Note: api-documenter only supports code marked with exactly 1 (`) or 3 (```) backticks, and won't for example support ``this `code` has a backtick`` (Warning: tsdoc-code-span-empty).
  • api-documenter will escape asterisks (*), underscores (_), and headers (#); while VSCode renders them as Markdown when applicable.
  • VSCode allows escaping asterisks (*), underscores (_), and headers (#); while api-documenter doesn't nothing different for escaped characters except throwing for escaped underscores.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-documenter version? 7.25.14
Operating system? Windows
Documentation target? Markdown
Would you consider contributing a PR? No
TypeScript compiler version? 5.4.2
Node.js version (node -v)? 22.7.0
@markus-incisive
Copy link
Author

May just be a TSDoc issue microsoft/tsdoc#12

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: Needs triage
Development

No branches or pull requests

1 participant