@mui/internal-docs-infra 0.1.1-alpha.11 → 0.1.1-alpha.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CodeProvider.d.ts","sourceRoot":"","sources":["../../src/CodeProvider/CodeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAe,MAAM,oBAAoB,CAAC;AAG5F,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,UAAU,GACX,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,2CAmDA"}
1
+ {"version":3,"file":"CodeProvider.d.ts","sourceRoot":"","sources":["../../src/CodeProvider/CodeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAe,MAAM,oBAAoB,CAAC;AAI5F,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,UAAU,GACX,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,2CAsDA"}
@@ -5,6 +5,7 @@ import * as React from 'react';
5
5
  import { createStarryNight } from '@wooorm/starry-night';
6
6
  import { CodeContext } from "./CodeContext.js";
7
7
  import { extensionMap, grammars } from "../pipeline/parseSource/grammars.js";
8
+ import { starryNightGutter } from "../pipeline/parseSource/addLineGutters.js";
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  export function CodeProvider(_ref) {
10
11
  var children = _ref.children,
@@ -35,7 +36,10 @@ export function CodeProvider(_ref) {
35
36
  }]
36
37
  };
37
38
  }
38
- return starryNight.highlight(source, extensionMap[fileType]);
39
+ var highlighted = starryNight.highlight(source, extensionMap[fileType]);
40
+ starryNightGutter(highlighted); // mutates the tree to add line gutters
41
+
42
+ return highlighted;
39
43
  };
40
44
  return parseSourceFn;
41
45
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.1.1-alpha.11",
3
+ "version": "0.1.1-alpha.12",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "main": "./index.js",
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'hast';
2
+ export declare function starryNightGutter(tree: Root): void;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addLineGutters.d.ts","sourceRoot":"","sources":["../../../src/pipeline/parseSource/addLineGutters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA+B,IAAI,EAAE,MAAM,MAAM,CAAC;AAE9D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAuElD"}
@@ -0,0 +1,82 @@
1
+ // Example copied from https://github.com/wooorm/starry-night#example-adding-line-numbers
2
+
3
+ export function starryNightGutter(tree) {
4
+ /** @type {Array<RootContent>} */
5
+ var replacement = [];
6
+ var search = /\r?\n|\r/g;
7
+ var index = -1;
8
+ var start = 0;
9
+ var startTextRemainder = '';
10
+ var lineNumber = 0;
11
+ while (index + 1 < tree.children.length) {
12
+ index += 1;
13
+ var child = tree.children[index];
14
+ if (child.type === 'text') {
15
+ var textStart = 0;
16
+ var match = search.exec(child.value);
17
+ while (match) {
18
+ // Nodes in this line.
19
+ var _line = tree.children.slice(start, index);
20
+
21
+ // Prepend text from a partial matched earlier text.
22
+ if (startTextRemainder) {
23
+ _line.unshift({
24
+ type: 'text',
25
+ value: startTextRemainder
26
+ });
27
+ startTextRemainder = '';
28
+ }
29
+
30
+ // Append text from this text.
31
+ if (match.index > textStart) {
32
+ _line.push({
33
+ type: 'text',
34
+ value: child.value.slice(textStart, match.index)
35
+ });
36
+ }
37
+
38
+ // Add a line, and the eol.
39
+ lineNumber += 1;
40
+ replacement.push(createLine(_line, lineNumber), {
41
+ type: 'text',
42
+ value: match[0]
43
+ });
44
+ start = index + 1;
45
+ textStart = match.index + match[0].length;
46
+ match = search.exec(child.value);
47
+ }
48
+
49
+ // If we matched, make sure to not drop the text after the last line ending.
50
+ if (start === index + 1) {
51
+ startTextRemainder = child.value.slice(textStart);
52
+ }
53
+ }
54
+ }
55
+ var line = tree.children.slice(start);
56
+ // Prepend text from a partial matched earlier text.
57
+ if (startTextRemainder) {
58
+ line.unshift({
59
+ type: 'text',
60
+ value: startTextRemainder
61
+ });
62
+ startTextRemainder = '';
63
+ }
64
+ if (line.length > 0) {
65
+ lineNumber += 1;
66
+ replacement.push(createLine(line, lineNumber));
67
+ }
68
+
69
+ // Replace children with new array.
70
+ tree.children = replacement;
71
+ }
72
+ function createLine(children, line) {
73
+ return {
74
+ type: 'element',
75
+ tagName: 'span',
76
+ properties: {
77
+ className: 'line',
78
+ dataLineNumber: line
79
+ },
80
+ children: children
81
+ };
82
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"parseSource.d.ts","sourceRoot":"","sources":["../../../src/pipeline/parseSource/parseSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD,eAAO,MAAM,WAAW,EAAE,WAsBzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,WAAW,CAM7D,CAAC"}
1
+ {"version":3,"file":"parseSource.d.ts","sourceRoot":"","sources":["../../../src/pipeline/parseSource/parseSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQpD,eAAO,MAAM,WAAW,EAAE,WAyBzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,WAAW,CAM7D,CAAC"}
@@ -2,6 +2,7 @@ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import { createStarryNight } from '@wooorm/starry-night';
4
4
  import { grammars, extensionMap } from "./grammars.js";
5
+ import { starryNightGutter } from "./addLineGutters.js";
5
6
  var starryNight = null;
6
7
  export var parseSource = function parseSource(source, fileName) {
7
8
  if (!starryNight) {
@@ -18,7 +19,10 @@ export var parseSource = function parseSource(source, fileName) {
18
19
  }]
19
20
  };
20
21
  }
21
- return starryNight.highlight(source, extensionMap[fileType]);
22
+ var highlighted = starryNight.highlight(source, extensionMap[fileType]);
23
+ starryNightGutter(highlighted); // mutates the tree to add line gutters
24
+
25
+ return highlighted;
22
26
  };
23
27
  export var createParseSource = /*#__PURE__*/function () {
24
28
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {