Repository: TypeScript
Issue: JSDoc unexpected leading whitespace behaviour with `@example` and `<caption>`
Labels: Bug,Domain: JSDoc

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->
#15749 matches, but was last updated in June 2020 -- was informed to make a new issue

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSDoc and leading whitespace

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?#code/PTAEEkDtQFwCwKagMYHsAmSBGAbVyBrULBPAdwBpQADAZwFcBbACgENJayEAnKgVgCU1UAEtaoAHIB5ACqjImSDAToqWejFGbacVPRzpiCAHQAoEDQaMATGw5deoQcLHzFy9GdPmAVD9OgPqAAgujo4jBkqKCQTCTctAFBSaAAAgAOrNysjKCsMXE8oKiQCCkZWTnEBYzxsFHl3Agw9NwcoFbFAGY1dSVI7IaxtUWRqCnlCAAeOek4SAA8yKzpMCIlAHyhhgCMeQqgAMzGED3snEWuGwAMVFbiTQw4moNOxgvAy6vrkBsp1ACUmgOC97EUALwdJjMHZUQ4CADcoAsTRabXEABYJoFRD07BduKANqBrgJQABvFKgKEsc4OfgCFIAX3+gMCwFMXXokGQaxKNLYAC5ejw1MLhvEBOLCoTKdTUa1oPkANTEUws7zAPwpbYRKIihLYoIVbK5fISor9cqZU3VC2EsaNZqK8SdVA9e3FUr7IYy+rjHGTGaMOaLL5837bUB7V7HU77AmicQ3O5MB4IJ6gwx8d6fFYRv44gHUKnUstl4G0UGJyFWWywo6I5FgBXo0BYwM48vdkR4ulFYmkiml7vluv4+lORld0fUllFtk+DlcnkRmm2VjSkaOLBbyV7opy0CtpWgVVYdWmIA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
// In the code block below, `sum(answer, 5)` is NOT indented, but it should be.
// `sum2(answer, 5)` is indented.


/**
 * Adds two numbers
 * 
 * @param a number one
 * @param b number two
 * @returns sum of number one and number two
 * 
 * @example <caption>Add 1 and 3. If answer is >0, sums result and 5.</caption>
 * ```
 * const answer = sum(1, 3); // returns 4
 * 
 * if (answer > 0) {
 *   sum(answer, 5)
 * }
 * ```
 */
function sum(a: number, b: number): number {
  return a + b
}


/**
 * Adds two numbers
 * 
 * @param a number one
 * @param b number two
 * @returns sum of number one and number two
 * 
 * @example <caption>Add 1 and 3. If answer is >0, sums result and 5.</caption>
 * ```
 *          const answer = sum2(1, 3); // returns 4
 * 
 *          if (answer > 0) {
 *            sum2(answer, 5)
 *          }
 * ```
 */
function sum2(a: number, b: number): number {
  return a + b
}
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->

The JSDoc produced for `sum()` has the example without any indentation, despite there being preceding whitespace.

This only happens when there is a `<caption>` tag present.

![image](https://user-images.githubusercontent.com/7406822/117079715-39873900-ad34-11eb-9ade-9273c32117b4.png)

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

The result should have the same indentation as present in the comment, preferably determined from the indentation of the code block backticks.

![image](https://user-images.githubusercontent.com/7406822/117079762-5459ad80-ad34-11eb-9224-ff174dc38da1.png)