@de-otio/epimethian-mcp 4.1.0 → 4.1.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/dist/cli/index.js +33 -41
- package/dist/cli/index.js.map +2 -2
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -45365,27 +45365,29 @@ function extractHeadings(storageHtml) {
|
|
|
45365
45365
|
}
|
|
45366
45366
|
return lines.length > 0 ? lines.join("\n") : "(no headings found)";
|
|
45367
45367
|
}
|
|
45368
|
+
function findHeadingInTree(root, headingText) {
|
|
45369
|
+
const allHeadings = root.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
|
45370
|
+
for (const heading of allHeadings) {
|
|
45371
|
+
if (heading.text.trim().toLowerCase() !== headingText.toLowerCase()) continue;
|
|
45372
|
+
const tagMatch = heading.tagName.match(/^H([1-6])$/i);
|
|
45373
|
+
if (!tagMatch) continue;
|
|
45374
|
+
const parent = heading.parentNode;
|
|
45375
|
+
const siblings = parent.childNodes;
|
|
45376
|
+
const startIdx = siblings.indexOf(heading);
|
|
45377
|
+
if (startIdx === -1) continue;
|
|
45378
|
+
return { siblings, startIdx, headingLevel: parseInt(tagMatch[1], 10) };
|
|
45379
|
+
}
|
|
45380
|
+
return null;
|
|
45381
|
+
}
|
|
45368
45382
|
function extractSection(storageHtml, headingText) {
|
|
45369
45383
|
const { parse: parse3 } = require_dist2();
|
|
45370
45384
|
const root = parse3(storageHtml);
|
|
45371
|
-
const
|
|
45372
|
-
|
|
45373
|
-
|
|
45374
|
-
|
|
45375
|
-
|
|
45376
|
-
|
|
45377
|
-
const el = node;
|
|
45378
|
-
const tagMatch = el.tagName?.match(/^H([1-6])$/i);
|
|
45379
|
-
if (tagMatch && el.text.trim().toLowerCase() === headingText.toLowerCase()) {
|
|
45380
|
-
startIdx = i;
|
|
45381
|
-
headingLevel = parseInt(tagMatch[1], 10);
|
|
45382
|
-
break;
|
|
45383
|
-
}
|
|
45384
|
-
}
|
|
45385
|
-
if (startIdx === -1) return null;
|
|
45386
|
-
let endIdx = topLevelNodes.length;
|
|
45387
|
-
for (let i = startIdx + 1; i < topLevelNodes.length; i++) {
|
|
45388
|
-
const node = topLevelNodes[i];
|
|
45385
|
+
const found = findHeadingInTree(root, headingText);
|
|
45386
|
+
if (!found) return null;
|
|
45387
|
+
const { siblings, startIdx, headingLevel } = found;
|
|
45388
|
+
let endIdx = siblings.length;
|
|
45389
|
+
for (let i = startIdx + 1; i < siblings.length; i++) {
|
|
45390
|
+
const node = siblings[i];
|
|
45389
45391
|
if (node.nodeType !== 1) continue;
|
|
45390
45392
|
const el = node;
|
|
45391
45393
|
const tagMatch = el.tagName?.match(/^H([1-6])$/i);
|
|
@@ -45394,30 +45396,18 @@ function extractSection(storageHtml, headingText) {
|
|
|
45394
45396
|
break;
|
|
45395
45397
|
}
|
|
45396
45398
|
}
|
|
45397
|
-
const sectionNodes =
|
|
45399
|
+
const sectionNodes = siblings.slice(startIdx, endIdx);
|
|
45398
45400
|
return sectionNodes.map((n) => n.toString()).join("");
|
|
45399
45401
|
}
|
|
45400
45402
|
function replaceSection(storageHtml, headingText, newContent) {
|
|
45401
45403
|
const { parse: parse3 } = require_dist2();
|
|
45402
45404
|
const root = parse3(storageHtml);
|
|
45403
|
-
const
|
|
45404
|
-
|
|
45405
|
-
|
|
45406
|
-
|
|
45407
|
-
|
|
45408
|
-
|
|
45409
|
-
const el = node;
|
|
45410
|
-
const tagMatch = el.tagName?.match(/^H([1-6])$/i);
|
|
45411
|
-
if (tagMatch && el.text.trim().toLowerCase() === headingText.toLowerCase()) {
|
|
45412
|
-
startIdx = i;
|
|
45413
|
-
headingLevel = parseInt(tagMatch[1], 10);
|
|
45414
|
-
break;
|
|
45415
|
-
}
|
|
45416
|
-
}
|
|
45417
|
-
if (startIdx === -1) return null;
|
|
45418
|
-
let endIdx = topLevelNodes.length;
|
|
45419
|
-
for (let i = startIdx + 1; i < topLevelNodes.length; i++) {
|
|
45420
|
-
const node = topLevelNodes[i];
|
|
45405
|
+
const found = findHeadingInTree(root, headingText);
|
|
45406
|
+
if (!found) return null;
|
|
45407
|
+
const { siblings, startIdx, headingLevel } = found;
|
|
45408
|
+
let endIdx = siblings.length;
|
|
45409
|
+
for (let i = startIdx + 1; i < siblings.length; i++) {
|
|
45410
|
+
const node = siblings[i];
|
|
45421
45411
|
if (node.nodeType !== 1) continue;
|
|
45422
45412
|
const el = node;
|
|
45423
45413
|
const tagMatch = el.tagName?.match(/^H([1-6])$/i);
|
|
@@ -45426,10 +45416,12 @@ function replaceSection(storageHtml, headingText, newContent) {
|
|
|
45426
45416
|
break;
|
|
45427
45417
|
}
|
|
45428
45418
|
}
|
|
45429
|
-
const before =
|
|
45430
|
-
const heading =
|
|
45431
|
-
const after =
|
|
45432
|
-
|
|
45419
|
+
const before = siblings.slice(0, startIdx);
|
|
45420
|
+
const heading = siblings[startIdx];
|
|
45421
|
+
const after = siblings.slice(endIdx);
|
|
45422
|
+
const parent = heading.parentNode;
|
|
45423
|
+
parent.innerHTML = before.map((n) => n.toString()).join("") + heading.toString() + newContent + after.map((n) => n.toString()).join("");
|
|
45424
|
+
return root.toString();
|
|
45433
45425
|
}
|
|
45434
45426
|
function truncateStorageFormat(storageHtml, maxLength) {
|
|
45435
45427
|
if (storageHtml.length <= maxLength) return storageHtml;
|