token-goat 2.9.30 → 2.9.31
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/README.md +24 -7
- package/SECURITY.md +10 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/native/win32-arm64/tg-hook.exe +0 -0
- package/dist/native/win32-x64/tg-hook.exe +0 -0
- package/dist/{token-goat-chunk-QSBRTGM2.mjs → token-goat-chunk-25TRAWET.mjs} +17 -7
- package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
- package/dist/{token-goat-chunk-IVKIZWAB.mjs → token-goat-chunk-2M7E4PF7.mjs} +41 -12
- package/dist/{token-goat-chunk-SMVRN2HU.mjs → token-goat-chunk-2UPZGKKY.mjs} +2 -2
- package/dist/token-goat-chunk-2WLPWKHV.mjs +135 -0
- package/dist/token-goat-chunk-2XBMMDBD.mjs +126 -0
- package/dist/token-goat-chunk-32ZOY4N5.mjs +23 -0
- package/dist/token-goat-chunk-3EZRNKTK.mjs +188 -0
- package/dist/token-goat-chunk-4ADZHI7J.mjs +63 -0
- package/dist/token-goat-chunk-4GBVPH3D.mjs +242 -0
- package/dist/{token-goat-chunk-KWPNJBDH.mjs → token-goat-chunk-4GILLLWY.mjs} +7 -4
- package/dist/{token-goat-chunk-67TQJ76B.mjs → token-goat-chunk-4NAPX7BA.mjs} +36 -3
- package/dist/{token-goat-chunk-PU7V3FD6.mjs → token-goat-chunk-4SC7UJYV.mjs} +3354 -2553
- package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
- package/dist/{token-goat-chunk-AFLYLHDH.mjs → token-goat-chunk-4ZBFWLXF.mjs} +283 -427
- package/dist/{token-goat-chunk-JDWCRD6M.mjs → token-goat-chunk-57BIAXJL.mjs} +73 -40
- package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
- package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
- package/dist/token-goat-chunk-646E6U44.mjs +398 -0
- package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
- package/dist/{token-goat-chunk-JN4XMLSD.mjs → token-goat-chunk-6DG6HWP3.mjs} +8 -2
- package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
- package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
- package/dist/{token-goat-chunk-VPBBTSJR.mjs → token-goat-chunk-76FGDLRO.mjs} +262 -255
- package/dist/{token-goat-chunk-7IN2MKDS.mjs → token-goat-chunk-7EZTZOMC.mjs} +121 -289
- package/dist/{token-goat-chunk-OJBNYTJP.mjs → token-goat-chunk-7MAOA6X4.mjs} +640 -80
- package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
- package/dist/{token-goat-chunk-PD5VKH46.mjs → token-goat-chunk-AUNGYYQX.mjs} +2 -2
- package/dist/{token-goat-chunk-HG45AF2B.mjs → token-goat-chunk-AUQYRMMH.mjs} +794 -37
- package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
- package/dist/{token-goat-chunk-A3CK6N5Z.mjs → token-goat-chunk-BA4HI6BW.mjs} +1309 -110
- package/dist/{token-goat-chunk-JB6QN6VF.mjs → token-goat-chunk-BFCWY73P.mjs} +59 -23
- package/dist/{token-goat-chunk-B45VMIIH.mjs → token-goat-chunk-BWGFUZZE.mjs} +7 -5
- package/dist/{token-goat-chunk-P4QMM4WK.mjs → token-goat-chunk-C75NA7PL.mjs} +50 -23
- package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
- package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
- package/dist/{token-goat-chunk-H2PHHGM5.mjs → token-goat-chunk-CIMQ2BB3.mjs} +57 -12
- package/dist/{token-goat-chunk-N2NMER56.mjs → token-goat-chunk-CJLS3CDL.mjs} +46 -4
- package/dist/{token-goat-chunk-VES7EL7O.mjs → token-goat-chunk-CO3UYX6G.mjs} +1 -1
- package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
- package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
- package/dist/{token-goat-chunk-4LCCNRTG.mjs → token-goat-chunk-CVCEVUGK.mjs} +8 -6
- package/dist/{token-goat-chunk-B2RZZCSS.mjs → token-goat-chunk-CXHOFN7R.mjs} +37 -20
- package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
- package/dist/{token-goat-chunk-APGZXSPS.mjs → token-goat-chunk-DGS2LVNA.mjs} +47 -30
- package/dist/{token-goat-chunk-54K3EUV3.mjs → token-goat-chunk-DOWRSMWO.mjs} +1 -1
- package/dist/token-goat-chunk-E45INMY3.mjs +71 -0
- package/dist/token-goat-chunk-EC5F37F4.mjs +244 -0
- package/dist/{token-goat-chunk-XTQAOTSO.mjs → token-goat-chunk-EDBDRVH5.mjs} +4 -1
- package/dist/{token-goat-chunk-5BCIJXMO.mjs → token-goat-chunk-EELTBKDM.mjs} +14 -10
- package/dist/{token-goat-chunk-W3QCJS6G.mjs → token-goat-chunk-F4HYL64R.mjs} +8 -6
- package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
- package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
- package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
- package/dist/{token-goat-chunk-C63JQV5K.mjs → token-goat-chunk-GL3ETKSC.mjs} +233 -15
- package/dist/token-goat-chunk-GVB2MUST.mjs +1298 -0
- package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
- package/dist/{token-goat-chunk-ZEJVMUQH.mjs → token-goat-chunk-HLPW63A7.mjs} +2 -2
- package/dist/{token-goat-chunk-GOLEOXZP.mjs → token-goat-chunk-HU4TORC5.mjs} +44 -26
- package/dist/{token-goat-chunk-Z57YODA2.mjs → token-goat-chunk-I7VKZZAW.mjs} +2 -2
- package/dist/{token-goat-chunk-NYKZLXMK.mjs → token-goat-chunk-IA6XSPE3.mjs} +6 -6
- package/dist/{token-goat-chunk-E3OQX2XT.mjs → token-goat-chunk-IAGXMHIK.mjs} +81 -42
- package/dist/{token-goat-chunk-HYBFA5X3.mjs → token-goat-chunk-IK2DRMFX.mjs} +24 -68
- package/dist/{token-goat-chunk-COBQGL5S.mjs → token-goat-chunk-INNPTRUX.mjs} +249 -299
- package/dist/{token-goat-chunk-7NADEDKJ.mjs → token-goat-chunk-JJ5BX4F4.mjs} +6 -1
- package/dist/{token-goat-chunk-PEPTHRFF.mjs → token-goat-chunk-JVFSHVFJ.mjs} +6 -6
- package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
- package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
- package/dist/{token-goat-chunk-Q5VTGRH7.mjs → token-goat-chunk-LCNQ2CNN.mjs} +55 -319
- package/dist/token-goat-chunk-M3LFJDPU.mjs +58 -0
- package/dist/token-goat-chunk-M52KPT3C.mjs +87 -0
- package/dist/token-goat-chunk-MBEG42H7.mjs +150 -0
- package/dist/{token-goat-chunk-EVC4TOLE.mjs → token-goat-chunk-METECDOH.mjs} +3 -12
- package/dist/{token-goat-chunk-T4FK7VOV.mjs → token-goat-chunk-MHX7XCC3.mjs} +2 -1
- package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
- package/dist/{token-goat-chunk-LOBGHXPB.mjs → token-goat-chunk-N5MMR2IW.mjs} +1 -1
- package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
- package/dist/{token-goat-chunk-RHXKCZX3.mjs → token-goat-chunk-NISNMD7T.mjs} +2182 -2959
- package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
- package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
- package/dist/{token-goat-chunk-KQNZDCBD.mjs → token-goat-chunk-NSNSPPBG.mjs} +25 -3
- package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
- package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
- package/dist/{token-goat-chunk-JTQQGXZH.mjs → token-goat-chunk-ODBT2USM.mjs} +124 -57
- package/dist/token-goat-chunk-OS5EM5PP.mjs +107 -0
- package/dist/token-goat-chunk-OUKDTVNU.mjs +1178 -0
- package/dist/token-goat-chunk-OXFMP75N.mjs +566 -0
- package/dist/{token-goat-chunk-DZX2YDPT.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -2
- package/dist/{token-goat-chunk-QCLDAQTS.mjs → token-goat-chunk-P6HQSWQ3.mjs} +50 -53
- package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
- package/dist/{token-goat-chunk-7BXSNBY5.mjs → token-goat-chunk-PFWIMH2E.mjs} +23 -15
- package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
- package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
- package/dist/{token-goat-chunk-GFBSN7BD.mjs → token-goat-chunk-PX5PQWTY.mjs} +22 -250
- package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
- package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
- package/dist/{token-goat-chunk-FBNQNSJK.mjs → token-goat-chunk-QH7YVYOY.mjs} +2198 -2782
- package/dist/{token-goat-chunk-64FBPDTK.mjs → token-goat-chunk-QLMUHEPB.mjs} +12 -9
- package/dist/{token-goat-chunk-RZRTDST7.mjs → token-goat-chunk-QQOJIHL3.mjs} +37 -11
- package/dist/{token-goat-chunk-XKI4SEMX.mjs → token-goat-chunk-QQTWJY2O.mjs} +19 -0
- package/dist/{token-goat-chunk-U4N3BN2W.mjs → token-goat-chunk-QYHO5CPH.mjs} +3 -2
- package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
- package/dist/{token-goat-chunk-ETBHVDB6.mjs → token-goat-chunk-RSLPOBKQ.mjs} +22 -11
- package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
- package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
- package/dist/{token-goat-chunk-4JJS54TR.mjs → token-goat-chunk-SOAFZNNZ.mjs} +161 -38
- package/dist/{token-goat-chunk-664RTTUV.mjs → token-goat-chunk-SRTHT7KV.mjs} +21 -16
- package/dist/{token-goat-chunk-4FVIAHSI.mjs → token-goat-chunk-T5P5ACNQ.mjs} +7 -6
- package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
- package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
- package/dist/{token-goat-chunk-COTXZHTS.mjs → token-goat-chunk-TM6MC754.mjs} +4 -3
- package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
- package/dist/{token-goat-chunk-3CHUNJ2O.mjs → token-goat-chunk-U2KSB4SG.mjs} +8 -5
- package/dist/{token-goat-chunk-3Z5S4KGM.mjs → token-goat-chunk-U4WHMG6Y.mjs} +29 -49
- package/dist/{token-goat-chunk-PY533T7F.mjs → token-goat-chunk-UGJHGR5A.mjs} +21 -15
- package/dist/{token-goat-chunk-CYCEYAEO.mjs → token-goat-chunk-UOUDVA5U.mjs} +1 -1
- package/dist/{token-goat-chunk-JDHE26RP.mjs → token-goat-chunk-URRJ33GR.mjs} +16 -5
- package/dist/{token-goat-chunk-56EIMS3E.mjs → token-goat-chunk-UZOROKIS.mjs} +23 -17
- package/dist/{token-goat-chunk-CZ3LUXYZ.mjs → token-goat-chunk-VIHGGGEI.mjs} +427 -308
- package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
- package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
- package/dist/{token-goat-chunk-YARZFCZS.mjs → token-goat-chunk-VWZA2H4P.mjs} +62 -53
- package/dist/{token-goat-chunk-SQSSNQPE.mjs → token-goat-chunk-VXEXMJDL.mjs} +3979 -4745
- package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
- package/dist/{token-goat-chunk-SJHWVNDQ.mjs → token-goat-chunk-WDH44VAU.mjs} +7 -4
- package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
- package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
- package/dist/{token-goat-chunk-FZ3NEW5O.mjs → token-goat-chunk-XLRBNZCC.mjs} +13 -8
- package/dist/{token-goat-chunk-Z44YO3QZ.mjs → token-goat-chunk-XRKUX6CM.mjs} +1 -1
- package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
- package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
- package/dist/{token-goat-chunk-WY3L4DVT.mjs → token-goat-chunk-Y2ZTQOCL.mjs} +13 -8
- package/dist/{token-goat-chunk-UQ5UK2T7.mjs → token-goat-chunk-YB4VMGK2.mjs} +1 -1
- package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
- package/dist/{token-goat-chunk-ZQSJMO2R.mjs → token-goat-chunk-YHVDKQBR.mjs} +105 -105
- package/dist/{token-goat-chunk-H2K3QP6H.mjs → token-goat-chunk-YJB5XLWI.mjs} +8 -6
- package/dist/{token-goat-chunk-ZCDTCVIS.mjs → token-goat-chunk-YKB6AQG3.mjs} +5 -2
- package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
- package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
- package/dist/{token-goat-chunk-HOJLCGDP.mjs → token-goat-chunk-YY6AVUFL.mjs} +2033 -2251
- package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
- package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
- package/dist/token-goat-hook-client.cjs +1 -1
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +67 -38
- package/dist/token-goat.core.mjs +4 -4
- package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
- package/docs/cli.md +40 -21
- package/docs/install.md +19 -9
- package/docs/security.md +5 -3
- package/package.json +2 -1
- package/dist/token-goat-chunk-5KDMCMF2.mjs +0 -362
- package/dist/token-goat-chunk-6QMAS7AB.mjs +0 -42
- package/dist/token-goat-chunk-7F2UBPD3.mjs +0 -397
- package/dist/token-goat-chunk-ARDNEC2U.mjs +0 -248
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +0 -134
- package/dist/token-goat-chunk-EFHMMIGP.mjs +0 -68
- package/dist/token-goat-chunk-IVALLT3S.mjs +0 -48
- package/dist/token-goat-chunk-JDU3EXSU.mjs +0 -65
- package/dist/token-goat-chunk-MKPF4CL5.mjs +0 -37
- package/dist/token-goat-chunk-RC35RBUL.mjs +0 -312
- package/dist/token-goat-chunk-USILZ3T3.mjs +0 -53
- package/dist/token-goat-chunk-VL3YIFHZ.mjs +0 -2975
- package/dist/token-goat-chunk-XU4P6Z24.mjs +0 -133
- package/dist/token-goat-chunk-Y776AENC.mjs +0 -1597
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
eachUnfencedLine,
|
|
5
|
+
frontMatterEndIndex,
|
|
6
|
+
lineOpenDelimiterAfter,
|
|
7
|
+
stripTomlComment,
|
|
8
|
+
tomlBracketDelta,
|
|
9
|
+
yamlLineClosesQuote,
|
|
10
|
+
yamlOpenQuoteAfter
|
|
11
|
+
} from "./token-goat-chunk-NISNMD7T.mjs";
|
|
12
|
+
import {
|
|
13
|
+
ATX_CLASS_BREAK_RE,
|
|
14
|
+
matchAtxHeading,
|
|
15
|
+
matchRuleBannerTitle,
|
|
16
|
+
matchTableHeaderName
|
|
17
|
+
} from "./token-goat-chunk-EVMZJ27Z.mjs";
|
|
18
|
+
import {
|
|
19
|
+
_detectOpenQuote,
|
|
20
|
+
_lineClosesQuote,
|
|
21
|
+
detectLanguage,
|
|
22
|
+
redactIfDotenv,
|
|
23
|
+
refineLanguageByContent
|
|
24
|
+
} from "./token-goat-chunk-GVB2MUST.mjs";
|
|
25
|
+
import {
|
|
26
|
+
buildLineIndex,
|
|
27
|
+
findHtmlHeadingMatches,
|
|
28
|
+
offsetToLine
|
|
29
|
+
} from "./token-goat-chunk-OUKDTVNU.mjs";
|
|
30
|
+
import {
|
|
31
|
+
decodeSource
|
|
32
|
+
} from "./token-goat-chunk-HU4TORC5.mjs";
|
|
33
|
+
import {
|
|
34
|
+
init_define_import_meta_env
|
|
35
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
36
|
+
|
|
37
|
+
// src/section_reader.ts
|
|
38
|
+
init_define_import_meta_env();
|
|
39
|
+
import { readFileSync } from "node:fs";
|
|
40
|
+
function parseHeadingSpec(spec, headers) {
|
|
41
|
+
const m = /^([^#\r\n]+)#(\d+)$/.exec(spec);
|
|
42
|
+
if (m !== null && m[1] !== void 0 && m[2] !== void 0) {
|
|
43
|
+
const specLower = spec.trim().toLowerCase();
|
|
44
|
+
const isLiteralHeading = headers?.some((h) => h.heading.trim().toLowerCase() === specLower) ?? false;
|
|
45
|
+
if (isLiteralHeading) {
|
|
46
|
+
return { base: spec.trim(), ordinal: null };
|
|
47
|
+
}
|
|
48
|
+
return { base: m[1].trim(), ordinal: Number.parseInt(m[2], 10) };
|
|
49
|
+
}
|
|
50
|
+
return { base: spec.trim(), ordinal: null };
|
|
51
|
+
}
|
|
52
|
+
function normalizeHeading(s) {
|
|
53
|
+
let n = s.replace(/[—–]/g, "-");
|
|
54
|
+
n = n.replace(/\s*\([^)]+\)\s*$/, "");
|
|
55
|
+
n = n.replace(/^\d+\.\s+/, "");
|
|
56
|
+
return n.replace(/\s+/g, " ").trim();
|
|
57
|
+
}
|
|
58
|
+
function normalizeHeadingStrip(s) {
|
|
59
|
+
let n = s.replace(/\s*[—–].*$/, "");
|
|
60
|
+
n = n.replace(/\s*\([^)]+\)\s*$/, "");
|
|
61
|
+
n = n.replace(/^\d+\.\s+/, "");
|
|
62
|
+
return n.replace(/\s+/g, " ").trim();
|
|
63
|
+
}
|
|
64
|
+
var MIN_WIDEN_WORD_LEN = 3;
|
|
65
|
+
var PYTHON_HEADER_RE = /^(\s*)(?:async\s+)?(?:def|class)\s+([A-Za-z_]\w*)/;
|
|
66
|
+
var KEYVALUE_HEADER_RE = /^([A-Za-z_][\w.-]*)\s*(?:=|:(?!\/\/))/;
|
|
67
|
+
var ENV_KEYVALUE_HEADER_RE = /^(?:export\s+)?([A-Za-z_][\w.-]*)\s*(?:=|:(?!\/\/))/;
|
|
68
|
+
function findMarkdownHeaders(lines) {
|
|
69
|
+
const headers = [];
|
|
70
|
+
const fmEnd = frontMatterEndIndex(lines);
|
|
71
|
+
const unfenced = Array.from(eachUnfencedLine(lines)).filter(([i]) => i >= fmEnd);
|
|
72
|
+
let paraStart = -1;
|
|
73
|
+
for (let u = 0; u < unfenced.length; u++) {
|
|
74
|
+
const [i, line] = unfenced[u];
|
|
75
|
+
const atx = matchAtxHeading(line, ATX_CLASS_BREAK_RE, true);
|
|
76
|
+
if (atx !== null) {
|
|
77
|
+
headers.push({ heading: atx.name, level: atx.level, index: i });
|
|
78
|
+
paraStart = -1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (paraStart !== -1 && i !== unfenced[u - 1][0] + 1) paraStart = -1;
|
|
82
|
+
const trimmed = line.trim();
|
|
83
|
+
if (paraStart !== -1 && /^(=+|-+)$/.test(trimmed)) {
|
|
84
|
+
const heading = unfenced.slice(paraStart, u).map(([, text]) => text.trim()).join(" ");
|
|
85
|
+
headers.push({ heading, level: trimmed.startsWith("=") ? 1 : 2, index: unfenced[paraStart][0] });
|
|
86
|
+
paraStart = -1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const isText = trimmed !== "" && !trimmed.startsWith("#") && !trimmed.startsWith("|") && !trimmed.startsWith("```") && !trimmed.startsWith("~~~") && !/^([-*+]|\d+\.)\s/.test(trimmed) && !/^(=+|-+)$/.test(trimmed);
|
|
90
|
+
if (!isText) paraStart = -1;
|
|
91
|
+
else if (paraStart === -1) paraStart = u;
|
|
92
|
+
}
|
|
93
|
+
return headers;
|
|
94
|
+
}
|
|
95
|
+
function findTableHeaders(lines, isToml) {
|
|
96
|
+
const headers = [];
|
|
97
|
+
let openDelim = null;
|
|
98
|
+
let arrayDepth = 0;
|
|
99
|
+
for (let i = 0; i < lines.length; i++) {
|
|
100
|
+
const line = lines[i];
|
|
101
|
+
if (line === void 0) continue;
|
|
102
|
+
if (openDelim !== null) {
|
|
103
|
+
const closeIdx = line.indexOf(openDelim);
|
|
104
|
+
if (closeIdx === -1) continue;
|
|
105
|
+
const restStart = closeIdx + openDelim.length;
|
|
106
|
+
const name2 = matchTableHeaderName(line.slice(restStart));
|
|
107
|
+
if (name2 !== null) headers.push({ heading: name2.trim(), level: 1, index: i });
|
|
108
|
+
openDelim = lineOpenDelimiterAfter(stripTomlComment(line.slice(restStart)), 0);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (isToml && arrayDepth > 0) {
|
|
112
|
+
arrayDepth = Math.max(0, arrayDepth + tomlBracketDelta(stripTomlComment(line)));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const name = matchTableHeaderName(line);
|
|
116
|
+
if (name !== null) headers.push({ heading: name.trim(), level: 1, index: i });
|
|
117
|
+
if (isToml) {
|
|
118
|
+
const code = stripTomlComment(line);
|
|
119
|
+
openDelim = lineOpenDelimiterAfter(code, 0);
|
|
120
|
+
if (openDelim === null) arrayDepth = Math.max(0, tomlBracketDelta(code));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return headers;
|
|
124
|
+
}
|
|
125
|
+
var VB_REGION_RE = /^\s*#\s*Region\s+"((?:[^"]|"")*)"/i;
|
|
126
|
+
var VB_END_REGION_RE = /^\s*#\s*End\s+Region\b/i;
|
|
127
|
+
function extractShellBannerHeading(line) {
|
|
128
|
+
const trimmed = line.trim();
|
|
129
|
+
if (!trimmed.startsWith("#")) return null;
|
|
130
|
+
if (trimmed.startsWith("#!")) return null;
|
|
131
|
+
const mdMatch = /^(#{2,6})[^\S\r\n]+(\S(?:.*?\S)?)(?:[^\S\r\n]+#+)?$/.exec(trimmed);
|
|
132
|
+
if (mdMatch && mdMatch[1] && mdMatch[2]) {
|
|
133
|
+
const text = mdMatch[2].trim();
|
|
134
|
+
if (text && !/^[-=]+$/.test(text)) {
|
|
135
|
+
return { heading: text, level: mdMatch[1].length };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const ruleTitle = matchRuleBannerTitle(trimmed);
|
|
139
|
+
if (ruleTitle) {
|
|
140
|
+
const text = ruleTitle.trim();
|
|
141
|
+
if (text && !/^[-=]+$/.test(text)) {
|
|
142
|
+
return { heading: text, level: 1 };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const bracketMatch = /^#\s*\[([a-zA-Z0-9_.\-\s]+)\]$/.exec(trimmed);
|
|
146
|
+
if (bracketMatch && bracketMatch[1]) {
|
|
147
|
+
const text = bracketMatch[1].trim();
|
|
148
|
+
if (text) {
|
|
149
|
+
return { heading: text, level: 1 };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const regionMatch = /^#\s*(?:REGION|SECTION):\s*(\S.*)$/i.exec(trimmed);
|
|
153
|
+
if (regionMatch && regionMatch[1]) {
|
|
154
|
+
const text = regionMatch[1].trim();
|
|
155
|
+
if (text) {
|
|
156
|
+
return { heading: text, level: 1 };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
function findShellBannerHeaders(lines) {
|
|
162
|
+
const headers = [];
|
|
163
|
+
for (let i = 0; i < lines.length; i++) {
|
|
164
|
+
const line = lines[i] ?? "";
|
|
165
|
+
const banner = extractShellBannerHeading(line);
|
|
166
|
+
if (banner !== null) {
|
|
167
|
+
headers.push({ heading: banner.heading, level: banner.level, index: i });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return headers;
|
|
171
|
+
}
|
|
172
|
+
function findVbRegionHeaders(lines) {
|
|
173
|
+
const headers = [];
|
|
174
|
+
const open = [];
|
|
175
|
+
for (let i = 0; i < lines.length; i++) {
|
|
176
|
+
const line = lines[i] ?? "";
|
|
177
|
+
const m = VB_REGION_RE.exec(line);
|
|
178
|
+
if (m !== null) {
|
|
179
|
+
open.push(headers.length);
|
|
180
|
+
headers.push({ heading: (m[1] ?? "").replace(/""/g, '"'), level: open.length, index: i });
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (VB_END_REGION_RE.test(line)) {
|
|
184
|
+
const pos = open.pop();
|
|
185
|
+
const h = pos === void 0 ? void 0 : headers[pos];
|
|
186
|
+
if (pos !== void 0 && h !== void 0) headers[pos] = { ...h, endIndex: i + 1 };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return headers;
|
|
190
|
+
}
|
|
191
|
+
function headerEndIndex(headers, kind, headerPos, totalLines) {
|
|
192
|
+
const explicit = headers[headerPos]?.endIndex;
|
|
193
|
+
if (explicit !== void 0) return explicit;
|
|
194
|
+
return kind === "table-toml" ? tableSectionEndIndex(headers, headerPos, totalLines) : sectionEndIndex(headers, headerPos, totalLines);
|
|
195
|
+
}
|
|
196
|
+
function findPythonHeaders(lines) {
|
|
197
|
+
const headers = [];
|
|
198
|
+
const indentStack = [];
|
|
199
|
+
let openDelim = null;
|
|
200
|
+
for (let i = 0; i < lines.length; i++) {
|
|
201
|
+
const line = lines[i];
|
|
202
|
+
if (line === void 0) continue;
|
|
203
|
+
if (openDelim !== null) {
|
|
204
|
+
const closeIdx = line.indexOf(openDelim);
|
|
205
|
+
if (closeIdx === -1) continue;
|
|
206
|
+
openDelim = lineOpenDelimiterAfter(line, closeIdx + openDelim.length);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const m = PYTHON_HEADER_RE.exec(line);
|
|
210
|
+
if (m === null || m[1] === void 0 || m[2] === void 0) {
|
|
211
|
+
openDelim = lineOpenDelimiterAfter(line, 0);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const indent = m[1].replace(/\t/g, " ").length;
|
|
215
|
+
while (indentStack.length > 0 && indent <= (indentStack[indentStack.length - 1] ?? -1)) {
|
|
216
|
+
indentStack.pop();
|
|
217
|
+
}
|
|
218
|
+
const level = indentStack.length + 1;
|
|
219
|
+
indentStack.push(indent);
|
|
220
|
+
headers.push({ heading: m[2], level, index: i });
|
|
221
|
+
openDelim = lineOpenDelimiterAfter(line, 0);
|
|
222
|
+
}
|
|
223
|
+
return headers;
|
|
224
|
+
}
|
|
225
|
+
function findKeyValueHeaders(lines, language) {
|
|
226
|
+
const headers = [];
|
|
227
|
+
const isEnv = language === "env_file";
|
|
228
|
+
let openQuote = null;
|
|
229
|
+
for (let i = 0; i < lines.length; i++) {
|
|
230
|
+
const line = lines[i];
|
|
231
|
+
if (line === void 0) continue;
|
|
232
|
+
if (openQuote !== null) {
|
|
233
|
+
const closed = isEnv ? _lineClosesQuote(line, openQuote) : yamlLineClosesQuote(line, openQuote);
|
|
234
|
+
if (closed) openQuote = null;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const scanned = isEnv ? line.replace(/^[ \t]+/, "") : line;
|
|
238
|
+
const m = (isEnv ? ENV_KEYVALUE_HEADER_RE : KEYVALUE_HEADER_RE).exec(scanned);
|
|
239
|
+
if (m === null || m[1] === void 0) continue;
|
|
240
|
+
headers.push({ heading: m[1], level: 1, index: i });
|
|
241
|
+
openQuote = isEnv ? _detectOpenQuote(scanned.slice(m[0].length)) : yamlOpenQuoteAfter(line, m[0].length);
|
|
242
|
+
}
|
|
243
|
+
return headers;
|
|
244
|
+
}
|
|
245
|
+
function findHtmlHeaders(text) {
|
|
246
|
+
const lineIndex = buildLineIndex(text);
|
|
247
|
+
const headers = [];
|
|
248
|
+
for (const hm of findHtmlHeadingMatches(text)) {
|
|
249
|
+
if (!hm.heading) continue;
|
|
250
|
+
const index = offsetToLine(lineIndex, hm.offset) - 1;
|
|
251
|
+
headers.push({ heading: hm.heading, level: hm.level, index });
|
|
252
|
+
}
|
|
253
|
+
return headers;
|
|
254
|
+
}
|
|
255
|
+
function findHeaders(text, language) {
|
|
256
|
+
const lines = text.split("\n");
|
|
257
|
+
if (language === "markdown") return { headers: findMarkdownHeaders(lines), kind: "markdown" };
|
|
258
|
+
if (language === "html" || language === "liquid") return { headers: findHtmlHeaders(text), kind: "markdown" };
|
|
259
|
+
if (language === "toml") return { headers: findTableHeaders(lines, true), kind: "table-toml" };
|
|
260
|
+
if (language === "python") return { headers: findPythonHeaders(lines), kind: "python" };
|
|
261
|
+
if (language === "bash") {
|
|
262
|
+
const banners = findShellBannerHeaders(lines);
|
|
263
|
+
if (banners.length > 0) return { headers: banners, kind: "banner" };
|
|
264
|
+
}
|
|
265
|
+
if (language === "vb") return { headers: findVbRegionHeaders(lines), kind: "region" };
|
|
266
|
+
if (language === "ini") return { headers: findTableHeaders(lines, false), kind: "table-flat" };
|
|
267
|
+
if (language === "yaml" || language === "env_file")
|
|
268
|
+
return { headers: findKeyValueHeaders(lines, language), kind: "keyvalue" };
|
|
269
|
+
const md = findMarkdownHeaders(lines);
|
|
270
|
+
if (md.length > 0) return { headers: md, kind: "markdown" };
|
|
271
|
+
const tbl = findTableHeaders(lines, false);
|
|
272
|
+
if (tbl.length > 0) return { headers: tbl, kind: "table-toml" };
|
|
273
|
+
return { headers: findKeyValueHeaders(lines, language), kind: "keyvalue" };
|
|
274
|
+
}
|
|
275
|
+
function sectionEndIndex(headers, headerPos, totalLines) {
|
|
276
|
+
const current = headers[headerPos];
|
|
277
|
+
if (current === void 0) return totalLines;
|
|
278
|
+
for (let j = headerPos + 1; j < headers.length; j++) {
|
|
279
|
+
const next = headers[j];
|
|
280
|
+
if (next === void 0) continue;
|
|
281
|
+
if (next.level <= current.level) return next.index;
|
|
282
|
+
}
|
|
283
|
+
return totalLines;
|
|
284
|
+
}
|
|
285
|
+
function tableSectionEndIndex(headers, headerPos, totalLines) {
|
|
286
|
+
const current = headers[headerPos];
|
|
287
|
+
if (current === void 0) return totalLines;
|
|
288
|
+
const prefix = current.heading + ".";
|
|
289
|
+
for (let j = headerPos + 1; j < headers.length; j++) {
|
|
290
|
+
const next = headers[j];
|
|
291
|
+
if (next === void 0) continue;
|
|
292
|
+
if (next.heading.startsWith(prefix)) continue;
|
|
293
|
+
return next.index;
|
|
294
|
+
}
|
|
295
|
+
return totalLines;
|
|
296
|
+
}
|
|
297
|
+
function resolveHeaderPos(headers, base, ordinal, allowFuzzy = true) {
|
|
298
|
+
const target = base.toLowerCase();
|
|
299
|
+
const normalizedTarget = normalizeHeading(base).toLowerCase();
|
|
300
|
+
const strippedTarget = normalizeHeadingStrip(base).toLowerCase();
|
|
301
|
+
const exactMatches = [];
|
|
302
|
+
const normalizedMatches = [];
|
|
303
|
+
const strippedMatches = [];
|
|
304
|
+
for (let i = 0; i < headers.length; i++) {
|
|
305
|
+
const h = headers[i];
|
|
306
|
+
if (h === void 0) continue;
|
|
307
|
+
const headingLower = h.heading.toLowerCase();
|
|
308
|
+
if (headingLower === target) {
|
|
309
|
+
exactMatches.push(i);
|
|
310
|
+
} else if (normalizeHeading(h.heading).toLowerCase() === normalizedTarget) {
|
|
311
|
+
normalizedMatches.push(i);
|
|
312
|
+
} else if (normalizeHeadingStrip(h.heading).toLowerCase() === strippedTarget) {
|
|
313
|
+
strippedMatches.push(i);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const matches = exactMatches.length > 0 ? exactMatches : normalizedMatches.length > 0 ? normalizedMatches : strippedMatches;
|
|
317
|
+
if (matches.length > 0) {
|
|
318
|
+
const pick = ordinal === null ? 0 : ordinal - 1;
|
|
319
|
+
const headerPos = matches[pick];
|
|
320
|
+
if (headerPos === void 0) return null;
|
|
321
|
+
let occurrences = null;
|
|
322
|
+
if (ordinal === null && matches.length > 1) {
|
|
323
|
+
occurrences = [];
|
|
324
|
+
for (const i of matches) {
|
|
325
|
+
const h = headers[i];
|
|
326
|
+
if (h !== void 0) occurrences.push(h.index + 1);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return { headerPos, redirectedFrom: null, occurrences };
|
|
330
|
+
}
|
|
331
|
+
if (ordinal !== null || normalizedTarget.length === 0) return null;
|
|
332
|
+
let prefixPos = -1;
|
|
333
|
+
const distinct = /* @__PURE__ */ new Set();
|
|
334
|
+
for (let i = 0; i < headers.length; i++) {
|
|
335
|
+
const h = headers[i];
|
|
336
|
+
if (h === void 0) continue;
|
|
337
|
+
const norm = normalizeHeading(h.heading).toLowerCase();
|
|
338
|
+
if (norm.startsWith(normalizedTarget)) {
|
|
339
|
+
distinct.add(norm);
|
|
340
|
+
if (prefixPos === -1) prefixPos = i;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (distinct.size === 1 && prefixPos !== -1) {
|
|
344
|
+
const chosen = headers[prefixPos];
|
|
345
|
+
if (chosen === void 0) return null;
|
|
346
|
+
return { headerPos: prefixPos, redirectedFrom: base, occurrences: null };
|
|
347
|
+
}
|
|
348
|
+
const queryWords = normalizedTarget.split(/\s+/).filter((w) => w.length >= MIN_WIDEN_WORD_LEN);
|
|
349
|
+
if (queryWords.length === 0) return null;
|
|
350
|
+
const widenedMatches = [];
|
|
351
|
+
for (let i = 0; i < headers.length; i++) {
|
|
352
|
+
const h = headers[i];
|
|
353
|
+
if (h === void 0) continue;
|
|
354
|
+
const headingWords = normalizeHeading(h.heading).toLowerCase().split(/\s+/);
|
|
355
|
+
const allWordsMatch = queryWords.every((qw) => headingWords.some((hw) => hw.includes(qw)));
|
|
356
|
+
if (allWordsMatch) widenedMatches.push(i);
|
|
357
|
+
}
|
|
358
|
+
if (widenedMatches.length === 1) {
|
|
359
|
+
const widenedPos = widenedMatches[0];
|
|
360
|
+
if (widenedPos !== void 0) {
|
|
361
|
+
return { headerPos: widenedPos, redirectedFrom: base, occurrences: null };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function sectionLevenshtein(a, b) {
|
|
365
|
+
if (a === b) return 0;
|
|
366
|
+
const la = a.length;
|
|
367
|
+
const lb = b.length;
|
|
368
|
+
if (la === 0) return lb;
|
|
369
|
+
if (lb === 0) return la;
|
|
370
|
+
const v0 = new Array(lb + 1);
|
|
371
|
+
const v1 = new Array(lb + 1);
|
|
372
|
+
for (let i = 0; i <= lb; i++) v0[i] = i;
|
|
373
|
+
for (let i = 0; i < la; i++) {
|
|
374
|
+
v1[0] = i + 1;
|
|
375
|
+
for (let j = 0; j < lb; j++) {
|
|
376
|
+
const cost = a.charCodeAt(i) === b.charCodeAt(j) ? 0 : 1;
|
|
377
|
+
v1[j + 1] = Math.min(v1[j] + 1, v0[j + 1] + 1, v0[j] + cost);
|
|
378
|
+
}
|
|
379
|
+
for (let j = 0; j <= lb; j++) v0[j] = v1[j];
|
|
380
|
+
}
|
|
381
|
+
return v0[lb];
|
|
382
|
+
}
|
|
383
|
+
const STOP_WORDS = /* @__PURE__ */ new Set(["a", "an", "the", "and", "or", "in", "on", "at", "to", "for", "of", "with", "by", "is", "&"]);
|
|
384
|
+
const cleanTokens = (str) => str.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length > 0);
|
|
385
|
+
const rawQTokens = cleanTokens(base);
|
|
386
|
+
const qTokens = rawQTokens.filter((t) => !STOP_WORDS.has(t) || rawQTokens.length <= 2);
|
|
387
|
+
if (allowFuzzy && qTokens.length > 0) {
|
|
388
|
+
const candidates = [];
|
|
389
|
+
for (let i = 0; i < headers.length; i++) {
|
|
390
|
+
const h = headers[i];
|
|
391
|
+
if (h === void 0) continue;
|
|
392
|
+
const rawHTokens = cleanTokens(h.heading);
|
|
393
|
+
const hTokens = rawHTokens.filter((t) => !STOP_WORDS.has(t) || rawHTokens.length <= 2);
|
|
394
|
+
if (hTokens.length === 0) continue;
|
|
395
|
+
const normH = normalizeHeading(h.heading).toLowerCase();
|
|
396
|
+
const maxLen = Math.max(normalizedTarget.length, normH.length);
|
|
397
|
+
const editDist = sectionLevenshtein(normalizedTarget, normH);
|
|
398
|
+
const strSim = maxLen > 0 ? 1 - editDist / maxLen : 0;
|
|
399
|
+
let matchedQ = 0;
|
|
400
|
+
for (const qw of qTokens) {
|
|
401
|
+
let best = 0;
|
|
402
|
+
for (const hw of hTokens) {
|
|
403
|
+
if (qw === hw) {
|
|
404
|
+
best = 1;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
if (qw.length >= 3 && hw.length >= 3) {
|
|
408
|
+
if (hw.startsWith(qw) || qw.startsWith(hw)) {
|
|
409
|
+
best = Math.max(best, 0.9);
|
|
410
|
+
} else if (sectionLevenshtein(qw, hw) <= 1) {
|
|
411
|
+
best = Math.max(best, 0.85);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
matchedQ += best;
|
|
416
|
+
}
|
|
417
|
+
let matchedH = 0;
|
|
418
|
+
for (const hw of hTokens) {
|
|
419
|
+
let best = 0;
|
|
420
|
+
for (const qw of qTokens) {
|
|
421
|
+
if (qw === hw) {
|
|
422
|
+
best = 1;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
if (qw.length >= 3 && hw.length >= 3) {
|
|
426
|
+
if (hw.startsWith(qw) || qw.startsWith(hw)) {
|
|
427
|
+
best = Math.max(best, 0.9);
|
|
428
|
+
} else if (sectionLevenshtein(qw, hw) <= 1) {
|
|
429
|
+
best = Math.max(best, 0.85);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
matchedH += best;
|
|
434
|
+
}
|
|
435
|
+
const wordRecall = matchedQ / qTokens.length;
|
|
436
|
+
const wordPrecision = matchedH / hTokens.length;
|
|
437
|
+
const tokenDice = 2 * matchedQ / (qTokens.length + hTokens.length);
|
|
438
|
+
let score = 0;
|
|
439
|
+
if (strSim >= 0.8) {
|
|
440
|
+
score = strSim;
|
|
441
|
+
} else if (tokenDice >= 0.75 && wordRecall >= 0.7 && wordPrecision >= 0.7) {
|
|
442
|
+
score = (tokenDice + wordRecall + wordPrecision) / 3;
|
|
443
|
+
}
|
|
444
|
+
if (score >= 0.75) {
|
|
445
|
+
candidates.push({ index: i, score });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (candidates.length > 0) {
|
|
449
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
450
|
+
const best = candidates[0];
|
|
451
|
+
const runnerUp = candidates[1];
|
|
452
|
+
if (candidates.length === 1 || runnerUp !== void 0 && best.score - runnerUp.score >= 0.08) {
|
|
453
|
+
return { headerPos: best.index, redirectedFrom: base, occurrences: null };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
function buildSectionResult(headers, kind, lines, headerPos, redirectedFrom) {
|
|
460
|
+
const header = headers[headerPos];
|
|
461
|
+
if (header === void 0) return null;
|
|
462
|
+
const endIndex = headerEndIndex(headers, kind, headerPos, lines.length);
|
|
463
|
+
let endExclusive = endIndex;
|
|
464
|
+
while (endExclusive > header.index + 1 && (lines[endExclusive - 1] === "" || lines[endExclusive - 1] === "\r")) {
|
|
465
|
+
endExclusive--;
|
|
466
|
+
}
|
|
467
|
+
const content = lines.slice(header.index, endExclusive).join("\n");
|
|
468
|
+
const result = {
|
|
469
|
+
heading: header.heading,
|
|
470
|
+
content,
|
|
471
|
+
lineStart: header.index + 1,
|
|
472
|
+
lineEnd: endExclusive
|
|
473
|
+
};
|
|
474
|
+
return redirectedFrom === null ? result : { ...result, redirectedFrom };
|
|
475
|
+
}
|
|
476
|
+
function resolveSectionFromText(text, headingSpec, language, allowFuzzy = true) {
|
|
477
|
+
const { headers, kind } = findHeaders(text, language);
|
|
478
|
+
const { base, ordinal } = parseHeadingSpec(headingSpec, headers);
|
|
479
|
+
if (base.length === 0) return null;
|
|
480
|
+
const lines = text.split("\n");
|
|
481
|
+
const resolved = resolveHeaderPos(headers, base, ordinal, allowFuzzy);
|
|
482
|
+
if (resolved === null) return null;
|
|
483
|
+
const built = buildSectionResult(headers, kind, lines, resolved.headerPos, resolved.redirectedFrom);
|
|
484
|
+
if (built === null || resolved.occurrences === null) return built;
|
|
485
|
+
return { ...built, occurrences: resolved.occurrences };
|
|
486
|
+
}
|
|
487
|
+
function extractSection(text, headingSpec) {
|
|
488
|
+
return resolveSectionFromText(text, headingSpec, "unknown");
|
|
489
|
+
}
|
|
490
|
+
function readTextForSections(filePath, readFn) {
|
|
491
|
+
let text;
|
|
492
|
+
if (readFn !== void 0) {
|
|
493
|
+
const read = readFn(filePath);
|
|
494
|
+
if (read === null) return null;
|
|
495
|
+
text = read;
|
|
496
|
+
} else {
|
|
497
|
+
try {
|
|
498
|
+
text = decodeSource(readFileSync(filePath));
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (text.charCodeAt(0) === 65279) {
|
|
504
|
+
text = text.slice(1);
|
|
505
|
+
}
|
|
506
|
+
return redactIfDotenv(filePath, text);
|
|
507
|
+
}
|
|
508
|
+
function readSection(filePath, headingSpec, readFn, allowFuzzy = true) {
|
|
509
|
+
const text = readTextForSections(filePath, readFn);
|
|
510
|
+
if (text === null) return null;
|
|
511
|
+
return resolveSectionFromText(text, headingSpec, refineLanguageByContent(filePath, detectLanguage(filePath), text), allowFuzzy);
|
|
512
|
+
}
|
|
513
|
+
function findContainingSection(filePath, lineStart, lineEnd, readFn) {
|
|
514
|
+
const text = readTextForSections(filePath, readFn);
|
|
515
|
+
if (text === null) return null;
|
|
516
|
+
const language = refineLanguageByContent(filePath, detectLanguage(filePath), text);
|
|
517
|
+
const { headers, kind } = findHeaders(text, language);
|
|
518
|
+
if (headers.length === 0) return null;
|
|
519
|
+
const lines = text.split("\n");
|
|
520
|
+
let bestPos = -1;
|
|
521
|
+
let bestHeaderLine = -1;
|
|
522
|
+
for (let i = 0; i < headers.length; i++) {
|
|
523
|
+
const header = headers[i];
|
|
524
|
+
if (header === void 0) continue;
|
|
525
|
+
const endIndex = headerEndIndex(headers, kind, i, lines.length);
|
|
526
|
+
const sectionLineStart = header.index + 1;
|
|
527
|
+
if (sectionLineStart <= lineStart && lineEnd <= endIndex) {
|
|
528
|
+
if (header.index > bestHeaderLine) {
|
|
529
|
+
bestHeaderLine = header.index;
|
|
530
|
+
bestPos = i;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (bestPos === -1) return null;
|
|
535
|
+
const result = buildSectionResult(headers, kind, lines, bestPos, null);
|
|
536
|
+
if (result === null) return null;
|
|
537
|
+
const bestHeader = headers[bestPos];
|
|
538
|
+
if (bestHeader === void 0) return result;
|
|
539
|
+
const target = bestHeader.heading.toLowerCase();
|
|
540
|
+
const matches = [];
|
|
541
|
+
for (let i = 0; i < headers.length; i++) {
|
|
542
|
+
const h = headers[i];
|
|
543
|
+
if (h !== void 0 && h.heading.toLowerCase() === target) matches.push(i);
|
|
544
|
+
}
|
|
545
|
+
if (matches.length <= 1) return result;
|
|
546
|
+
const ordinal = matches.indexOf(bestPos) + 1;
|
|
547
|
+
return { ...result, heading: `${bestHeader.heading}#${ordinal}` };
|
|
548
|
+
}
|
|
549
|
+
function listSections(filePath, readFn) {
|
|
550
|
+
const text = readTextForSections(filePath, readFn);
|
|
551
|
+
if (text === null) return [];
|
|
552
|
+
const language = refineLanguageByContent(filePath, detectLanguage(filePath), text);
|
|
553
|
+
const { headers } = findHeaders(text, language);
|
|
554
|
+
return headers.map((h) => h.heading);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export {
|
|
558
|
+
normalizeHeading,
|
|
559
|
+
findMarkdownHeaders,
|
|
560
|
+
extractShellBannerHeading,
|
|
561
|
+
findShellBannerHeaders,
|
|
562
|
+
extractSection,
|
|
563
|
+
readSection,
|
|
564
|
+
findContainingSection,
|
|
565
|
+
listSections
|
|
566
|
+
};
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
serveBatch,
|
|
5
5
|
serveOne,
|
|
6
6
|
swapEnv
|
|
7
|
-
} from "./token-goat-chunk-
|
|
7
|
+
} from "./token-goat-chunk-XRKUX6CM.mjs";
|
|
8
8
|
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
9
|
-
import "./token-goat-chunk-
|
|
9
|
+
import "./token-goat-chunk-CO3UYX6G.mjs";
|
|
10
10
|
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
11
11
|
export {
|
|
12
12
|
serveBatch,
|