token-goat 2.9.29 → 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 +53 -42
- package/SECURITY.md +37 -11
- package/THIRD_PARTY_NOTICES.md +41 -4
- 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/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-25TRAWET.mjs} +23 -6
- package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
- package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-2M7E4PF7.mjs} +43 -14
- package/dist/token-goat-chunk-2UPZGKKY.mjs +188 -0
- 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-2WOUYWLM.mjs → token-goat-chunk-4GILLLWY.mjs} +34 -7
- package/dist/token-goat-chunk-4NAPX7BA.mjs +90 -0
- package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-4SC7UJYV.mjs} +9981 -11563
- package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
- package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-4ZBFWLXF.mjs} +310 -441
- package/dist/token-goat-chunk-57BIAXJL.mjs +286 -0
- package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
- package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/token-goat-chunk-646E6U44.mjs +398 -0
- package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
- package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-6DG6HWP3.mjs} +13 -3
- package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
- package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
- package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-76FGDLRO.mjs} +574 -340
- package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7EZTZOMC.mjs} +780 -767
- package/dist/token-goat-chunk-7MAOA6X4.mjs +3647 -0
- package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
- package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
- package/dist/token-goat-chunk-AUNGYYQX.mjs +184 -0
- package/dist/token-goat-chunk-AUQYRMMH.mjs +2985 -0
- package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
- package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-BA4HI6BW.mjs} +1910 -165
- package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-BFCWY73P.mjs} +58 -20
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/token-goat-chunk-BWGFUZZE.mjs +25 -0
- package/dist/token-goat-chunk-C75NA7PL.mjs +322 -0
- package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
- package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
- package/dist/token-goat-chunk-CIMQ2BB3.mjs +233 -0
- package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-CJLS3CDL.mjs} +70 -18
- package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-CO3UYX6G.mjs} +7 -1
- package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
- package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
- package/dist/token-goat-chunk-CVCEVUGK.mjs +315 -0
- package/dist/token-goat-chunk-CXHOFN7R.mjs +371 -0
- package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
- package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-DGS2LVNA.mjs} +70 -160
- package/dist/{token-goat-chunk-L7H3U27L.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-EELTBKDM.mjs +613 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-F4HYL64R.mjs} +12 -2
- package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
- package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
- package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-GL3ETKSC.mjs} +276 -19
- package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-GVB2MUST.mjs} +265 -1567
- package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HLPW63A7.mjs +48 -0
- package/dist/token-goat-chunk-HU4TORC5.mjs +1377 -0
- package/dist/token-goat-chunk-I7VKZZAW.mjs +35 -0
- package/dist/token-goat-chunk-IA6XSPE3.mjs +218 -0
- package/dist/token-goat-chunk-IAGXMHIK.mjs +863 -0
- package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-IK2DRMFX.mjs} +129 -74
- package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-INNPTRUX.mjs} +2954 -2783
- package/dist/token-goat-chunk-JJ5BX4F4.mjs +129 -0
- package/dist/token-goat-chunk-JVFSHVFJ.mjs +129 -0
- package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
- package/dist/token-goat-chunk-LCNQ2CNN.mjs +497 -0
- 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-2AWQ2R5X.mjs → token-goat-chunk-MHX7XCC3.mjs} +3 -2
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
- package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-N5MMR2IW.mjs} +30 -8
- package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
- package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-NISNMD7T.mjs} +2545 -2953
- package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
- package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
- package/dist/token-goat-chunk-NSNSPPBG.mjs +69 -0
- package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
- package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
- package/dist/token-goat-chunk-ODBT2USM.mjs +800 -0
- 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-ASLWOQ3I.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -1
- package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-P6HQSWQ3.mjs} +55 -47
- package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
- package/dist/token-goat-chunk-PFWIMH2E.mjs +261 -0
- package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
- package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
- package/dist/token-goat-chunk-PX5PQWTY.mjs +462 -0
- package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
- package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
- package/dist/token-goat-chunk-QH7YVYOY.mjs +3957 -0
- package/dist/token-goat-chunk-QLMUHEPB.mjs +43 -0
- package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-QQOJIHL3.mjs} +50 -14
- package/dist/token-goat-chunk-QQTWJY2O.mjs +85 -0
- package/dist/token-goat-chunk-QYHO5CPH.mjs +93 -0
- package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
- package/dist/token-goat-chunk-RSLPOBKQ.mjs +339 -0
- package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
- package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
- package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-SOAFZNNZ.mjs} +164 -40
- package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-SRTHT7KV.mjs} +33 -15
- package/dist/token-goat-chunk-T5P5ACNQ.mjs +212 -0
- package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
- package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
- package/dist/token-goat-chunk-TM6MC754.mjs +40 -0
- package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
- package/dist/token-goat-chunk-U2KSB4SG.mjs +56 -0
- package/dist/token-goat-chunk-U4WHMG6Y.mjs +898 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/token-goat-chunk-UGJHGR5A.mjs +52 -0
- package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-UOUDVA5U.mjs} +76 -16
- package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-URRJ33GR.mjs} +22 -4
- package/dist/token-goat-chunk-UZOROKIS.mjs +165 -0
- package/dist/token-goat-chunk-VIHGGGEI.mjs +4234 -0
- package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
- package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
- package/dist/token-goat-chunk-VWZA2H4P.mjs +368 -0
- package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-VXEXMJDL.mjs} +2964 -3153
- package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
- package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-WDH44VAU.mjs} +19 -22
- package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
- package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
- package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-XLRBNZCC.mjs} +40 -21
- package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-XRKUX6CM.mjs} +4 -0
- package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
- package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
- package/dist/token-goat-chunk-Y2ZTQOCL.mjs +35 -0
- package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-YB4VMGK2.mjs} +15 -4
- package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
- package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-YHVDKQBR.mjs} +389 -221
- package/dist/token-goat-chunk-YJB5XLWI.mjs +26 -0
- package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-YKB6AQG3.mjs} +53 -31
- package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
- package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
- package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-YY6AVUFL.mjs} +13246 -12247
- package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
- package/dist/token-goat-hook-client.cjs +87 -23
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +76 -31
- package/dist/token-goat.core.mjs +6 -6
- package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
- package/docs/cli.md +113 -60
- package/docs/install.md +63 -20
- package/docs/security.md +10 -8
- package/package.json +18 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
- package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
- package/dist/token-goat-chunk-BGYOZ6DO.mjs +0 -24
- package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
- package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
- package/dist/token-goat-chunk-D4ETHJD6.mjs +0 -246
- package/dist/token-goat-chunk-DNRPXHYH.mjs +0 -1062
- package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
- package/dist/token-goat-chunk-FTP4U4QA.mjs +0 -64
- package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
- package/dist/token-goat-chunk-GLXRTTLE.mjs +0 -36
- package/dist/token-goat-chunk-H5J3C56Q.mjs +0 -1511
- package/dist/token-goat-chunk-IVWI2OCK.mjs +0 -368
- package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
- package/dist/token-goat-chunk-LZNBQTDK.mjs +0 -26
- package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
- package/dist/token-goat-chunk-RTMVLHWX.mjs +0 -7113
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
- package/dist/token-goat-chunk-VZQEWRVH.mjs +0 -312
- package/dist/token-goat-chunk-XYWPOSCN.mjs +0 -807
- package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
- package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
|
@@ -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,8 +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-CO3UYX6G.mjs";
|
|
9
10
|
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
10
11
|
export {
|
|
11
12
|
serveBatch,
|