You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds support for target ranges defined by matching `start`...`end` annotation comments. This allows you to annotate ranges of code without having to count lines or manually updating the ranges when the code changes.
6
+
7
+
The following example shows how to define a simple target line range using the new feature:
8
+
9
+
```js
10
+
// [!mark:start]
11
+
functionfoo() {
12
+
console.log('foo')
13
+
}
14
+
// [!mark:end]
15
+
```
16
+
17
+
You can also combine `start`...`end` ranges with search queries, which limits the search to the range defined by the `start` and `end` annotation comments:
18
+
19
+
```js
20
+
// [!mark:"log":start]
21
+
functionfoo() {
22
+
console.log('The words "log" will be marked both in the method call and this text.')
23
+
console.log('Also on this line.')
24
+
}
25
+
// [!mark:"log":end]
26
+
27
+
console.log('As this line is outside the range, "log" will not be marked.')
Copy file name to clipboardExpand all lines: .config/typedoc.preamble.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,7 @@ Annotation tags consist of the following parts:
78
78
- If omitted, the annotation targets only 1 line or target search query match. Depending on the location of the annotation, this may be above, below, or on the line containing the annotation itself.
79
79
- The following range types are supported:
80
80
- A **numeric range** defined by positive or negative numbers, e.g. `:3`, `:-1`. Positive ranges extend downwards, negative ranges extend upwards from the location of the annotation. If the annotation shares a line with code, the range starts at this line. Otherwise, it starts at the first non-annotation line in the direction of the range. The special range `:0` can be used to create standalone annotations that do not target any code.
81
+
- A **range between two matching annotations** defined by the suffixes `:start` and `:end`, e.g. `// [!ins:start]`, followed by some code lines, and a matching `// [!ins:end]` to mark the end of the inserted code.
Copy file name to clipboardExpand all lines: README.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,5 @@
1
1
# annotation-comments
2
2
3
-
> **Warning**: ⚠ This repository has just been made public and is still a work in progress. The documentation and code quality will be improved in the near future.
4
-
>
5
-
> As the API has not been finalized yet, we recommend waiting until this notice has been removed before attempting to use this package or contributing to it.
6
-
7
3
This library provides functionality to parse and extract annotation comments from code snippets.
8
4
9
5
Annotation comments allow authors to annotate pieces of source code with additional information (e.g. marking important lines, highlighting changes, adding notes, and more) while keeping it readable and functional:
Copy file name to clipboardExpand all lines: packages/annotation-comments/README.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,7 @@ Annotation tags consist of the following parts:
78
78
- If omitted, the annotation targets only 1 line or target search query match. Depending on the location of the annotation, this may be above, below, or on the line containing the annotation itself.
79
79
- The following range types are supported:
80
80
- A **numeric range** defined by positive or negative numbers, e.g. `:3`, `:-1`. Positive ranges extend downwards, negative ranges extend upwards from the location of the annotation. If the annotation shares a line with code, the range starts at this line. Otherwise, it starts at the first non-annotation line in the direction of the range. The special range `:0` can be used to create standalone annotations that do not target any code.
81
+
- A **range between two matching annotations** defined by the suffixes `:start` and `:end`, e.g. `// [!ins:start]`, followed by some code lines, and a matching `// [!ins:end]` to mark the end of the inserted code.
81
82
- The **closing sequence**`]`
82
83
83
84
### Annotation content
@@ -547,7 +548,7 @@ type AnnotationTag = {
547
548
name: string;
548
549
range: SourceRange;
549
550
rawTag: string;
550
-
relativeTargetRange: number;
551
+
relativeTargetRange: number | "start" | "end";
551
552
targetSearchQuery: string | RegExp;
552
553
};
553
554
```
@@ -581,7 +582,7 @@ rawTag: string;
581
582
##### relativeTargetRange?
582
583
583
584
```ts
584
-
optional relativeTargetRange: number;
585
+
optional relativeTargetRange: number | "start" | "end";
0 commit comments