Skip to content

Commit 647aca5

Browse files
AlexJerabekNicholas Pape
authored andcommitted
[api-documenter] Office Extension: Adding logic to remove added escape characters from code lines (microsoft#734)
* Adding logic to remove added escape characters from code lines * Adding change log
1 parent e42e964 commit 647aca5

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

apps/api-documenter/src/yaml/OfficeYamlDocumenter.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,6 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
6868

6969
protected onCustomizeYamlItem(yamlItem: IYamlItem): void { // override
7070
const nameWithoutPackage: string = yamlItem.uid.replace(/^[^.]+\./, '');
71-
72-
const snippets: string[] | undefined = this._snippets[nameWithoutPackage];
73-
if (snippets) {
74-
delete this._snippets[nameWithoutPackage];
75-
76-
if (!yamlItem.remarks) {
77-
yamlItem.remarks = '';
78-
}
79-
80-
yamlItem.remarks += '\n\n#### Examples\n';
81-
for (const snippet of snippets) {
82-
if (snippet.search(/await/) === -1) {
83-
yamlItem.remarks += '\n```javascript\n' + snippet + '\n```\n';
84-
} else {
85-
yamlItem.remarks += '\n```typescript\n' + snippet + '\n```\n';
86-
}
87-
}
88-
}
89-
9071
if (yamlItem.summary) {
9172
yamlItem.summary = this._fixupApiSet(yamlItem.summary, yamlItem.uid);
9273
yamlItem.summary = this._fixBoldAndItalics(yamlItem.summary);
@@ -96,7 +77,7 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
9677
yamlItem.remarks = this._fixupApiSet(yamlItem.remarks, yamlItem.uid);
9778
yamlItem.remarks = this._fixBoldAndItalics(yamlItem.remarks);
9879
yamlItem.remarks = this._fixCodeTicks(yamlItem.remarks);
99-
yamlItem.remarks = this._fixCodeArrows(yamlItem.remarks);
80+
yamlItem.remarks = this._fixEscapedCode(yamlItem.remarks);
10081
}
10182
if (yamlItem.syntax && yamlItem.syntax.parameters) {
10283
yamlItem.syntax.parameters.forEach(part => {
@@ -106,6 +87,24 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
10687
}
10788
});
10889
}
90+
91+
const snippets: string[] | undefined = this._snippets[nameWithoutPackage];
92+
if (snippets) {
93+
delete this._snippets[nameWithoutPackage];
94+
95+
if (!yamlItem.remarks) {
96+
yamlItem.remarks = '';
97+
}
98+
99+
yamlItem.remarks += '\n\n#### Examples\n';
100+
for (const snippet of snippets) {
101+
if (snippet.search(/await/) === -1) {
102+
yamlItem.remarks += '\n```javascript\n' + snippet + '\n```\n';
103+
} else {
104+
yamlItem.remarks += '\n```typescript\n' + snippet + '\n```\n';
105+
}
106+
}
107+
}
109108
}
110109

111110
private _fixupApiSet(markup: string, uid: string): string {
@@ -137,7 +136,16 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
137136
return Text.replaceAll(text, '\\`', '`');
138137
}
139138

140-
private _fixCodeArrows(text: string): string {
141-
return Text.replaceAll(text, '=>', '=>');
139+
private _fixEscapedCode(text: string): string {
140+
const backtickIndex: number = text.indexOf('`');
141+
if (text.indexOf('`', backtickIndex) > 0) {
142+
text = Text.replaceAll(text, '=>', '=>');
143+
let x: number = text.indexOf('\\', backtickIndex);
144+
while (x >= 0) {
145+
text = text.replace(/\\([^\\])/, '$1');
146+
x = text.indexOf('\\', x + 1);
147+
}
148+
}
149+
return text;
142150
}
143151
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-documenter",
5+
"comment": "Changing Office's APIExtractor add-on to unescape characters in code blocks",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-documenter",
10+
"email": "AlexJerabek@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)