Skip to content

Commit

Permalink
fix(pacmak): dotnet code docs loses indentation (#3180)
Browse files Browse the repository at this point in the history
Currently code examples in dotnet lose their indentation styles because we call `trim()` on each line in the code example. We want that behavior for other types of xml docs but not for code. This PR makes code a special case that calls `trimRight()` on each line, preserving the indentation on the left.

The only change in the snapshots is translating this example: 
```ts
docs const x = 12 + 44;
const s1 = "string";
const s2 = "string \nwith new newlines"; // see #2569
const s3 = `string
            with
            new lines`;
```

to this:
```
<code>int x = 12 + 44;
string s1 = "string";
string s2 = @"string
with new newlines"; // see #2569
string s3 = @"string
            with
            new lines";</code>
```

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
kaizencc committed Nov 17, 2021
1 parent 96914c3 commit ace0b83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ export class DotNetDocGenerator {
xml.att(name, value);
}
const xmlstring = xml.end({ allowEmpty: true, pretty: false });

for (const line of xmlstring.split('\n').map((x) => x.trim())) {
const trimLeft = tag !== 'code';
for (const line of xmlstring
.split('\n')
.map((x) => (trimLeft ? x.trim() : x.trimRight()))) {
this.code.line(`/// ${line}`);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ace0b83

Please sign in to comment.