@effected/markdown 0.5.2 → 0.6.1

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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  Zero-dependency CommonMark 0.31.2 and GFM parsing, editing and transformation expressed as Effect schemas and pure functions. Parse markdown into mdast-shaped nodes carrying byte offsets, navigate headings, sections and links, compute surgical offset-splice edits, normalize markers, decode frontmatter into a validated domain schema, project to and from plain mdast for the remark ecosystem, and walk a document as a `Stream`.
9
9
 
10
10
  > **Pre-release.** This package is part of the `@effected/*` kit, in pre-`1.0.0`
11
- > development against a single pinned Effect v4 beta. Packages graduate to
11
+ > development against a single pinned Effect v4 prerelease. Packages graduate to
12
12
  > `1.0.0` once Effect `4.0.0` ships. To hold your own `effect` versions at
13
13
  > exactly the ones the kit is built and tested against, install
14
14
  > [`@effected/pnpm-plugin-effect`](https://www.npmjs.com/package/@effected/pnpm-plugin-effect).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/markdown",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "description": "CommonMark and GFM markdown parse, edit and transform schemas for Effect",
6
6
  "keywords": [
@@ -39,10 +39,10 @@
39
39
  "./package.json": "./package.json"
40
40
  },
41
41
  "peerDependencies": {
42
- "@effected/jsonc": "^0.6.0",
43
- "@effected/toml": "^0.4.0",
44
- "@effected/yaml": "^0.9.0",
45
- "effect": "4.0.0-beta.107"
42
+ "@effected/jsonc": "^0.7.0",
43
+ "@effected/toml": "^0.5.0",
44
+ "@effected/yaml": "^0.10.0",
45
+ "effect": "4.0.0-rc.109"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@effected/jsonc": {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.12"
8
+ "packageVersion": "7.58.13"
9
9
  }
10
10
  ]
11
11
  }