Skip to content

Commit

Permalink
improvement(api-markdown-documenter): Remove embedded html support (m…
Browse files Browse the repository at this point in the history
…icrosoft#22671)

Support for embedded HTML contents in TSDoc comments has been removed.

The TSDoc parser has some half-baked support for preserving HTML tags in
its output, despite the TSDoc spec making no claims about supporting
embedded HTML. But it does so in a structure that is difficult to handle
correctly, assuming that the output language can support arbitrary HTML
contents, and that it is safe to output the contents raw and
unsanitized.

As a result, this library's support for such contents was similarly
half-baked, and difficult to maintain.

VSCode Intellisense, as a comparison, chooses to completely ignore HTML
tags, and simply render the inner contents ignoring any HTML decorators.

This library has adopted the same policy.

### Breaking Change

If you depended on HTML content preservation, this change will affect
your output.
  • Loading branch information
Josmithr authored Sep 30, 2024
1 parent c176a1e commit 533e7dd
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 32 deletions.
12 changes: 12 additions & 0 deletions tools/api-markdown-documenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @fluid-tools/api-markdown-documenter

## 0.17.0

### ⚠ BREAKING CHANGES

- Support for embedded HTML contents in TSDoc comments has been removed.
The TSDoc parser has some half-baked support for preserving HTML tags in its output, despite the TSDoc spec making no claims about supporting embedded HTML.
But it does so in a structure that is difficult to handle correctly, assuming that the output language can support arbitrary HTML contents, and that it is safe to output the contents raw and unsanitized.
As a result, this library's support for such contents was similarly half-baked, and difficult to maintain.
VSCode Intellisense, as a comparison, chooses to completely ignore HTML tags, and simply render the inner contents ignoring any HTML decorators.
This library has adopted the same policy.
If you depended on HTML content preservation, this change will break you.

## 0.16.1

- Promote `toHtml` transformation functions to `@public`.
Expand Down
10 changes: 10 additions & 0 deletions tools/api-markdown-documenter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ The input `ApiModel` here will generally be the output of [API-Extractor][].

See [Documentation Domain](#documentation-domain) below for more details on the output format.

##### Limitations

###### Embedded HTML

Note: `TSDoc`'s parser has limited support for preserving `HTML` tags in `TSDoc` comments.
This library does not preserve embedded `HTML` in doc comments.
Instead, any `HTML` tags found will be discarded, and the contents within will be rendered normally.
This matches VSCode Intellisense's behavior.
We may reconsider this in the future.

#### MarkdownRenderer

The `MarkdownRenderer` namespace includes a few functions for generating Markdown contents.
Expand Down
2 changes: 1 addition & 1 deletion tools/api-markdown-documenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fluid-tools/api-markdown-documenter",
"version": "0.16.1",
"version": "0.17.0",
"description": "Processes .api.json files generated by API-Extractor and generates Markdown documentation from them.",
"homepage": "https://fluidframework.com",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
type DocDeclarationReference,
type DocEscapedText,
type DocFencedCode,
type DocHtmlEndTag,
type DocHtmlStartTag,
type DocLinkTag,
type DocNode,
DocNodeKind,
Expand Down Expand Up @@ -111,11 +109,13 @@ export function _transformTsdocNode(
case DocNodeKind.FencedCode: {
return transformTsdocFencedCode(node as DocFencedCode, options);
}
case DocNodeKind.HtmlStartTag: {
return transformTsdocHtmlTag(node as DocHtmlStartTag, options);
}
case DocNodeKind.HtmlStartTag:
case DocNodeKind.HtmlEndTag: {
return transformTsdocHtmlTag(node as DocHtmlEndTag, options);
// This matches intellisense's policy for HTML in TSDoc/JSDoc comments.
options.logger?.error(
`Encountered an HTML tag. This library does not support embedded HTML content. Inner contents will be mapped as normal, but the HTML tags will be ignored.`,
);
return undefined;
}
case DocNodeKind.InheritDocTag: {
options.logger?.error(
Expand Down Expand Up @@ -205,19 +205,6 @@ export function transformTsdocEscapedText(
return new PlainTextNode(node.encodedText, /* escaped: */ true);
}

/**
* Converts a {@link @microsoft/tsdoc#DocHtmlStartTag} | {@link @microsoft/tsdoc#DocHtmlEndTag} to a {@link PlainTextNode}.
*/
export function transformTsdocHtmlTag(
node: DocHtmlStartTag | DocHtmlEndTag,
options: TsdocNodeTransformOptions,
): PlainTextNode {
// TODO: this really isn't right. Mapping this forward as plain text assumes that any output format can support embedded HTML.
// That is valid for HTML and Markdown, but not necessarily for other formats.
// Instead, we should map embedded HTML content forward in an encapsulated format, and let the renderer decide how to handle it.
return new PlainTextNode(node.emitAsHtml(), /* escaped: */ true);
}

/**
* Converts a {@link @microsoft/tsdoc#DocPlainText} to a {@link PlainTextNode}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2>
<a href='./test-suite-a'>test-suite-a</a>
</td>
<td>
<b>Test package</b>
Test package
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>
</section>
<section>
<p>
<b>Test package</b>
Test package
</p>
</section>
<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>
<a href='docs/test-suite-a'>test-suite-a</a>
</td>
<td>
<b>Test package</b>
Test package
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</section>
<section>
<p>
<b>Test package</b>
Test package
</p>
</section>
<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>
<a href='docs/test-suite-a'>test-suite-a</a>
</td>
<td>
<b>Test package</b>
Test package
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>
</h2>
<section>
<p>
<b>Test package</b>
Test package
</p>
</section>
<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

| Package | Description |
| --- | --- |
| [test-suite-a](./test-suite-a) | <b>Test package</b> |
| [test-suite-a](./test-suite-a) | Test package |
| [test-suite-b](./test-suite-b) | |
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Packages](./) &gt; [test-suite-a](./test-suite-a)

<b>Test package</b>
Test package

## Remarks {#test-suite-a-remarks}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

| Package | Description |
| --- | --- |
| [test-suite-a](docs/test-suite-a) | <b>Test package</b> |
| [test-suite-a](docs/test-suite-a) | Test package |
| [test-suite-b](docs/test-suite-b) | |
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Packages](docs/) &gt; [test-suite-a](docs/test-suite-a)

<b>Test package</b>
Test package

# Remarks {#test-suite-a-remarks}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

| Package | Description |
| --- | --- |
| [test-suite-a](docs/test-suite-a) | <b>Test package</b> |
| [test-suite-a](docs/test-suite-a) | Test package |
| [test-suite-b](docs/test-suite-b) | |
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## test-suite-a

<b>Test package</b>
Test package

### Remarks {#test-suite-a-remarks}

Expand Down

0 comments on commit 533e7dd

Please sign in to comment.