@riebeckite/plugin-code-annotations 0.0.5 → 0.0.7

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.
package/README.md CHANGED
@@ -133,5 +133,5 @@ highlighting regardless.
133
133
 
134
134
  ## See also
135
135
 
136
- - [Plugin guide](../../docs/plugins_en.md)
136
+ - [Plugin guide](../../../docs/en/plugin-system.md)
137
137
  - [`@riebeckite/plugin-code-enhance`](../code-enhance/README.md)
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { CodeAnnotationsOptions } from "./src/types.js";
2
- export { ANNOTATIONS_META_PREFIX, collectCodeAnnotations, createEmptyPlan, deserializeAnnotations, encodeAnnotationsMeta, extractAnnotationsMeta, hasAnnotations, parseCodeAnnotations, parseLineRanges, serializeAnnotations, stripInlineCodeAnnotation, } from "./src/annotations.js";
3
2
  export type { CollectedCodeAnnotations, InlineCodeAnnotation, } from "./src/annotations.js";
3
+ export { ANNOTATIONS_META_PREFIX, collectCodeAnnotations, createEmptyPlan, deserializeAnnotations, encodeAnnotationsMeta, extractAnnotationsMeta, hasAnnotations, parseCodeAnnotations, parseLineRanges, serializeAnnotations, stripInlineCodeAnnotation, } from "./src/annotations.js";
4
+ export { DEFAULT_CODE_ANNOTATIONS_OPTIONS, resolveCodeAnnotationsOptions, } from "./src/options.js";
4
5
  export { rehypeCodeAnnotations } from "./src/rehype.js";
5
6
  export { remarkCodeAnnotations } from "./src/remark.js";
6
- export { DEFAULT_CODE_ANNOTATIONS_OPTIONS, resolveCodeAnnotationsOptions, } from "./src/options.js";
7
7
  export type { CodeAnnotationKind, CodeAnnotationPlan, CodeAnnotationsOptions, ResolvedCodeAnnotationsOptions, } from "./src/types.js";
8
8
  /**
9
9
  * VitePress/Docusaurus-style code block annotations: line highlighting from
package/dist/index.js CHANGED
@@ -1,6 +1,29 @@
1
1
  // index.ts
2
2
  import { createStyleAsset, definePlugin } from "@riebeckite/core";
3
3
 
4
+ // src/options.ts
5
+ var DEFAULT_CODE_ANNOTATIONS_OPTIONS = {
6
+ className: "rb-code",
7
+ lineClassName: "rb-code__line",
8
+ highlightClassName: "rb-code__line--highlighted",
9
+ addedClassName: "rb-code__line--added",
10
+ removedClassName: "rb-code__line--removed",
11
+ focusClassName: "rb-code__line--focused"
12
+ };
13
+ function resolveCodeAnnotationsOptions(options = {}) {
14
+ const resolved = {
15
+ className: options.className ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.className,
16
+ lineClassName: options.lineClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.lineClassName,
17
+ highlightClassName: options.highlightClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.highlightClassName,
18
+ addedClassName: options.addedClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.addedClassName,
19
+ removedClassName: options.removedClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.removedClassName,
20
+ focusClassName: options.focusClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.focusClassName
21
+ };
22
+ const language = options.language?.trim();
23
+ if (language) resolved.language = language;
24
+ return resolved;
25
+ }
26
+
4
27
  // src/annotations.ts
5
28
  var ANNOTATIONS_META_PREFIX = "rb-annotations=";
6
29
  var ANNOTATION_KEYS = [
@@ -11,7 +34,7 @@ var ANNOTATION_KEYS = [
11
34
  ];
12
35
  var FOCUS_META_PATTERN = /(?:^|\s)focus[:=]\{([^}]*)\}/g;
13
36
  var HIGHLIGHT_META_PATTERN = /\{([^{}]*)\}/g;
14
- var INLINE_ANNOTATION_PATTERN = /([ \t]*)(?:(?:\/\/|#|--)[ \t]*\[!code[ \t]+(focus|highlight|\+\+|--)(?::(\d+))?\]|<!--[ \t]*\[!code[ \t]+(focus|highlight|\+\+|--)(?::(\d+))?[ \t]*-->)[ \t]*$/;
37
+ var INLINE_ANNOTATION_PATTERN = /([ \t]*)(?:(?:\/\/|#|--)[ \t]*\[!code[ \t]+(focus|highlight|\+\+|--)(?::(\d+))?\]|<!--[ \t]*\[!code[ \t]+(focus|highlight|\+\+|--)(?::(\d+))?[ \t]*\][ \t]*-->)[ \t]*$/;
15
38
  function createEmptyPlan() {
16
39
  return { highlight: [], added: [], removed: [], focus: [] };
17
40
  }
@@ -236,29 +259,6 @@ function getChildren(node) {
236
259
  return Array.isArray(children) ? children : [];
237
260
  }
238
261
 
239
- // src/options.ts
240
- var DEFAULT_CODE_ANNOTATIONS_OPTIONS = {
241
- className: "rb-code",
242
- lineClassName: "rb-code__line",
243
- highlightClassName: "rb-code__line--highlighted",
244
- addedClassName: "rb-code__line--added",
245
- removedClassName: "rb-code__line--removed",
246
- focusClassName: "rb-code__line--focused"
247
- };
248
- function resolveCodeAnnotationsOptions(options = {}) {
249
- const resolved = {
250
- className: options.className ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.className,
251
- lineClassName: options.lineClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.lineClassName,
252
- highlightClassName: options.highlightClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.highlightClassName,
253
- addedClassName: options.addedClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.addedClassName,
254
- removedClassName: options.removedClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.removedClassName,
255
- focusClassName: options.focusClassName ?? DEFAULT_CODE_ANNOTATIONS_OPTIONS.focusClassName
256
- };
257
- const language = options.language?.trim();
258
- if (language) resolved.language = language;
259
- return resolved;
260
- }
261
-
262
262
  // src/rehype.ts
263
263
  function rehypeCodeAnnotations(options = resolveCodeAnnotationsOptions()) {
264
264
  return (tree) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-code-annotations",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,11 @@
15
15
  "./style.css": "./style.css"
16
16
  },
17
17
  "dependencies": {
18
- "@riebeckite/core": "0.0.5"
18
+ "@riebeckite/core": "0.0.7"
19
+ },
20
+ "devDependencies": {
21
+ "tsx": "^4.22.4",
22
+ "@riebeckite/test": "0.0.7"
19
23
  },
20
24
  "publishConfig": {
21
25
  "access": "public"
@@ -50,6 +54,7 @@
50
54
  "./style.css"
51
55
  ],
52
56
  "scripts": {
53
- "build": "node ../../../scripts/build_package.mjs"
57
+ "build": "node ../../../scripts/build_package.mjs",
58
+ "test": "node --import tsx --test \"test/*.test.ts\""
54
59
  }
55
60
  }
package/style.css CHANGED
@@ -1,36 +1,36 @@
1
- .rb-code {
2
- --rb-code-annotation-accent: var(--rb-color-accent, #686868);
3
- position: relative;
4
- }
5
-
6
- .rb-code__line {
7
- display: block;
8
- min-width: 100%;
9
- }
10
-
11
- .rb-code__line--highlighted {
12
- background: color-mix(
13
- in srgb,
14
- var(--rb-code-annotation-accent) 14%,
15
- transparent
16
- );
17
- }
18
-
19
- .rb-code__line--added {
20
- background: color-mix(in srgb, #1f883d 14%, transparent);
21
- }
22
-
23
- .rb-code__line--removed {
24
- background: color-mix(in srgb, #cf222e 14%, transparent);
25
- }
26
-
27
- .rb-code__line--focused {
28
- background: color-mix(
29
- in srgb,
30
- var(--rb-code-annotation-accent) 10%,
31
- transparent
32
- );
33
- outline: 1px solid
34
- color-mix(in srgb, var(--rb-code-annotation-accent) 45%, transparent);
35
- outline-offset: -1px;
36
- }
1
+ .rb-code {
2
+ --rb-code-annotation-accent: var(--rb-color-accent, #686868);
3
+ position: relative;
4
+ }
5
+
6
+ .rb-code__line {
7
+ display: block;
8
+ min-width: 100%;
9
+ }
10
+
11
+ .rb-code__line--highlighted {
12
+ background: color-mix(
13
+ in srgb,
14
+ var(--rb-code-annotation-accent) 14%,
15
+ transparent
16
+ );
17
+ }
18
+
19
+ .rb-code__line--added {
20
+ background: color-mix(in srgb, #1f883d 14%, transparent);
21
+ }
22
+
23
+ .rb-code__line--removed {
24
+ background: color-mix(in srgb, #cf222e 14%, transparent);
25
+ }
26
+
27
+ .rb-code__line--focused {
28
+ background: color-mix(
29
+ in srgb,
30
+ var(--rb-code-annotation-accent) 10%,
31
+ transparent
32
+ );
33
+ outline: 1px solid
34
+ color-mix(in srgb, var(--rb-code-annotation-accent) 45%, transparent);
35
+ outline-offset: -1px;
36
+ }