@effected/markdown 0.6.0 → 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.
- package/MarkdownDocument.js +35 -11
- package/package.json +1 -1
- package/tsdoc-metadata.json +1 -1
package/MarkdownDocument.js
CHANGED
|
@@ -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
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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