@cparra/apexdocs 2.25.0-alpha.5 → 2.25.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,66 +166,60 @@ var __spreadValues$f = (a, b) => {
166
166
  };
167
167
  var __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
168
168
  function adaptDescribable(describable, linkGenerator) {
169
- function describableToRenderableContent(describable2) {
170
- if (!describable2) {
171
- return;
172
- }
173
- let content = [];
174
- for (let i = 0; i < describable2.length; i++) {
175
- const line = describable2[i];
176
- const codeBlockMatch = line.match(/^```([a-zA-Z]*)$/);
177
- if (codeBlockMatch) {
178
- const language = codeBlockMatch[1] || "apex";
179
- const codeBlockLines = [];
180
- i++;
181
- while (i < describable2.length) {
182
- const currentLine = describable2[i];
183
- if (currentLine.trim() === "```") {
184
- break;
185
- }
186
- codeBlockLines.push(currentLine);
187
- i++;
169
+ return {
170
+ description: describableToRenderableContent(describable, linkGenerator)
171
+ };
172
+ }
173
+ function describableToRenderableContent(describable, linkGenerator) {
174
+ if (!describable) {
175
+ return;
176
+ }
177
+ let content = [];
178
+ for (let i = 0; i < describable.length; i++) {
179
+ const line = describable[i];
180
+ const codeBlockMatch = line.match(/^```([a-zA-Z]*)$/);
181
+ if (codeBlockMatch) {
182
+ const language = codeBlockMatch[1] || "apex";
183
+ const codeBlockLines = [];
184
+ i++;
185
+ while (i < describable.length) {
186
+ const currentLine = describable[i];
187
+ if (currentLine.trim() === "```") {
188
+ break;
188
189
  }
189
- content = [
190
- ...content,
191
- {
192
- __type: "code-block",
193
- language,
194
- content: codeBlockLines
195
- },
196
- { __type: "empty-line" }
197
- ];
198
- continue;
190
+ codeBlockLines.push(currentLine);
191
+ i++;
199
192
  }
200
193
  content = [
201
194
  ...content,
202
- ...replaceInlineReferences(line, linkGenerator),
203
195
  {
204
- __type: "empty-line"
205
- }
196
+ __type: "code-block",
197
+ language,
198
+ content: codeBlockLines
199
+ },
200
+ { __type: "empty-line" }
206
201
  ];
202
+ continue;
207
203
  }
208
- return content.filter((line, index, lines) => !(isEmptyLine(line) && index === lines.length - 1));
204
+ content = [
205
+ ...content,
206
+ ...replaceInlineReferences(line, linkGenerator),
207
+ {
208
+ __type: "empty-line"
209
+ }
210
+ ];
209
211
  }
210
- return {
211
- description: describableToRenderableContent(describable)
212
- };
212
+ return content.filter((line, index, lines) => !(isEmptyLine(line) && index === lines.length - 1));
213
213
  }
214
214
  function adaptDocumentable(documentable, linkGenerator, subHeadingLevel) {
215
215
  var _a, _b, _c;
216
216
  function extractCustomTags(type) {
217
217
  var _a2, _b2;
218
- const baseTags = ["description", "group", "author", "date", "see", "example", "mermaid", "throws", "exception"];
218
+ const baseTags = ["description", "group", "author", "date", "see", "example", "throws", "exception"];
219
219
  return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.filter((currentAnnotation) => !baseTags.includes(currentAnnotation.name.toLowerCase())).map((currentAnnotation) => __spreadProps$f(__spreadValues$f({}, adaptDescribable(currentAnnotation.bodyLines, linkGenerator)), {
220
220
  name: currentAnnotation.name
221
221
  }))) != null ? _b2 : [];
222
222
  }
223
- function extractAnnotationBodyLines(type, annotationName) {
224
- var _a2, _b2;
225
- return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.find(
226
- (currentAnnotation) => currentAnnotation.name.toLowerCase() === annotationName
227
- )) == null ? void 0 : _b2.bodyLines;
228
- }
229
223
  function extractAnnotationBody(type, annotationName) {
230
224
  var _a2, _b2;
231
225
  return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.find(
@@ -236,28 +230,13 @@ function adaptDocumentable(documentable, linkGenerator, subHeadingLevel) {
236
230
  var _a2, _b2;
237
231
  return (_b2 = (_a2 = type.docComment) == null ? void 0 : _a2.annotations.filter((currentAnnotation) => currentAnnotation.name.toLowerCase() === "see").map((currentAnnotation) => currentAnnotation.body)) != null ? _b2 : [];
238
232
  }
239
- function bodyLinesToCodeBlock(language, bodyLines) {
240
- if (!bodyLines) {
241
- return;
242
- }
243
- return {
244
- __type: "code-block",
245
- language,
246
- content: bodyLines
247
- };
248
- }
249
233
  return __spreadProps$f(__spreadValues$f({}, adaptDescribable((_a = documentable.docComment) == null ? void 0 : _a.descriptionLines, linkGenerator)), {
250
234
  annotations: documentable.annotations.map((annotation) => annotation.type.toUpperCase()),
251
235
  customTags: extractCustomTags(documentable),
252
- mermaid: {
253
- headingLevel: subHeadingLevel,
254
- heading: "Diagram",
255
- value: bodyLinesToCodeBlock("mermaid", extractAnnotationBodyLines(documentable, "mermaid"))
256
- },
257
236
  example: {
258
237
  headingLevel: subHeadingLevel,
259
238
  heading: "Example",
260
- value: bodyLinesToCodeBlock("apex", (_c = (_b = documentable.docComment) == null ? void 0 : _b.exampleAnnotation) == null ? void 0 : _c.bodyLines)
239
+ value: describableToRenderableContent((_c = (_b = documentable.docComment) == null ? void 0 : _b.exampleAnnotation) == null ? void 0 : _c.bodyLines, linkGenerator)
261
240
  },
262
241
  group: extractAnnotationBody(documentable, "group"),
263
242
  author: extractAnnotationBody(documentable, "author"),
@@ -973,7 +952,7 @@ const documentablePartialTemplate = `
973
952
 
974
953
  {{#if doc.example.value}}
975
954
  {{ heading doc.example.headingLevel doc.example.heading }}
976
- {{code doc.example.value}}
955
+ {{{renderContent doc.example.value}}}
977
956
  {{/if}}
978
957
  `.trim();
979
958
 
@@ -72,7 +72,5 @@ public virtual String sayHello()
72
72
  A string value.
73
73
 
74
74
  ##### Example
75
- ```apex
76
- SampleClass sample = new SampleClass();
77
- sample.doSomething();
78
- ```
75
+ SampleClass sample &#x3D; new SampleClass();
76
+ sample.doSomething();
@@ -8,6 +8,13 @@ title: SampleInterface
8
8
 
9
9
  This is a sample interface
10
10
 
11
+ **Mermaid**
12
+
13
+ graph TD
14
+ A[SampleInterface] --&gt;|extends| B[ParentInterface]
15
+ B --&gt;|extends| C[GrandParentInterface]
16
+ C --&gt;|extends| D[GreatGrandParentInterface]
17
+
11
18
  **Author** John Doe
12
19
 
13
20
  **Date** 2020-01-01
@@ -19,19 +26,9 @@ This is a sample interface
19
26
  ## Namespace
20
27
  apexdocs
21
28
 
22
- ## Diagram
23
- ```mermaid
24
- graph TD
25
- A[SampleInterface] -->|extends| B[ParentInterface]
26
- B -->|extends| C[GrandParentInterface]
27
- C -->|extends| D[GreatGrandParentInterface]
28
- ```
29
-
30
29
  ## Example
31
- ```apex
32
- SampleInterface sampleInterface = new SampleInterface();
30
+ SampleInterface sampleInterface &#x3D; new SampleInterface();
33
31
  sampleInterface.sampleMethod();
34
- ```
35
32
 
36
33
  **Extends**
37
34
  [apexdocs.ParentInterface](./apexdocs.ParentInterface.md)
@@ -51,6 +48,13 @@ This is a custom tag
51
48
 
52
49
  This is another custom tag
53
50
 
51
+ **Mermaid**
52
+
53
+ graph TD
54
+ A[SampleInterface] --&gt;|extends| B[ParentInterface]
55
+ B --&gt;|extends| C[GrandParentInterface]
56
+ C --&gt;|extends| D[GreatGrandParentInterface]
57
+
54
58
  #### Signature
55
59
  ```apex
56
60
  public String sampleMethod()
@@ -66,19 +70,9 @@ Some return value
66
70
 
67
71
  AnotherSampleException: This is another sample exception
68
72
 
69
- #### Diagram
70
- ```mermaid
71
- graph TD
72
- A[SampleInterface] -->|extends| B[ParentInterface]
73
- B -->|extends| C[GrandParentInterface]
74
- C -->|extends| D[GreatGrandParentInterface]
75
- ```
76
-
77
73
  #### Example
78
- ```apex
79
- SampleInterface sampleInterface = new SampleInterface();
74
+ SampleInterface sampleInterface &#x3D; new SampleInterface();
80
75
  sampleInterface.sampleMethod();
81
- ```
82
76
 
83
77
  ---
84
78
 
@@ -5,9 +5,10 @@ title: Url
5
5
  # Url Class
6
6
 
7
7
  Represents a uniform resource locator (URL) and provides access to parts of the URL.
8
- Enables access to the base URL used to access your Salesforce org.
9
-
10
- ## Usage
8
+ Enables access to the base URL used to access your Salesforce org.
9
+
10
+ **Usage**
11
+
11
12
  Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
12
13
  logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
13
14
  a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
@@ -31,8 +32,25 @@ Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
31
32
  String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
32
33
  ```
33
34
 
35
+ **Version Behavior Changes**
36
+
37
+ In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
38
+
39
+ The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
40
+ specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
41
+ parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
42
+ that inputs are valid, RFC-compliant URL or URI strings.
34
43
 
35
- ## Example
44
+ * [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
45
+ * [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
46
+
47
+ **See Also**
48
+ * [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
49
+
50
+ ## Namespace
51
+ apexdocs
52
+
53
+ ## Example
36
54
  In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
37
55
  pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
38
56
  prints out all the results to the debug log output.
@@ -63,24 +81,6 @@ System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol());
63
81
  System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
64
82
  ```
65
83
 
66
-
67
- ## Version Behavior Changes
68
- In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
69
-
70
- The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
71
- specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
72
- parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
73
- that inputs are valid, RFC-compliant URL or URI strings.
74
-
75
- * [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
76
- * [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
77
-
78
- **See Also**
79
- * [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
80
-
81
- ## Namespace
82
- apexdocs
83
-
84
84
  ## Constructors
85
85
  ### `Url(spec)`
86
86
 
@@ -254,12 +254,10 @@ global static String getFileFieldURL(String entityId, String fieldName)
254
254
  The download URL for the file attachment.
255
255
 
256
256
  #### Example
257
- ```apex
258
- String fileURL =
259
- URL.getFileFieldURL(
260
- '087000000000123' ,
261
- 'AttachmentBody');
262
- ```
257
+ String fileURL &#x3D;
258
+ URL.getFileFieldURL(
259
+ &#x27;087000000000123&#x27; ,
260
+ &#x27;AttachmentBody&#x27;);
263
261
 
264
262
  ---
265
263
 
@@ -306,8 +304,9 @@ global static Url getOrgDomainUrl()
306
304
  getOrgDomainUrl() always returns the login URL for your org, regardless of context. Use that URL when making API calls to your org.
307
305
 
308
306
  #### Example
307
+ This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
308
+
309
309
  ```apex
310
- // This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
311
310
  Http h = new Http();
312
311
  HttpRequest req = new HttpRequest();
313
312
  req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
@@ -15,6 +15,12 @@ This description has several lines
15
15
  Test. I can also have a [apexdocs.ReferencedEnum](../Miscellaneous/apexdocs.ReferencedEnum.md) here.
16
16
  And it can be multiline.
17
17
 
18
+ **Mermaid**
19
+
20
+ graph TD
21
+ A[SampleEnum] --&gt;|references| B[ReferencedEnum]
22
+ B --&gt;|referenced by| A
23
+
18
24
  **Group** Sample Enums
19
25
 
20
26
  **Author** John Doe
@@ -26,13 +32,6 @@ And it can be multiline.
26
32
  ## Namespace
27
33
  apexdocs
28
34
 
29
- ## Diagram
30
- ```mermaid
31
- graph TD
32
- A[SampleEnum] -->|references| B[ReferencedEnum]
33
- B -->|referenced by| A
34
- ```
35
-
36
35
  ## Values
37
36
  | Value | Description |
38
37
  |-------|-------------|
@@ -14,10 +14,8 @@ deserunt ea officia exercitation laboris enim in duis quis enim eiusmod eu amet
14
14
  apexdocs
15
15
 
16
16
  ## Example
17
- ```apex
18
- SampleClass sample = new SampleClass();
17
+ SampleClass sample &#x3D; new SampleClass();
19
18
  sample.doSomething();
20
- ```
21
19
 
22
20
  **Inheritance**
23
21
 
@@ -121,10 +119,8 @@ public virtual String sayHello()
121
119
  A string value.
122
120
 
123
121
  ##### Example
124
- ```apex
125
- SampleClass sample = new SampleClass();
122
+ SampleClass sample &#x3D; new SampleClass();
126
123
  sample.doSomething();
127
- ```
128
124
 
129
125
  ## Classes
130
126
  ### SomeInnerClass Class
@@ -38,78 +38,7 @@ This is a sample interface
38
38
  ### [apexdocs.Url](./Miscellaneous/apexdocs.Url.md)
39
39
 
40
40
  Represents a uniform resource locator (URL) and provides access to parts of the URL.
41
- Enables access to the base URL used to access your Salesforce org.
42
-
43
- ## Usage
44
- Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
45
- logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
46
- a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
47
-
48
- ```apex
49
- // Get a file uploaded through Chatter.
50
- ContentDocument doc = [SELECT Id FROM ContentDocument
51
- WHERE Title = 'myfile'];
52
- // Create a link to the file.
53
- String fullFileURL = URL.getOrgDomainURL().toExternalForm() +
54
- '/' + doc.id;
55
- System.debug(fullFileURL);
56
- ```
57
-
58
-
59
- The following example creates a link to a Salesforce record. The full URL is created by concatenating the Salesforce base
60
- URL with the record ID.
61
-
62
- ```apex
63
- Account acct = [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1];
64
- String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
65
- ```
66
-
67
-
68
- ## Example
69
- In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
70
- pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
71
- prints out all the results to the debug log output.
72
-
73
- ```apex
74
- // Create a new account called Acme that we will create a link for later.
75
- Account myAccount = new Account(Name='Acme');
76
- insert myAccount;
77
-
78
- // Get the base URL.
79
- String sfdcBaseURL = URL.getOrgDomainURL().toExternalForm();
80
- System.debug('Base URL: ' + sfdcBaseURL );
81
-
82
- // Get the URL for the current request.
83
- String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
84
- System.debug('Current request URL: ' + currentRequestURL);
85
-
86
- // Create the account URL from the base URL.
87
- String accountURL = URL.getOrgDomainURL().toExternalForm() +
88
- '/' + myAccount.Id;
89
- System.debug('URL of a particular account: ' + accountURL);
90
-
91
- // Get some parts of the base URL.
92
- System.debug('Host: ' + URL.getOrgDomainURL().getHost());
93
- System.debug('Protocol: ' + URL.getOrgDomainURL().getProtocol());
94
-
95
- // Get the query string of the current request.
96
- System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
97
- ```
98
-
99
-
100
- ## Version Behavior Changes
101
- In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
102
-
103
- The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
104
- specific instance. Salesforce strongly encourages you to use API 41.0 and later versions for fully RFC-compliant URL
105
- parsing that includes proper handling of edge cases of complex URL structures. API 41.0 and later versions also enforce
106
- that inputs are valid, RFC-compliant URL or URI strings.
107
-
108
- * [URL Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_constructors)
109
- * [URL Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_url.htm#apex_System_URL_methods)
110
-
111
- **See Also**
112
- * [URL Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_url.htm)
41
+ Enables access to the base URL used to access your Salesforce org.
113
42
 
114
43
  ## Sample Enums
115
44
 
@@ -2,7 +2,7 @@
2
2
  * @description Represents a uniform resource locator (URL) and provides access to parts of the URL.
3
3
  * Enables access to the base URL used to access your Salesforce org.
4
4
  *
5
- * ## Usage
5
+ * @usage
6
6
  * Use the methods of the `System.URL` class to create links to objects in your organization. Such objects can be files, images,
7
7
  * logos, or records that you want to include in external emails, in activities, or in Chatter posts. For example, you can create
8
8
  * a link to a file uploaded as an attachment to a Chatter post by concatenating the Salesforce base URL with the file ID:
@@ -25,7 +25,7 @@
25
25
  * String fullRecordURL = URL.getOrgDomainURL().toExternalForm() + '/' + acct.Id;
26
26
  * ```
27
27
  *
28
- * ## Example
28
+ * @example
29
29
  * In this example, the base URL and the full request URL of the current Salesforce server instance are retrieved. Next, a URL
30
30
  * pointing to a specific account object is created. Finally, components of the base and full URL are obtained. This example
31
31
  * prints out all the results to the debug log output.
@@ -56,7 +56,7 @@
56
56
  * System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());
57
57
  * ```
58
58
  *
59
- * ## Version Behavior Changes
59
+ * @version-behavior-changes
60
60
  * In API version 41.0 and later, Apex URL objects are represented by the java.net.URI type, not the java.net.URL type.
61
61
  *
62
62
  * The API version in which the URL object was instantiated determines the behavior of subsequent method calls to the
@@ -177,7 +177,9 @@ global class Url {
177
177
  * You don't need a RemoteSiteSetting for your org to interact with the Salesforce APIs using domain URLs retrieved with this method.
178
178
  *
179
179
  * @example
180
- * // This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
180
+ * This example uses the Salesforce REST API to get organization limit values. For information on limits, see Limits in the REST API Developer Guide.
181
+ *
182
+ * ```apex
181
183
  * Http h = new Http();
182
184
  * HttpRequest req = new HttpRequest();
183
185
  * req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
@@ -185,6 +187,7 @@ global class Url {
185
187
  * req.setMethod('GET');
186
188
  * req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
187
189
  * HttpResponse res = h.send(req);
190
+ * ```
188
191
  *
189
192
  * @see-also
190
193
  * * [Lightning Aura Components Developer Guide: Making API Calls from Apex](https://developer.salesforce.com/docs/atlas.en-us.250.0.lightning.meta/lightning/apex_api_calls.htm)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "2.25.0-alpha.5",
3
+ "version": "2.25.0-alpha.8",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -21,9 +21,7 @@
21
21
  "lint": "eslint \"./src/**/*.{js,ts}\" --quiet --fix",
22
22
  "prepare": "npm run build",
23
23
  "version": "npm run format && git add -A src",
24
- "postversion": "git push && git push --tags",
25
- "docs:init": "docsify init docs",
26
- "docs:serve": "docsify serve docs"
24
+ "postversion": "git push && git push --tags"
27
25
  },
28
26
  "author": "Cesar Parra",
29
27
  "license": "MIT",
@@ -37,7 +35,6 @@
37
35
  "@types/jest": "^29.5.12",
38
36
  "@types/node": "^20.14.10",
39
37
  "@types/shelljs": "^0.8.15",
40
- "docsify": "^4.13.1",
41
38
  "eslint": "^8.57.0",
42
39
  "eslint-config-prettier": "^9.1.0",
43
40
  "husky": "^9.0.11",
@@ -61,7 +58,7 @@
61
58
  ]
62
59
  },
63
60
  "dependencies": {
64
- "@cparra/apex-reflection": "2.11.2",
61
+ "@cparra/apex-reflection": "2.11.3",
65
62
  "@types/js-yaml": "^4.0.9",
66
63
  "@types/yargs": "^17.0.32",
67
64
  "chalk": "^4.1.2",
@@ -340,11 +340,13 @@ describe('Generates interface documentation', () => {
340
340
  const input = `
341
341
  /**
342
342
  * @mermaid
343
+ * \`\`\`mermaid
343
344
  * graph TD
344
345
  * A[Square Rect] -- Link text --> B((Circle))
345
346
  * A --> C(Round Rect)
346
347
  * B --> D{Rhombus}
347
348
  * C --> D
349
+ * \`\`\`
348
350
  */
349
351
  public class MyClass {}
350
352
  `;
@@ -359,11 +361,13 @@ describe('Generates interface documentation', () => {
359
361
  const input = `
360
362
  /**
361
363
  * @example
364
+ * \`\`\`apex
362
365
  * public class MyClass {
363
366
  * public void myMethod() {
364
367
  * System.debug('Hello, World!');
365
368
  * }
366
369
  * }
370
+ * \`\`\`
367
371
  */
368
372
  public class MyClass {}`;
369
373
 
@@ -669,11 +673,13 @@ describe('Generates interface documentation', () => {
669
673
  public class MyClass {
670
674
  /**
671
675
  * @mermaid
676
+ * \`\`\`mermaid
672
677
  * graph TD
673
678
  * A[Square Rect] -- Link text --> B((Circle))
674
679
  * A --> C(Round Rect)
675
680
  * B --> D{Rhombus}
676
681
  * C --> D
682
+ * \`\`\`
677
683
  */
678
684
  public void myMethod() {}
679
685
  }
@@ -287,11 +287,13 @@ describe('Generates enum documentation', () => {
287
287
  const input = `
288
288
  /**
289
289
  * @mermaid
290
+ * \`\`\`mermaid
290
291
  * graph TD
291
292
  * A[Square Rect] -- Link text --> B((Circle))
292
293
  * A --> C(Round Rect)
293
294
  * B --> D{Rhombus}
294
295
  * C --> D
296
+ * \`\`\`
295
297
  */
296
298
  public enum MyEnum {
297
299
  VALUE1,
@@ -309,11 +311,13 @@ describe('Generates enum documentation', () => {
309
311
  const input = `
310
312
  /**
311
313
  * @example
314
+ * \`\`\`apex
312
315
  * public class MyClass {
313
316
  * public void myMethod() {
314
317
  * System.debug('Hello, World!');
315
318
  * }
316
319
  * }
320
+ * \`\`\`
317
321
  */
318
322
  public enum MyEnum {
319
323
  VALUE1,
@@ -261,11 +261,13 @@ describe('Generates interface documentation', () => {
261
261
  const input = `
262
262
  /**
263
263
  * @mermaid
264
+ * \`\`\`mermaid
264
265
  * graph TD
265
266
  * A[Square Rect] -- Link text --> B((Circle))
266
267
  * A --> C(Round Rect)
267
268
  * B --> D{Rhombus}
268
269
  * C --> D
270
+ * \`\`\`
269
271
  */
270
272
  public interface MyInterface {}
271
273
  `;
@@ -280,11 +282,13 @@ describe('Generates interface documentation', () => {
280
282
  const input = `
281
283
  /**
282
284
  * @example
285
+ * \`\`\`apex
283
286
  * public class MyClass {
284
287
  * public void myMethod() {
285
288
  * System.debug('Hello, World!');
286
289
  * }
287
290
  * }
291
+ * \`\`\`
288
292
  */
289
293
  public interface MyInterface {}`;
290
294
 
@@ -343,11 +347,13 @@ describe('Generates interface documentation', () => {
343
347
  public interface MyInterface {
344
348
  /**
345
349
  * @mermaid
350
+ * \`\`\`mermaid
346
351
  * graph TD
347
352
  * A[Square Rect] -- Link text --> B((Circle))
348
353
  * A --> C(Round Rect)
349
354
  * B --> D{Rhombus}
350
355
  * C --> D
356
+ * \`\`\`
351
357
  */
352
358
  void myMethod();
353
359
  }
@@ -1,4 +1,4 @@
1
- import { CustomTag, RenderableDocumentation, RenderableContent, CodeBlock } from './types';
1
+ import { CustomTag, RenderableDocumentation, RenderableContent } from './types';
2
2
  import { Describable, Documentable, GetRenderableContentByTypeName } from './types';
3
3
  import { replaceInlineReferences } from './inline';
4
4
  import { isEmptyLine } from './type-utils';
@@ -9,59 +9,62 @@ export function adaptDescribable(
9
9
  ): {
10
10
  description?: RenderableContent[];
11
11
  } {
12
- function describableToRenderableContent(describable: Describable): RenderableContent[] | undefined {
13
- if (!describable) {
14
- return;
15
- }
12
+ return {
13
+ description: describableToRenderableContent(describable, linkGenerator),
14
+ };
15
+ }
16
16
 
17
- let content: RenderableContent[] = [];
18
- for (let i = 0; i < describable.length; i++) {
19
- const line = describable[i];
20
- // The language might or might not be present after ```
21
- const codeBlockMatch = line.match(/^```([a-zA-Z]*)$/);
22
- if (codeBlockMatch) {
23
- // Check if the language is present, if not, fallback to "apex"
24
- const language = codeBlockMatch[1] || 'apex';
25
- const codeBlockLines: string[] = [];
26
- i++;
27
- while (i < describable.length) {
28
- const currentLine = describable[i];
29
- if (currentLine.trim() === '```') {
30
- break;
31
- }
32
- codeBlockLines.push(currentLine);
33
- i++;
17
+ export function describableToRenderableContent(
18
+ describable: Describable,
19
+ linkGenerator: GetRenderableContentByTypeName,
20
+ ): RenderableContent[] | undefined {
21
+ if (!describable) {
22
+ return;
23
+ }
24
+
25
+ let content: RenderableContent[] = [];
26
+ for (let i = 0; i < describable.length; i++) {
27
+ const line = describable[i];
28
+ // The language might or might not be present after ```
29
+ const codeBlockMatch = line.match(/^```([a-zA-Z]*)$/);
30
+ if (codeBlockMatch) {
31
+ // Check if the language is present, if not, fallback to "apex"
32
+ const language = codeBlockMatch[1] || 'apex';
33
+ const codeBlockLines: string[] = [];
34
+ i++;
35
+ while (i < describable.length) {
36
+ const currentLine = describable[i];
37
+ if (currentLine.trim() === '```') {
38
+ break;
34
39
  }
35
- content = [
36
- ...content,
37
- {
38
- __type: 'code-block',
39
- language,
40
- content: codeBlockLines,
41
- },
42
- { __type: 'empty-line' },
43
- ];
44
- continue;
40
+ codeBlockLines.push(currentLine);
41
+ i++;
45
42
  }
46
-
47
43
  content = [
48
44
  ...content,
49
- ...replaceInlineReferences(line, linkGenerator),
50
45
  {
51
- __type: 'empty-line',
46
+ __type: 'code-block',
47
+ language,
48
+ content: codeBlockLines,
52
49
  },
50
+ { __type: 'empty-line' },
53
51
  ];
52
+ continue;
54
53
  }
55
- return (
56
- content
57
- // If the last element is an empty line, remove it
58
- .filter((line, index, lines) => !(isEmptyLine(line) && index === lines.length - 1))
59
- );
60
- }
61
54
 
62
- return {
63
- description: describableToRenderableContent(describable),
64
- };
55
+ content = [
56
+ ...content,
57
+ ...replaceInlineReferences(line, linkGenerator),
58
+ {
59
+ __type: 'empty-line',
60
+ },
61
+ ];
62
+ }
63
+ return (
64
+ content
65
+ // If the last element is an empty line, remove it
66
+ .filter((line, index, lines) => !(isEmptyLine(line) && index === lines.length - 1))
67
+ );
65
68
  }
66
69
 
67
70
  export function adaptDocumentable(
@@ -70,7 +73,7 @@ export function adaptDocumentable(
70
73
  subHeadingLevel: number,
71
74
  ): RenderableDocumentation {
72
75
  function extractCustomTags(type: Documentable): CustomTag[] {
73
- const baseTags = ['description', 'group', 'author', 'date', 'see', 'example', 'mermaid', 'throws', 'exception'];
76
+ const baseTags = ['description', 'group', 'author', 'date', 'see', 'example', 'throws', 'exception'];
74
77
 
75
78
  return (
76
79
  type.docComment?.annotations
@@ -82,12 +85,6 @@ export function adaptDocumentable(
82
85
  );
83
86
  }
84
87
 
85
- function extractAnnotationBodyLines(type: Documentable, annotationName: string): string[] | undefined {
86
- return type.docComment?.annotations.find(
87
- (currentAnnotation) => currentAnnotation.name.toLowerCase() === annotationName,
88
- )?.bodyLines;
89
- }
90
-
91
88
  function extractAnnotationBody(type: Documentable, annotationName: string): string | undefined {
92
89
  return type.docComment?.annotations.find(
93
90
  (currentAnnotation) => currentAnnotation.name.toLowerCase() === annotationName,
@@ -102,30 +99,14 @@ export function adaptDocumentable(
102
99
  );
103
100
  }
104
101
 
105
- function bodyLinesToCodeBlock(language: string, bodyLines: string[] | undefined): CodeBlock | undefined {
106
- if (!bodyLines) {
107
- return;
108
- }
109
- return {
110
- __type: 'code-block',
111
- language,
112
- content: bodyLines,
113
- };
114
- }
115
-
116
102
  return {
117
103
  ...adaptDescribable(documentable.docComment?.descriptionLines, linkGenerator),
118
104
  annotations: documentable.annotations.map((annotation) => annotation.type.toUpperCase()),
119
105
  customTags: extractCustomTags(documentable),
120
- mermaid: {
121
- headingLevel: subHeadingLevel,
122
- heading: 'Diagram',
123
- value: bodyLinesToCodeBlock('mermaid', extractAnnotationBodyLines(documentable, 'mermaid')),
124
- },
125
106
  example: {
126
107
  headingLevel: subHeadingLevel,
127
108
  heading: 'Example',
128
- value: bodyLinesToCodeBlock('apex', documentable.docComment?.exampleAnnotation?.bodyLines),
109
+ value: describableToRenderableContent(documentable.docComment?.exampleAnnotation?.bodyLines, linkGenerator),
129
110
  },
130
111
  group: extractAnnotationBody(documentable, 'group'),
131
112
  author: extractAnnotationBody(documentable, 'author'),
@@ -84,8 +84,7 @@ type RenderableDocumentation = {
84
84
  annotations?: Annotation[];
85
85
  description?: RenderableContent[];
86
86
  customTags?: CustomTag[];
87
- mermaid: RenderableSection<CodeBlock | undefined>;
88
- example: RenderableSection<CodeBlock | undefined>;
87
+ example: RenderableSection<RenderableContent[] | undefined>;
89
88
  group?: string;
90
89
  author?: string;
91
90
  date?: string;
@@ -21,6 +21,6 @@ export const documentablePartialTemplate = `
21
21
 
22
22
  {{#if doc.example.value}}
23
23
  {{ heading doc.example.headingLevel doc.example.heading }}
24
- {{code doc.example.value}}
24
+ {{{renderContent doc.example.value}}}
25
25
  {{/if}}
26
26
  `.trim();