@effected/markdown 0.6.0 → 0.6.2

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.
@@ -229,19 +229,43 @@ var MarkdownDocument = class MarkdownDocument extends Schema.Class("MarkdownDocu
229
229
  get sections() {
230
230
  const blocks = this.root.children;
231
231
  const sections = [];
232
+ const headings = [];
232
233
  for (let index = 0; index < blocks.length; index += 1) {
233
234
  const block = blocks[index];
234
- if (block === void 0 || block.type !== "heading") continue;
235
- let boundary = this.source.length;
236
- let end = blocks.length;
237
- for (let next = index + 1; next < blocks.length; next += 1) {
238
- const candidate = blocks[next];
239
- if (candidate !== void 0 && candidate.type === "heading" && candidate.depth <= block.depth) {
240
- boundary = candidate.position.start.offset;
241
- end = next;
242
- break;
243
- }
235
+ if (block !== void 0 && block.type === "heading") headings.push({
236
+ index,
237
+ node: block
238
+ });
239
+ }
240
+ const nextByDepth = [
241
+ void 0,
242
+ void 0,
243
+ void 0,
244
+ void 0,
245
+ void 0,
246
+ void 0,
247
+ void 0
248
+ ];
249
+ const boundaryByHeading = new Array(headings.length);
250
+ for (let index = headings.length - 1; index >= 0; index -= 1) {
251
+ const current = headings[index]?.node;
252
+ if (current === void 0) continue;
253
+ let boundary;
254
+ for (let depth = 1; depth <= current.depth; depth += 1) {
255
+ const candidate = nextByDepth[depth];
256
+ if (candidate !== void 0 && (boundary === void 0 || candidate < boundary)) boundary = candidate;
244
257
  }
258
+ boundaryByHeading[index] = boundary;
259
+ nextByDepth[current.depth] = index;
260
+ }
261
+ for (let index = 0; index < headings.length; index += 1) {
262
+ const current = headings[index];
263
+ if (current === void 0) continue;
264
+ const block = current.node;
265
+ const boundaryHeading = boundaryByHeading[index];
266
+ const boundaryNode = boundaryHeading === void 0 ? void 0 : headings[boundaryHeading]?.node;
267
+ const boundary = boundaryNode === void 0 ? this.source.length : boundaryNode.position.start.offset;
268
+ const end = boundaryHeading === void 0 ? blocks.length : headings[boundaryHeading]?.index ?? blocks.length;
245
269
  const start = block.position.start.offset;
246
270
  const bodyStart = block.position.end.offset;
247
271
  sections.push(new DocumentSection({
@@ -251,7 +275,7 @@ var MarkdownDocument = class MarkdownDocument extends Schema.Class("MarkdownDocu
251
275
  offset: start,
252
276
  length: boundary - start
253
277
  }),
254
- children: blocks.slice(index + 1, end).filter((child) => child.type !== "frontmatter"),
278
+ children: blocks.slice(current.index + 1, end).filter((child) => child.type !== "frontmatter"),
255
279
  text: phrasingText(block.children),
256
280
  bodyRange: MarkdownRange.make({
257
281
  offset: bodyStart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/markdown",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "description": "CommonMark and GFM markdown parse, edit and transform schemas for Effect",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "peerDependencies": {
42
42
  "@effected/jsonc": "^0.7.0",
43
43
  "@effected/toml": "^0.5.0",
44
- "@effected/yaml": "^0.10.0",
44
+ "@effected/yaml": "^0.11.0",
45
45
  "effect": "4.0.0-rc.109"
46
46
  },
47
47
  "peerDependenciesMeta": {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.12"
8
+ "packageVersion": "7.59.0"
9
9
  }
10
10
  ]
11
11
  }