Commit 58e34d9
authored
fix(api-markdown-documenter): Fixed an issue where
The issue here is somewhat complicated. The following is an attempt to
provide a high-level-ish overview of what's going on.
## The Problem
Keeping the description at a high-level, `CommonMark` specifies 2 ways
to force an explicit line break: either ending a line with 2 spaces or
ending a line with a backslash.
- https://commonmark.org/help/tutorial/03-paragraphs.html
`mdast-util-to-markdown`, the library we use to emit prefers the latter,
as it is more explicit.
In most cases, this is irrelevant, and Markdown parsers that adhere to
`CommonMark` should tolerate this. Docusaurus doesn't appear to, causing
spurious trailing backslash characters to appear in *some* of our API
documentation. E.g.
https://fluidframework.com/docs/api/fluid-framework/allowedtypesfullevaluated-typealias
But our library shouldn't need to output forced line breaks. We build
our Markdown AST trees manually, and so we control the output structure.
We generally avoid explicit line breaks, and instead use `Paragraph`
nodes when separating blocks of text.
But for contents parsed by `TSDoc`, we _transform_ their parsed content,
making certain assumptions about how the parser behaves.
The case that was causing problems for us is a case where `TSDoc` fails
to trim trailing whitespace from comment blocks (generally this
manifests in the summary component). In particular, when a summary
comment is followed by 2 or more modifier tags on a subsequent line,
TSDoc fails to trim the summary comment, yielding something with
trailing explicit line breaks.
### Example
Given the following comment:
```typescript
/**
* I am a comment
*
*/
```
The TSDoc parser will yield a summary block of `I am a comment`
But given the following comment:
```typescript
/**
* I am a comment
*
* @Sealed @public
*/
```
The TSDoc parser will yield a summary block of `I am a comment \n`
## The Solution
The solution is to better trim paragraph contents given to us from the
`TSDoc` parser. Previously, we would trim any leading/trailing line
breaks we encountered. Now, we also trim and leading/trailing whitespace
content.
This simplifies the Paragraph trees we hand off to
`mdast-util-to-markdown`, removing the need for them to inject trailing
`\` characters to force line breaks.
[AB#53737](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/53737)MarkdownRenderer would emit trailing \ characters when processing certain summary comments. (#25933)1 parent 7bc8741 commit 58e34d9
File tree
10 files changed
+75
-27
lines changed- tools/api-markdown-documenter
- src
- api-item-transforms
- test
- test
- snapshots/markdown/simple-suite-test
- deep-config/test-suite-a
- testbetanamespace-namespace
- default-config/test-suite-a
- testbetanamespace-namespace
- flat-config
- test-data/simple-suite-test
10 files changed
+75
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Lines changed: 18 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | | - | |
| 173 | + | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
| 701 | + | |
| 702 | + | |
705 | 703 | | |
706 | | - | |
| 704 | + | |
707 | 705 | | |
708 | 706 | | |
709 | 707 | | |
710 | 708 | | |
711 | 709 | | |
712 | 710 | | |
713 | 711 | | |
714 | | - | |
| 712 | + | |
715 | 713 | | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
716 | 724 | | |
717 | 725 | | |
718 | 726 | | |
719 | 727 | | |
720 | 728 | | |
721 | 729 | | |
722 | 730 | | |
723 | | - | |
| 731 | + | |
724 | 732 | | |
725 | 733 | | |
726 | 734 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
870 | 870 | | |
871 | 871 | | |
872 | 872 | | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
873 | 904 | | |
874 | 905 | | |
875 | 906 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
1181 | 1181 | | |
1182 | 1182 | | |
1183 | 1183 | | |
| 1184 | + | |
1184 | 1185 | | |
1185 | 1186 | | |
1186 | 1187 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
| 572 | + | |
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| |||
0 commit comments