Skip to content

Commit f04292b

Browse files
shawninderGerrit0
authored andcommitted
Improve docs
1 parent 7a5eca5 commit f04292b

File tree

5 files changed

+60
-76
lines changed

5 files changed

+60
-76
lines changed

example/src/documents/include-code.md

+3-61
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
---
2-
title: Include Code
3-
category: Documents
4-
---
5-
6-
# Including Code
7-
8-
It can be convenient to write long-form guides/tutorials outside of doc comments.
9-
To support this, TypeDoc supports including documents (like this page!) which exist
10-
as standalone `.md` files in your repository.
11-
These files can then import code from other files using the `@includeCode` tag.
12-
131
## The `@includeCode` Tag
142

15-
The `@includeCode` tag can be placed in an md file to insert a code snippet at that location. As an example, this file is inserting the code block below using:
3+
For convenience, an `@includeCode` inline tag is also recognized, which will include the referenced file within a code block, using the file extension for selecting the syntax highlighting language.
4+
As an example, this file is inserting the code block below using:
165

176
```md
187
{@includeCode ../reexports.ts}
@@ -21,51 +10,4 @@ The `@includeCode` tag can be placed in an md file to insert a code snippet at t
2110
**Result:**
2211
{@includeCode ../reexports.ts}
2312

24-
### Include parts of files
25-
26-
#### Using regions
27-
28-
The `@includeCode` tag can also include only parts of a file using language-dependent region syntax as defined in the VS Code documentation for [Folding](https://code.visualstudio.com/docs/editor/codebasics#_folding), reproduced here for convenience:
29-
30-
| Language | Start region | End region |
31-
| --------------------- | ------------------------------------------------------ | ---------------------------------------------------------- |
32-
| Bat | `::#region regionName` or `REM #region regionName` | `::#endregion regionName` or `REM #endregion regionName` |
33-
| C# | `#region regionName` | `#endregion regionName` |
34-
| C/C++ | `#pragma region regionName` | `#pragma endregion regionName` |
35-
| CSS/Less/SCSS | `/*#region regionName*/` | `/*#endregion regionName*/` |
36-
| Coffeescript | `#region regionName` | `#endregion regionName` |
37-
| F# | `//#region regionName` or `(#_region) regionName` | `//#endregion regionName` or `(#_endregion) regionName` |
38-
| Java | `//#region regionName` or `//<editor-fold> regionName` | `//#endregion regionName` or `//</editor-fold> regionName` |
39-
| Markdown | `<!-- #region regionName -->` | `<!-- #endregion regionName -->` |
40-
| Perl5 | `#region regionName` or `=pod regionName` | `#endregion regionName` or `=cut regionName` |
41-
| PHP | `#region regionName` | `#endregion regionName` |
42-
| PowerShell | `#region regionName` | `#endregion regionName` |
43-
| Python | `#region regionName` or `# region regionName` | `#endregion regionName` or `# endregion regionName` |
44-
| TypeScript/JavaScript | `//#region regionName` | `//#endregion regionName` |
45-
| Visual Basic | `#Region regionName` | `#End Region regionName` |
46-
47-
For example:
48-
49-
```md
50-
{@includeCode ../enums.ts#simpleEnum}
51-
```
52-
53-
**Result:**
54-
55-
{@includeCode ../enums.ts#simpleEnum}
56-
57-
#### Using line numbers
58-
59-
For cases where you can't modify the source file or where comments are not allowed (in JSON files, for example), you can use line numbers to include a specific region of a file.
60-
61-
For example:
62-
63-
```md
64-
{@includeCode ../../package.json:2,6-7}
65-
```
66-
67-
**Result:**
68-
69-
{@includeCode ../../package.json:2,6-7}
70-
71-
> **Warning:** This makes it difficult to maintain the file, as you may need to update the line numbers if you change the code.
13+
{@include ../../../site/tags/include.md#includePartsOfFiles}

example/src/documents/include.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Include and Include Code
3+
category: Documents
4+
---
5+
6+
# Including other files
7+
8+
It can be convenient to write long-form guides/tutorials outside of doc comments.
9+
To support this, TypeDoc supports including documents (like this page!) which exist
10+
as standalone `.md` files in your repository.
11+
These files can then import other files using the `@include` tag.
12+
13+
For example, the rest of this page is imported from `include-code.md` using:
14+
15+
```md
16+
{@include ./include-code.md}
17+
```
18+
19+
{@include ./include-code.md}

example/src/enums.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** Describes the status of a delivery order. */
2+
3+
// #region simpleEnumRegion
24
// #region simpleEnum
35
export enum SimpleEnum {
46
/** This order has just been placed and is yet to be processed. */
@@ -11,6 +13,7 @@ export enum SimpleEnum {
1113
Complete = "COMPLETE",
1214
}
1315
// #endregion simpleEnum
16+
// #endregion simpleEnumRegion
1417

1518
/**
1619
* [A crazy enum from the TypeScript

example/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @document documents/external-markdown.md
88
* @document documents/markdown.md
99
* @document documents/syntax-highlighting.md
10-
* @document documents/include-code.md
10+
* @document documents/include.md
1111
*/
1212
export * from "./functions";
1313
export * from "./variables";

site/tags/include.md

+34-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ selecting the syntax highlighting language.
1616

1717
## Example
1818

19-
```js
19+
```ts
2020
/**
2121
* {@include ./doSomething_docs.md}
2222
*
@@ -30,11 +30,31 @@ selecting the syntax highlighting language.
3030
function doSomething() {}
3131
```
3232

33+
<!-- #region includePartsOfFiles -->
34+
3335
### Include parts of files
3436

35-
#### Using regions
37+
#### Using regions (preferred)
38+
39+
The `@include` and `@includeCode` tags can also include only parts of a file by referring to a specific named region.
40+
41+
For example:
42+
43+
```md
44+
{@includeCode ../../example/src/enums.ts#simpleEnum}
45+
```
46+
47+
Regions are specified in the files themselves via comments.
48+
49+
In Typescript for example, the following would be a valid region:
50+
51+
{@includeCode ../../example/src/enums.ts#simpleEnumRegion}
3652

37-
The `@include` and `@includeCode` tags can also include only parts of a file using language-dependent region syntax as defined in the VS Code documentation for [Folding](https://code.visualstudio.com/docs/editor/codebasics#_folding), reproduced here for convenience:
53+
**Result:**
54+
55+
{@includeCode ../../example/src/enums.ts#simpleEnum}
56+
57+
Language-dependent region syntax is meant to be compatible with VS Code [Folding](https://code.visualstudio.com/docs/editor/codebasics#_folding). Here is a reproduction of their table, but with `regionName` everywhere because we want to insist on named regions.
3858

3959
| Language | Start region | End region |
4060
| --------------------- | ------------------------------------------------------ | ---------------------------------------------------------- |
@@ -53,25 +73,25 @@ The `@include` and `@includeCode` tags can also include only parts of a file usi
5373
| TypeScript/JavaScript | `//#region regionName` | `//#endregion regionName` |
5474
| Visual Basic | `#Region regionName` | `#End Region regionName` |
5575

56-
##### Example
76+
#### Using line numbers (risky)
77+
78+
When you can't add comments to define regions (in JSON files, for example) you can use line numbers instead to include a specific region of a file.
79+
80+
> **Warning:** Referencing line numbers should be avoided since the reference will likely break when every time the file changes.
5781
5882
```md
59-
Here is a simple enum:
60-
{@includeCode ../enums.js#simpleEnum}
83+
{@includeCode ../../package.json:2,6-7}
6184
```
6285

63-
#### Using line numbers
86+
**Result:**
6487

65-
For cases where you can't modify the source file or where comments are not allowed (in JSON files, for example), you can use line numbers to include a specific region of a file.
88+
{@includeCode ../../package.json:2,6-7}
6689

67-
##### Example
90+
A colon (`:`) separates the file path from the line numbers: a comma-separated list of numbers or ranges of the form `<start>-<end>` (`6-7` in the example above).
6891

69-
```md
70-
In package.json, notice the following information:
71-
{@includeCode ../../package.json:2,6-7}
72-
```
92+
> **Note:** The first line in the file Line 1, not Line 0, just like you would see in most code editors.
7393
74-
> **Warning:** This makes it difficult to maintain the file, as you may need to update the line numbers if you change the code.
94+
<!-- #endregion includePartsOfFiles -->
7595

7696
## See Also
7797

0 commit comments

Comments
 (0)