@cyanheads/secedgar-mcp-server 0.20.0 → 0.21.0

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.
Files changed (128) hide show
  1. package/AGENTS.md +41 -33
  2. package/CLAUDE.md +41 -33
  3. package/README.md +37 -16
  4. package/changelog/0.20.x/0.20.1.md +39 -0
  5. package/changelog/0.21.x/0.21.0.md +35 -0
  6. package/changelog/template.md +10 -8
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js +3 -3
  10. package/dist/mcp-server/prompts/definitions/company-analysis.prompt.js.map +1 -1
  11. package/dist/mcp-server/tools/annual-report-reads.d.ts +50 -0
  12. package/dist/mcp-server/tools/annual-report-reads.d.ts.map +1 -0
  13. package/dist/mcp-server/tools/annual-report-reads.js +141 -0
  14. package/dist/mcp-server/tools/annual-report-reads.js.map +1 -0
  15. package/dist/mcp-server/tools/calendar-quarter.d.ts +22 -0
  16. package/dist/mcp-server/tools/calendar-quarter.d.ts.map +1 -0
  17. package/dist/mcp-server/tools/calendar-quarter.js +34 -0
  18. package/dist/mcp-server/tools/calendar-quarter.js.map +1 -0
  19. package/dist/mcp-server/tools/definitions/company-search.tool.d.ts.map +1 -1
  20. package/dist/mcp-server/tools/definitions/company-search.tool.js +11 -22
  21. package/dist/mcp-server/tools/definitions/company-search.tool.js.map +1 -1
  22. package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts +12 -2
  23. package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/definitions/compare-companies.tool.js +153 -48
  25. package/dist/mcp-server/tools/definitions/compare-companies.tool.js.map +1 -1
  26. package/dist/mcp-server/tools/definitions/dataframe-query.tool.d.ts.map +1 -1
  27. package/dist/mcp-server/tools/definitions/dataframe-query.tool.js +28 -5
  28. package/dist/mcp-server/tools/definitions/dataframe-query.tool.js.map +1 -1
  29. package/dist/mcp-server/tools/definitions/fetch-frames.tool.d.ts.map +1 -1
  30. package/dist/mcp-server/tools/definitions/fetch-frames.tool.js +4 -2
  31. package/dist/mcp-server/tools/definitions/fetch-frames.tool.js.map +1 -1
  32. package/dist/mcp-server/tools/definitions/find-holders.tool.d.ts.map +1 -1
  33. package/dist/mcp-server/tools/definitions/find-holders.tool.js +12 -19
  34. package/dist/mcp-server/tools/definitions/find-holders.tool.js.map +1 -1
  35. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts +24 -9
  36. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.d.ts.map +1 -1
  37. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js +126 -47
  38. package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js.map +1 -1
  39. package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts +24 -2
  40. package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts.map +1 -1
  41. package/dist/mcp-server/tools/definitions/get-filing.tool.js +370 -92
  42. package/dist/mcp-server/tools/definitions/get-filing.tool.js.map +1 -1
  43. package/dist/mcp-server/tools/definitions/get-financials.tool.d.ts.map +1 -1
  44. package/dist/mcp-server/tools/definitions/get-financials.tool.js +127 -44
  45. package/dist/mcp-server/tools/definitions/get-financials.tool.js.map +1 -1
  46. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.d.ts.map +1 -1
  47. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js +5 -6
  48. package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js.map +1 -1
  49. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts +42 -2
  50. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts.map +1 -1
  51. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js +525 -134
  52. package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js.map +1 -1
  53. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts +12 -0
  54. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.d.ts.map +1 -1
  55. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js +21 -36
  56. package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js.map +1 -1
  57. package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts +15 -0
  58. package/dist/mcp-server/tools/definitions/get-material-events.tool.d.ts.map +1 -1
  59. package/dist/mcp-server/tools/definitions/get-material-events.tool.js +108 -55
  60. package/dist/mcp-server/tools/definitions/get-material-events.tool.js.map +1 -1
  61. package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts +5 -0
  62. package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts.map +1 -1
  63. package/dist/mcp-server/tools/definitions/get-snapshot.tool.js +70 -37
  64. package/dist/mcp-server/tools/definitions/get-snapshot.tool.js.map +1 -1
  65. package/dist/mcp-server/tools/definitions/index.d.ts +282 -219
  66. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
  67. package/dist/mcp-server/tools/definitions/search-concepts.tool.d.ts.map +1 -1
  68. package/dist/mcp-server/tools/definitions/search-concepts.tool.js +16 -11
  69. package/dist/mcp-server/tools/definitions/search-concepts.tool.js.map +1 -1
  70. package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts +18 -0
  71. package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts.map +1 -1
  72. package/dist/mcp-server/tools/definitions/search-filings.tool.js +130 -68
  73. package/dist/mcp-server/tools/definitions/search-filings.tool.js.map +1 -1
  74. package/dist/mcp-server/tools/filing-dates.d.ts +46 -0
  75. package/dist/mcp-server/tools/filing-dates.d.ts.map +1 -0
  76. package/dist/mcp-server/tools/filing-dates.js +93 -0
  77. package/dist/mcp-server/tools/filing-dates.js.map +1 -0
  78. package/dist/mcp-server/tools/limit-clamp.d.ts.map +1 -1
  79. package/dist/mcp-server/tools/limit-clamp.js +6 -2
  80. package/dist/mcp-server/tools/limit-clamp.js.map +1 -1
  81. package/dist/services/edgar/body-text-decoder.d.ts +33 -0
  82. package/dist/services/edgar/body-text-decoder.d.ts.map +1 -0
  83. package/dist/services/edgar/body-text-decoder.js +103 -0
  84. package/dist/services/edgar/body-text-decoder.js.map +1 -0
  85. package/dist/services/edgar/call-scope.d.ts +13 -1
  86. package/dist/services/edgar/call-scope.d.ts.map +1 -1
  87. package/dist/services/edgar/call-scope.js +4 -1
  88. package/dist/services/edgar/call-scope.js.map +1 -1
  89. package/dist/services/edgar/concept-map.d.ts.map +1 -1
  90. package/dist/services/edgar/concept-map.js +88 -14
  91. package/dist/services/edgar/concept-map.js.map +1 -1
  92. package/dist/services/edgar/concept-series.d.ts +111 -1
  93. package/dist/services/edgar/concept-series.d.ts.map +1 -1
  94. package/dist/services/edgar/concept-series.js +196 -1
  95. package/dist/services/edgar/concept-series.js.map +1 -1
  96. package/dist/services/edgar/edgar-api-service.d.ts +2 -12
  97. package/dist/services/edgar/edgar-api-service.d.ts.map +1 -1
  98. package/dist/services/edgar/edgar-api-service.js +30 -39
  99. package/dist/services/edgar/edgar-api-service.js.map +1 -1
  100. package/dist/services/edgar/eight-k-items.d.ts +19 -1
  101. package/dist/services/edgar/eight-k-items.d.ts.map +1 -1
  102. package/dist/services/edgar/eight-k-items.js +24 -1
  103. package/dist/services/edgar/eight-k-items.js.map +1 -1
  104. package/dist/services/edgar/filing-to-text.d.ts +29 -10
  105. package/dist/services/edgar/filing-to-text.d.ts.map +1 -1
  106. package/dist/services/edgar/filing-to-text.js +605 -53
  107. package/dist/services/edgar/filing-to-text.js.map +1 -1
  108. package/dist/services/edgar/fiscal-periods.d.ts +2 -0
  109. package/dist/services/edgar/fiscal-periods.d.ts.map +1 -1
  110. package/dist/services/edgar/fiscal-periods.js +1 -1
  111. package/dist/services/edgar/fiscal-periods.js.map +1 -1
  112. package/dist/services/edgar/form4-amendments.d.ts +63 -0
  113. package/dist/services/edgar/form4-amendments.d.ts.map +1 -0
  114. package/dist/services/edgar/form4-amendments.js +99 -0
  115. package/dist/services/edgar/form4-amendments.js.map +1 -0
  116. package/dist/services/edgar/mirror/companyfacts-sync.d.ts +6 -1
  117. package/dist/services/edgar/mirror/companyfacts-sync.d.ts.map +1 -1
  118. package/dist/services/edgar/mirror/companyfacts-sync.js +29 -6
  119. package/dist/services/edgar/mirror/companyfacts-sync.js.map +1 -1
  120. package/dist/services/edgar/ownership-parser.d.ts +5 -0
  121. package/dist/services/edgar/ownership-parser.d.ts.map +1 -1
  122. package/dist/services/edgar/ownership-parser.js +3 -0
  123. package/dist/services/edgar/ownership-parser.js.map +1 -1
  124. package/dist/services/edgar/types.d.ts +12 -7
  125. package/dist/services/edgar/types.d.ts.map +1 -1
  126. package/package.json +8 -8
  127. package/server.json +3 -3
  128. package/skills/secedgar-guide/SKILL.md +22 -5
@@ -22,13 +22,17 @@ import { CURRENT_EIGHT_K_ITEMS } from './eight-k-items.js';
22
22
  * parser ignores CSS, so that div takes the `pre` formatter, which keeps the
23
23
  * text's whitespace as the stylesheet shows it, with a plain div's single line
24
24
  * break before and after.
25
+ *
26
+ * A table prints one row per line, its cells tab-separated
27
+ * ({@link formatTableRows}, #257).
25
28
  */
26
29
  const CONVERT_OPTIONS = {
27
30
  wordwrap: false,
31
+ formatters: { tableRows: formatTableRows },
28
32
  selectors: [
29
33
  { selector: 'a', options: { ignoreHref: true } },
30
34
  { selector: 'img', format: 'skip' },
31
- { selector: 'table', options: { uppercaseHeaderCells: false } },
35
+ { selector: 'table', format: 'tableRows' },
32
36
  {
33
37
  selector: 'div.largetext',
34
38
  format: 'pre',
@@ -567,6 +571,289 @@ function stripSentinels(converted, markers) {
567
571
  parts.push(converted.slice(copied));
568
572
  return { offsets, text: parts.join('') };
569
573
  }
574
+ /** One marker as {@link markInDocumentLinks} writes it. Global: a scanner over a field. */
575
+ const SENTINEL_RE = new RegExp(`${SENTINEL_OPEN}\\d+${SENTINEL_CLOSE}`, 'g');
576
+ /**
577
+ * The widest field run a cell's `colspan` opens. Workiva tables in a 14-filing
578
+ * sample reach 51; HTML's own cap is 1,000, and a run that wide would print ~45
579
+ * tabs per input character, so a crafted table could inflate the text far past
580
+ * its input.
581
+ */
582
+ const MAX_TABLE_COLSPAN = 100;
583
+ /**
584
+ * How many wrapper levels between the table and its rows (or a row and its
585
+ * cells) {@link formatTableRows} reads through: `thead`/`tbody`/`tfoot`, and the
586
+ * `font` or `form` an older filing wraps rows in. Deeper markup is printed as a
587
+ * field of its own, its text kept.
588
+ */
589
+ const MAX_TABLE_WRAPPER_DEPTH = 8;
590
+ /** The `colspan` {@link formatTableRows} gives content outside any cell, marking it for the printer. */
591
+ const LOOSE_FIELD = 0;
592
+ /**
593
+ * What a node is to {@link formatTableRows}: a row, a cell, a wrapper holding
594
+ * either, nothing to print (a comment, or text the parser reads as whitespace),
595
+ * or content to print as a field of its own.
596
+ */
597
+ function tableNodeKind(node, depth) {
598
+ if (node.type === 'comment')
599
+ return 'blank';
600
+ if (node.type === 'text') {
601
+ const data = node.data ?? '';
602
+ for (let at = 0; at < data.length; at++) {
603
+ if (!isConvertWhitespace(data.charCodeAt(at)))
604
+ return 'other';
605
+ }
606
+ return 'blank';
607
+ }
608
+ if (node.type !== 'tag')
609
+ return 'other';
610
+ if (node.name === 'tr')
611
+ return 'row';
612
+ if (node.name === 'td' || node.name === 'th')
613
+ return 'cell';
614
+ if (node.name === 'table')
615
+ return 'other';
616
+ return holdsTableStructure(node, MAX_TABLE_WRAPPER_DEPTH - depth) ? 'wrapper' : 'other';
617
+ }
618
+ /** Whether a row or cell sits within `levels` levels below `node`, no nested table crossed. */
619
+ function holdsTableStructure(node, levels) {
620
+ if (levels <= 0)
621
+ return false;
622
+ return node.children.some((child) => child.type === 'tag' &&
623
+ child.name !== 'table' &&
624
+ (child.name === 'tr' ||
625
+ child.name === 'td' ||
626
+ child.name === 'th' ||
627
+ holdsTableStructure(child, levels - 1)));
628
+ }
629
+ /** A cell's `colspan` as HTML reads it (leading digits), 1 when absent or invalid, at most {@link MAX_TABLE_COLSPAN}. */
630
+ function colspanOf(cell) {
631
+ const colspan = Number.parseInt(String(cell.attribs?.colspan ?? ''), 10);
632
+ return colspan >= 1 ? Math.min(colspan, MAX_TABLE_COLSPAN) : 1;
633
+ }
634
+ /**
635
+ * The `table` formatter (#257): each row prints as one line, each cell as one
636
+ * field, fields joined by a tab. html-to-text's own `table` format prints a
637
+ * table as a plain block unless the table is listed in its deprecated `tables`
638
+ * option, so rows and cells got no breaks: an inline-XBRL statement whose cells
639
+ * hold spans came back as one line with labels run into their figures, and a
640
+ * table whose cells hold `<p>` lost its rows. Its `dataTable` format pads
641
+ * columns to a width and wraps cells, which interleaves a cell's second line
642
+ * with its neighbours' first (814 multi-word cell texts no longer contiguous over
643
+ * 14 filings) and counts the #239 link sentinels into column widths, so the text
644
+ * changes once they are stripped.
645
+ *
646
+ * Rows are the table's `tr` elements, read through `thead`/`tbody`/`tfoot` and
647
+ * any other wrapper holding rows (up to {@link MAX_TABLE_WRAPPER_DEPTH} levels);
648
+ * cells outside any row print as a row of their own. Every other node — a
649
+ * caption, stray text, content between a row's cells — prints in its place as a
650
+ * field, so no text the block format printed is lost. Rowspan is ignored. Line
651
+ * breaks before and after the table are a block's, as the `table` format had.
652
+ */
653
+ function formatTableRows(elem, walk, builder, formatOptions) {
654
+ const field = (nodes, colspan) => {
655
+ builder.openTableCell();
656
+ walk(nodes, builder);
657
+ builder.closeTableCell({ colspan, rowspan: 1 });
658
+ };
659
+ const cells = (nodes, depth) => {
660
+ let loose = [];
661
+ for (const node of nodes) {
662
+ const kind = tableNodeKind(node, depth);
663
+ if (kind === 'blank')
664
+ continue;
665
+ if (kind === 'other') {
666
+ loose.push(node);
667
+ continue;
668
+ }
669
+ if (loose.length > 0)
670
+ field(loose, LOOSE_FIELD);
671
+ loose = [];
672
+ if (kind === 'cell')
673
+ field(node.children, colspanOf(node));
674
+ else
675
+ cells(node.children, depth + 1);
676
+ }
677
+ if (loose.length > 0)
678
+ field(loose, LOOSE_FIELD);
679
+ };
680
+ const rows = (nodes, depth) => {
681
+ let outsideRows = [];
682
+ const flush = () => {
683
+ if (outsideRows.length === 0)
684
+ return;
685
+ builder.openTableRow();
686
+ cells(outsideRows, depth);
687
+ builder.closeTableRow();
688
+ outsideRows = [];
689
+ };
690
+ for (const node of nodes) {
691
+ const kind = tableNodeKind(node, depth);
692
+ if (kind === 'blank')
693
+ continue;
694
+ if (kind === 'row') {
695
+ flush();
696
+ builder.openTableRow();
697
+ cells(node.children, depth + 1);
698
+ builder.closeTableRow();
699
+ }
700
+ else if (kind === 'wrapper') {
701
+ flush();
702
+ rows(node.children, depth + 1);
703
+ }
704
+ else {
705
+ outsideRows.push(node);
706
+ }
707
+ }
708
+ flush();
709
+ };
710
+ builder.openTable();
711
+ rows(elem.children, 0);
712
+ builder.closeTable({
713
+ tableToString: printTableRows,
714
+ leadingLineBreaks: formatOptions.leadingLineBreaks ?? 1,
715
+ trailingLineBreaks: formatOptions.trailingLineBreaks ?? 1,
716
+ });
717
+ }
718
+ /** A sentinel starting at `lastIndex`. Sticky: a test at one position. */
719
+ const SENTINEL_AT_RE = new RegExp(`${SENTINEL_OPEN}\\d+${SENTINEL_CLOSE}`, 'y');
720
+ /**
721
+ * The index just past a sentinel starting at `at`, or -1 when none does — a
722
+ * noncharacter the document itself holds (its conversion is never marked) is
723
+ * text.
724
+ */
725
+ function sentinelEnd(text, at) {
726
+ SENTINEL_AT_RE.lastIndex = at;
727
+ return SENTINEL_AT_RE.test(text) ? SENTINEL_AT_RE.lastIndex : -1;
728
+ }
729
+ /** The index of a sentinel ending just before `end`, or -1 when none does. */
730
+ function sentinelStart(text, end) {
731
+ const open = text.lastIndexOf(SENTINEL_OPEN, end - 1);
732
+ return open !== -1 && sentinelEnd(text, open) === end ? open : -1;
733
+ }
734
+ /** Whether a character is whitespace as `String.prototype.trim` reads it, NBSP included. */
735
+ const isTrimSpace = (char) => /\s/.test(char);
736
+ /** Whether a character is one of html-to-text's whitespace characters ({@link isConvertWhitespace}); NBSP is not. */
737
+ const isConvertSpace = (char) => isConvertWhitespace(char.charCodeAt(0));
738
+ /** The #239 sentinels in `text`, in order. */
739
+ function sentinelsIn(text) {
740
+ return text.match(SENTINEL_RE)?.join('') ?? '';
741
+ }
742
+ /**
743
+ * `text` with its ends trimmed of `space` — by default whitespace as
744
+ * `String.prototype.trim` reads it, NBSP included — while every #239 sentinel at
745
+ * either end is kept, so a marked field trims to the unmarked field plus its
746
+ * sentinels. Two passes over the ends, each sentinel read once.
747
+ */
748
+ function trimField(text, isSpace = isTrimSpace) {
749
+ let start = 0;
750
+ for (let next = 0; start < text.length; start = next) {
751
+ next = text.charAt(start) === SENTINEL_OPEN ? sentinelEnd(text, start) : -1;
752
+ if (next === -1 && isSpace(text.charAt(start)))
753
+ next = start + 1;
754
+ if (next === -1)
755
+ break;
756
+ }
757
+ let end = text.length;
758
+ for (let previous = 0; end > start; end = previous) {
759
+ previous = text.charAt(end - 1) === SENTINEL_CLOSE ? sentinelStart(text, end) : -1;
760
+ if (previous === -1 && isSpace(text.charAt(end - 1)))
761
+ previous = end - 1;
762
+ if (previous === -1)
763
+ break;
764
+ }
765
+ return sentinelsIn(text.slice(0, start)) + text.slice(start, end) + sentinelsIn(text.slice(end));
766
+ }
767
+ /** `line` with its trailing tabs removed, any sentinel among them kept at the line's end. */
768
+ function trimTrailingTabs(line) {
769
+ let end = line.length;
770
+ for (let previous = 0; end > 0; end = previous) {
771
+ previous = line.charAt(end - 1) === SENTINEL_CLOSE ? sentinelStart(line, end) : -1;
772
+ if (previous === -1 && line.charAt(end - 1) === '\t')
773
+ previous = end - 1;
774
+ if (previous === -1)
775
+ break;
776
+ }
777
+ return line.slice(0, end) + line.slice(end).replaceAll('\t', '');
778
+ }
779
+ /** Whether a trimmed field holds text beyond the #239 sentinels. */
780
+ function holdsText(field) {
781
+ return field.text.replace(SENTINEL_RE, '') !== '';
782
+ }
783
+ /**
784
+ * Print {@link formatTableRows}' rows, one line each, by how many of a row's
785
+ * fields hold text:
786
+ *
787
+ * - Two or more: a data row. Each field's own line breaks and tabs (a nested
788
+ * table's) fold to one space, since a break inside a cell would split the
789
+ * row; a `colspan` of N is followed by N−1 empty fields, so a period's figures
790
+ * stay under its header's span; fields are joined by a tab, trailing tabs
791
+ * trimmed.
792
+ * - One: a layout row — a spacer cell beside a paragraph, a caption cell, a
793
+ * one-cell wrapper around a nested table. It prints its text as the block
794
+ * layout did: line breaks and a nested table's rows kept, no empty fields, and
795
+ * only html-to-text's whitespace trimmed, so an NBSP-indented caption stays
796
+ * indented and out of the outline as before (Goldman Sachs' committee table
797
+ * " COMPENSATION"). SEC's 13D rendering sets the filer's Item paragraphs in
798
+ * such a row (#216).
799
+ * - None: nothing.
800
+ *
801
+ * A data row's fields are trimmed of all whitespace, NBSP included. No padding,
802
+ * no wrapping. Every trim and emptiness test passes over the #239 sentinels, so
803
+ * the marked conversion strips to the unmarked one byte for byte: a sentinel at a
804
+ * field's end stays at the trimmed end, a layout row keeps its empty fields'
805
+ * sentinels in document order around its text, and the sentinels of a field or
806
+ * row that prints nothing move to the start of the next field or row that does
807
+ * (to the end of the last row when none follows). A table printing no row drops
808
+ * its sentinels, so a target in it records no link, as a target with no text
809
+ * after it does.
810
+ */
811
+ function printTableRows(rows) {
812
+ const lines = [];
813
+ let carried = '';
814
+ for (const row of rows) {
815
+ const fields = row.map((cell) => ({
816
+ colspan: cell.colspan,
817
+ raw: cell.text,
818
+ text: trimField(cell.text),
819
+ }));
820
+ const textFields = fields.filter(holdsText).length;
821
+ if (textFields === 0) {
822
+ // A field without text trims to its sentinels alone.
823
+ carried += fields.map((field) => field.text).join('');
824
+ continue;
825
+ }
826
+ const line = textFields === 1
827
+ ? fields
828
+ .map((field) => (holdsText(field) ? trimField(field.raw, isConvertSpace) : field.text))
829
+ .join('')
830
+ : printDataRow(fields);
831
+ lines.push(carried + line);
832
+ carried = '';
833
+ }
834
+ if (carried !== '' && lines.length > 0)
835
+ lines[lines.length - 1] += carried;
836
+ return lines.join('\n');
837
+ }
838
+ /**
839
+ * One data row of {@link printTableRows}: trimmed fields folded and tab-joined,
840
+ * content outside a cell with no text dropped, its sentinels handed on.
841
+ */
842
+ function printDataRow(fields) {
843
+ const printed = [];
844
+ let pending = '';
845
+ for (const field of fields) {
846
+ if (field.colspan === LOOSE_FIELD && !holdsText(field)) {
847
+ pending += field.text;
848
+ continue;
849
+ }
850
+ printed.push(pending + field.text.replace(/[ \t\n]+/g, (run) => (/[\t\n]/.test(run) ? ' ' : run)));
851
+ pending = '';
852
+ for (let k = 1; k < field.colspan; k++)
853
+ printed.push('');
854
+ }
855
+ return trimTrailingTabs(printed.join('\t')) + pending;
856
+ }
570
857
  /**
571
858
  * Extract full plain text from a filing document — HTML, or an SGML submission,
572
859
  * every readable document in order with plain-text `<TEXT>` bodies keeping their
@@ -614,6 +901,10 @@ export function getExtractCache(cacheKey) {
614
901
  export function setExtractCache(cacheKey, entry) {
615
902
  cacheSet(cacheKey, entry);
616
903
  }
904
+ /** Drop one extraction, so the next read of its key resolves the filing again. */
905
+ export function deleteExtractCache(cacheKey) {
906
+ extractCache.delete(cacheKey);
907
+ }
617
908
  /** Exposed for tests: evict all entries from the extraction cache. */
618
909
  export function clearExtractCache() {
619
910
  extractCache.clear();
@@ -729,12 +1020,53 @@ const UNPUNCTUATED_ITEM_RE = new RegExp(String.raw `^item[^\S\n]+${ITEM_CODE}(?:
729
1020
  * Contents" above "Item 5 — Other information" at the top of a page).
730
1021
  */
731
1022
  const MID_SENTENCE_END_RE = /[,;]$/;
732
- /** Whether the line before the one starting at `lineStart` ends mid-sentence. */
1023
+ /**
1024
+ * Whether the line before the one starting at `lineStart` ends mid-sentence. A
1025
+ * table row ({@link formatTableRows}, a line holding a tab) is no sentence: its
1026
+ * last cell ends on a comma in a date header ("June 30,") as often as not.
1027
+ */
733
1028
  function followsMidSentence(text, lineStart) {
734
1029
  if (lineStart === 0)
735
1030
  return false;
736
1031
  const previousLine = text.slice(text.lastIndexOf('\n', lineStart - 2) + 1, lineStart - 1);
737
- return MID_SENTENCE_END_RE.test(previousLine.trimEnd());
1032
+ return !previousLine.includes('\t') && MID_SENTENCE_END_RE.test(previousLine.trimEnd());
1033
+ }
1034
+ /**
1035
+ * The title of an all-caps table-of-contents row — one title field and one page
1036
+ * cell ({@link TOC_PAGE_TAIL_RE}), "RISK FACTORS→27" — or undefined for any other
1037
+ * table row (#257). Every other row of capitals is cells ("AC→→→CC→→→NCGC",
1038
+ * "FWGR 1→—→—"), never a heading. A TOC row stays one: Anthropic's S-1/A prints
1039
+ * its contents in capitals and its section headings in mixed case, which
1040
+ * detection does not list, so its TOC rows are what `section` lands on and
1041
+ * follows through their links (#239).
1042
+ */
1043
+ function tocRowTitle(line) {
1044
+ const title = stripPageNumberTail(line);
1045
+ return title !== line && !title.includes('\t') ? title.trimEnd() : undefined;
1046
+ }
1047
+ /**
1048
+ * An Item or Part heading printed on a table row ({@link formatTableRows}, #257):
1049
+ * its marker field and, when that field is a bare marker, the next field with
1050
+ * text — its title — joined by one space. Later fields are dropped as a TOC page
1051
+ * cell is: a cross-reference index row "Item 1A.→→→Risk Factors→→→Pages 37-51"
1052
+ * reads "Item 1A. Risk Factors", and "ITEM 3.→KEY INFORMATION→6" "ITEM 3. KEY
1053
+ * INFORMATION". A page number in the title's place leaves the bare marker. Like a
1054
+ * marker joined to a title on a later line, the heading is not the line's bytes;
1055
+ * {@link isTitledAt} compares it folded.
1056
+ */
1057
+ function tableRowHeading(line) {
1058
+ const fields = line.split('\t');
1059
+ let kept = 1;
1060
+ if (BARE_MARKER_HEADING_RE.test((fields[0] ?? '').trim())) {
1061
+ while (kept < fields.length && (fields[kept] ?? '').trim() === '')
1062
+ kept++;
1063
+ kept++;
1064
+ }
1065
+ return stripPageNumberTail(fields.slice(0, kept).join('\t'))
1066
+ .split('\t')
1067
+ .map((field) => field.trim())
1068
+ .filter((field) => field !== '')
1069
+ .join(' ');
738
1070
  }
739
1071
  /** A whitespace-delimited token holding a digit must be a section number: `10`, `14A`, `2.`. */
740
1072
  const SECTION_NUMBER_TOKEN_RE = /^\d{1,2}[A-Z]?\.?$/;
@@ -870,19 +1202,32 @@ const SEPARATED_TITLE_RE = /\n[^\S\n]*\n(?:[^\S\n]*\n)*[^\S\n]*(\S[^\n]*)/y;
870
1202
  const TIGHT_TITLE_RE = /\n[^\S\n]*(\S[^\n]*)\n?([^\n]*)/y;
871
1203
  /** A whole line holding nothing but a page number — the TOC-cell tell. */
872
1204
  const PAGE_NUMBER_LINE_RE = /^[^\S\n]*\d{1,4}[^\S\n]*$/;
1205
+ /** A TOC page number: up to four digits, or a lettered financial-statement page ("F-3"). */
1206
+ const PAGE_NUMBER = String.raw `(?:\d{1,4}|[A-Z]-\d{1,3})`;
1207
+ /** A page or a range of pages ("29-32"). */
1208
+ const PAGE_SPAN = `${PAGE_NUMBER}(?:[-–]${PAGE_NUMBER})?`;
1209
+ /**
1210
+ * A page cell opening on a `Page` or `Pages` word, which may go on to list pages
1211
+ * and ranges: "Page 1", "Pages 29-32", "Pages 56-108, 110-115".
1212
+ */
1213
+ const PAGE_WORD_CELL = String.raw `(?:Pages?|PAGES?)[^\S\n]+${PAGE_SPAN}(?:,[^\S\n]*${PAGE_SPAN})*`;
873
1214
  /**
874
1215
  * A TOC row's page cell at the end of its line, set off by a tab or two or more
875
- * spaces ("Key Information 3", "Consolidated Balance Sheets F-3"), its
876
- * number optionally after a `Page` word ("Item 8.01 Other Events Page 1",
877
- * the cell First Bancorp's 8-K TOC prints, which otherwise kept the row from
878
- * deduping against its body Item and took `item 8`). One space is not enough: a
879
- * heading can end in its own number ("PROPOSAL NO. 1", "ARTICLE 5", "…Exchange
880
- * Act of 1934", "…as of June 30, 2026"), which a single-space rule stripped or
881
- * read as a TOC row (#172, #166). The lookbehind starts a try only where a
882
- * whitespace run begins; a try from inside the run rescanned the rest of it,
883
- * quadratic on a long run.
884
- */
885
- const TOC_PAGE_TAIL_RE = /(?<![^\S\n])(?:[^\S\n]{2,}|\t)(?:(?:Page|PAGE)[^\S\n]+)?(?:\d{1,4}|[A-Z]-\d{1,3})[^\S\n]*$/;
1216
+ * spaces ("Key Information 3", "Consolidated Balance Sheets F-3"): a page
1217
+ * number, or a `Page` word's cell ({@link PAGE_WORD_CELL}). The word form reads
1218
+ * "Item 8.01 Other Events Page 1", the cell First Bancorp's 8-K TOC prints,
1219
+ * which otherwise kept the row from deduping against its body Item and took
1220
+ * `item 8`; and the page lists of Intel's 10-K cross-reference index
1221
+ * (0000050863-26-000011), "Liquidity and capital resources→→Pages 29-32" under
1222
+ * its Item 7 row, which otherwise read as a body heading and took `management's
1223
+ * discussion` from the body (#257). A range with no `Page` word before it
1224
+ * ("37-51") stays text. One space is not enough: a heading can end in its own
1225
+ * number ("PROPOSAL NO. 1", "ARTICLE 5", "…Exchange Act of 1934", "…as of June
1226
+ * 30, 2026"), which a single-space rule stripped or read as a TOC row (#172,
1227
+ * #166). The lookbehind starts a try only where a whitespace run begins; a try
1228
+ * from inside the run rescanned the rest of it, quadratic on a long run.
1229
+ */
1230
+ const TOC_PAGE_TAIL_RE = new RegExp(String.raw `(?<![^\S\n])(?:[^\S\n]{2,}|\t)(?:${PAGE_WORD_CELL}|${PAGE_NUMBER})[^\S\n]*$`);
886
1231
  /**
887
1232
  * The title bound for an Item marker's title, a titled Part's title, and an
888
1233
  * all-caps heading line — past it the line reads as body prose. The same-line
@@ -1067,10 +1412,11 @@ function titleAfterMarkerLine(text, markerLineEnd, maxChars) {
1067
1412
  /**
1068
1413
  * A candidate title line reduced to heading text, or undefined when it is not a
1069
1414
  * title at all — empty, a bare page number, the next marker, or longer than
1070
- * `maxChars`, where it reads as body prose.
1415
+ * `maxChars`, where it reads as body prose. On a table row the title is the
1416
+ * first field with text (#257).
1071
1417
  */
1072
1418
  function usableTitle(raw, maxChars) {
1073
- const title = stripPageNumberTail(raw).trim();
1419
+ const title = (stripPageNumberTail(raw).trim().split('\t', 1)[0] ?? '').trim();
1074
1420
  if (title.length === 0 || title.length > maxChars)
1075
1421
  return;
1076
1422
  if (/^\d+$/.test(title))
@@ -1111,37 +1457,42 @@ export function detectHeadings(text) {
1111
1457
  // Item line may open on included (#176); `itemEntryOffset` places the entry.
1112
1458
  ALL_CAPS_HEADING_RE.lastIndex = 0;
1113
1459
  for (let match = ALL_CAPS_HEADING_RE.exec(text); match !== null; match = ALL_CAPS_HEADING_RE.exec(text)) {
1114
- const [, heading, capsLine] = match;
1115
- if (heading === undefined || isWrappedProse(text, match.index, heading))
1460
+ const [, line, capsLine] = match;
1461
+ if (line === undefined || isWrappedProse(text, match.index, line))
1116
1462
  continue;
1117
1463
  if (capsLine === undefined) {
1118
- if (isRunTogetherToc(heading))
1464
+ if (isRunTogetherToc(line))
1119
1465
  continue;
1120
1466
  }
1121
1467
  else {
1122
- if (!isAllCapsHeadingText(capsLine))
1468
+ const title = capsLine.includes('\t') ? tocRowTitle(capsLine) : capsLine;
1469
+ if (title === undefined || !isAllCapsHeadingText(title))
1123
1470
  continue;
1124
- const partTitle = TITLED_PART_HEADING_RE.exec(capsLine)?.[2];
1471
+ const partTitle = TITLED_PART_HEADING_RE.exec(title)?.[2];
1125
1472
  if (partTitle !== undefined && isPartCrossReference(text, match.index, partTitle))
1126
1473
  continue;
1127
1474
  }
1475
+ const heading = line.includes('\t') ? tableRowHeading(line) : line;
1128
1476
  const offset = itemEntryOffset(text, match.index, heading);
1129
1477
  if (offset !== undefined)
1130
1478
  add(heading, offset);
1131
1479
  }
1132
1480
  ITEM_PART_HEADING_RE.lastIndex = 0;
1133
1481
  for (let match = ITEM_PART_HEADING_RE.exec(text); match !== null; match = ITEM_PART_HEADING_RE.exec(text)) {
1134
- const [, heading, itemCode, itemTitle = '', partTitle] = match;
1135
- if (heading === undefined || isWrappedProse(text, match.index, heading))
1482
+ const [, line, itemCode, itemTitle = '', partTitle] = match;
1483
+ if (line === undefined || isWrappedProse(text, match.index, line))
1136
1484
  continue;
1485
+ // On a table row the title is one field; the bound counts it alone (#257).
1486
+ const titleField = itemTitle.split('\t', 1)[0] ?? '';
1137
1487
  if (itemCode !== undefined &&
1138
- (!sameLineTitleFits(itemCode, itemTitle) || isRunTogetherToc(heading))) {
1488
+ (!sameLineTitleFits(itemCode, titleField) || isRunTogetherToc(line))) {
1139
1489
  continue;
1140
1490
  }
1141
1491
  if (partTitle !== undefined &&
1142
1492
  (!/^[A-Z]/.test(partTitle) || isPartCrossReference(text, match.index, partTitle))) {
1143
1493
  continue;
1144
1494
  }
1495
+ const heading = line.includes('\t') ? tableRowHeading(line) : line;
1145
1496
  const offset = itemEntryOffset(text, match.index, heading);
1146
1497
  if (offset !== undefined)
1147
1498
  add(heading, offset);
@@ -1353,11 +1704,12 @@ export function findPhrase(text, phrase, from, limit) {
1353
1704
  /**
1354
1705
  * A TOC page cell on a line of its own: a page number, a lettered
1355
1706
  * financial-statement page ("F-3"), or a lowercase roman front-matter page
1356
- * ("ii"), any of them optionally after a `Page` word ("Page 3"). Roman cells
1707
+ * ("ii"), any of them optionally after a `Page` word ("Page 3", "Page ii"), which
1708
+ * may list pages and ranges ({@link PAGE_WORD_CELL}: "Pages 29-32"). Roman cells
1357
1709
  * count only on their own line — at the end of a line set off by spaces,
1358
1710
  * "Part iv" would read as a page cell.
1359
1711
  */
1360
- const PAGE_CELL_LINE_RE = /^[^\S\n]*(?:(?:Page|PAGE)[^\S\n]+)?(?:\d{1,4}|[A-Z]-\d{1,3}|[ivxlc]{1,7})[^\S\n]*$/;
1712
+ const PAGE_CELL_LINE_RE = new RegExp(String.raw `^[^\S\n]*(?:${PAGE_WORD_CELL}|(?:(?:Page|PAGE)[^\S\n]+)?[ivxlc]{1,7}|${PAGE_NUMBER})[^\S\n]*$`);
1361
1713
  /**
1362
1714
  * A line opening on an Item or Part marker, bare, titled, or run straight into
1363
1715
  * its title ({@link TITLE_RUN_IN}, #180: "Item 1Financial Statements"). Non-global:
@@ -1383,28 +1735,92 @@ function nextContentLine(text, from) {
1383
1735
  }
1384
1736
  return;
1385
1737
  }
1738
+ /**
1739
+ * The last line before the one starting at `lineStart` that holds anything but
1740
+ * whitespace, or undefined when none does: {@link nextContentLine} read backward.
1741
+ */
1742
+ function previousContentLine(text, lineStart) {
1743
+ for (let end = lineStart - 1; end > 0;) {
1744
+ const start = text.lastIndexOf('\n', end - 1) + 1;
1745
+ const line = text.slice(start, end);
1746
+ if (/\S/.test(line))
1747
+ return line;
1748
+ end = start - 1;
1749
+ }
1750
+ return;
1751
+ }
1752
+ /**
1753
+ * Whether `line` is an entry row of a table of contents: it holds a tab, ends in
1754
+ * a page cell ({@link TOC_PAGE_TAIL_RE}), and has a field with text before the
1755
+ * cell, every such field holding a letter ("Operating Segment Results→→21"). A
1756
+ * figure row that ends in a short number has a field holding none
1757
+ * ("Revenue→→$→9,350→→$→812").
1758
+ */
1759
+ function isTocEntryRow(line) {
1760
+ if (!line.includes('\t') || !TOC_PAGE_TAIL_RE.test(line))
1761
+ return false;
1762
+ const fields = stripPageNumberTail(line)
1763
+ .split('\t')
1764
+ .filter((field) => /\S/.test(field));
1765
+ return fields.length > 0 && fields.every((field) => /\p{L}/u.test(field));
1766
+ }
1767
+ /**
1768
+ * Whether a table row (#257) holds a figure cell ahead of its last cell: a field
1769
+ * after its first, before the page cell {@link TOC_PAGE_TAIL_RE} reads, with no
1770
+ * letter. A figure row whose last figure is short ends like a TOC row ("Net
1771
+ * income→→$→295→→$→63", Apple's 10-Q 0001104659-05-003520), and as one it was
1772
+ * skipped as a section line; a TOC row's fields before its page cell are titles,
1773
+ * its first field a title, a marker, or a number ("1.→Business→4"). A line with
1774
+ * no tab holds no cells.
1775
+ */
1776
+ function holdsFigureCells(line) {
1777
+ if (!line.includes('\t'))
1778
+ return false;
1779
+ let first = true;
1780
+ for (const field of stripPageNumberTail(line).split('\t')) {
1781
+ if (!/\S/.test(field))
1782
+ continue;
1783
+ if (!first && !/\p{L}/u.test(field))
1784
+ return true;
1785
+ first = false;
1786
+ }
1787
+ return false;
1788
+ }
1386
1789
  /**
1387
1790
  * Whether `line`, whose newline ends just before `after`, is a TOC row. Its page
1388
1791
  * cell sits at its end ({@link TOC_PAGE_TAIL_RE}) or on the next line with
1389
- * content ({@link PAGE_CELL_LINE_RE}), spacer lines passed over. A line that is
1390
- * not itself a marker, followed directly by an Item/Part marker, is a title cell
1391
- * of a TOC with no page column ("Business Overview" above the next row's "Item
1392
- * 1A."). A marker line (a Part over its first Item) is a TOC row when that Item
1393
- * row is: the Item line ends in a page cell, or the line below it holds one or
1394
- * ends in one (a title cell, or a wrapped title: "Item 5. Market for…Issuer
1792
+ * content ({@link PAGE_CELL_LINE_RE}), spacer lines passed over. A line holding
1793
+ * no tab between two entry rows ({@link isTocEntryRow}) is a group label of the
1794
+ * table (#257): Intel's 10-K (0000050863-26-000011) sets "Management's
1795
+ * Discussion and Analysis" over "Operating Segment Results→→21" and under "Our
1796
+ * Business→→6", and as a prefix line it took `management's discussion` from the
1797
+ * body. Both neighbours are required, and entry rows rather than any line ending
1798
+ * in a page cell: figure rows, year headers, and page footers end in a short
1799
+ * number too, and a caption or heading sits by them. A line that
1800
+ * is not itself a marker, followed directly by an Item/Part marker, is a title
1801
+ * cell of a TOC with no page column ("Business Overview" above the next row's
1802
+ * "Item 1A."). A marker line (a Part over its first Item) is a TOC row when that
1803
+ * Item row is: the Item line ends in a page cell, or the line below it holds one
1804
+ * or ends in one (a title cell, or a wrapped title: "Item 5. Market for…Issuer
1395
1805
  * Purchases / of Equity Securities....... 12"), or — a bare marker — the line
1396
1806
  * below its title holds one ("PART IV / Item 15. / Exhibit and Financial
1397
1807
  * Statement Schedules / 93"). A body Part sits over its Item too, but prose, not
1398
- * a page cell, follows.
1808
+ * a page cell, follows. A table row ending in a short figure reads as a page
1809
+ * cell only when it holds no figure cells before it ({@link holdsFigureCells}).
1399
1810
  */
1400
1811
  function isTocRow(text, line, after) {
1401
- if (TOC_PAGE_TAIL_RE.test(line))
1812
+ if (TOC_PAGE_TAIL_RE.test(line) && !holdsFigureCells(line))
1402
1813
  return true;
1403
1814
  const item = nextContentLine(text, after);
1404
1815
  if (item === undefined)
1405
1816
  return false;
1406
1817
  if (PAGE_CELL_LINE_RE.test(item.line))
1407
1818
  return true;
1819
+ if (!line.includes('\t') && isTocEntryRow(item.line)) {
1820
+ const before = previousContentLine(text, after - 1 - line.length);
1821
+ if (before !== undefined && isTocEntryRow(before))
1822
+ return true;
1823
+ }
1408
1824
  if (!MARKER_LINE_RE.test(item.line.trim()))
1409
1825
  return false;
1410
1826
  if (!MARKER_LINE_RE.test(line.trim()))
@@ -1488,10 +1904,19 @@ export function isTocHeading(text, heading) {
1488
1904
  /**
1489
1905
  * Whether a heading's text is printed at its offset — not a bare marker, nor a
1490
1906
  * marker joined to a title printed on a later line ({@link titleAfterMarkerLine}).
1907
+ * The line is compared folded ({@link foldForHeadingMatch}), since a heading on
1908
+ * a table row joins its marker and title fields with one space where the row
1909
+ * has tabs ({@link tableRowHeading}).
1491
1910
  */
1492
1911
  function isTitledAt(text, heading) {
1493
- return (!BARE_MARKER_HEADING_RE.test(heading.heading) &&
1494
- text.startsWith(heading.heading, heading.offset));
1912
+ if (BARE_MARKER_HEADING_RE.test(heading.heading))
1913
+ return false;
1914
+ if (text.startsWith(heading.heading, heading.offset))
1915
+ return true;
1916
+ const newline = text.indexOf('\n', heading.offset);
1917
+ const line = text.slice(heading.offset, newline === -1 ? text.length : newline);
1918
+ return (line.includes('\t') &&
1919
+ foldForHeadingMatch(line).startsWith(foldForHeadingMatch(heading.heading)));
1495
1920
  }
1496
1921
  /** The span of a {@link ContentLine}, its newline excluded. */
1497
1922
  function lineSpan(line) {
@@ -1581,6 +2006,8 @@ function startsWithTitle(line, key, needle) {
1581
2006
  }
1582
2007
  /** The longest row label: a figure row's own, or one {@link labelsTableRow} reads past. */
1583
2008
  const MAX_ROW_LABEL_CHARS = 60;
2009
+ /** A lone currency or nil cell, or a table row of them (#257). */
2010
+ const NIL_CELLS_RE = /^[$€£\-–—](?:\t+[$€£\-–—])*$/;
1584
2011
  /**
1585
2012
  * Whether a line is a table row's figure cells: a lone currency or nil cell
1586
2013
  * (`$`, `-`, `–`, `—`), or a line whose text after its last letter holds a
@@ -1592,16 +2019,31 @@ const MAX_ROW_LABEL_CHARS = 60;
1592
2019
  * table set on one line (AMC Robotics' S-1 MD&A "Revenue" over "Three months
1593
2020
  * ended June 30, 2026 2025 $ Change …"), which a heading may sit over. A nil
1594
2021
  * cell is the only figure some rows print (Worthington Steel's "Goodwill" over
1595
- * "-"). One backward pass to the last letter.
2022
+ * "-"). A table row ({@link formatTableRows}, #257) sets its figures off by a
2023
+ * tab and may print only nil cells, alone ("—→—") or behind its label
2024
+ * ("Goodwill→—→—"), and its fields after the label are figures when none holds
2025
+ * a letter and one a digit, whatever ends the label ("Basic (A/B)→$→18.00"). A
2026
+ * field with a letter keeps a row of years a column header ("Three months ended
2027
+ * June 30,→2026→2025→$ Change"), which a heading sits over. One backward pass to
2028
+ * the last letter.
1596
2029
  */
1597
2030
  function isFigureRow(line) {
1598
2031
  const content = line.trim();
1599
- if (/^[$€£\-–—]$/.test(content))
2032
+ if (NIL_CELLS_RE.test(content))
1600
2033
  return true;
2034
+ const [label = '', ...cells] = content.split('\t');
2035
+ if (label.length <= MAX_ROW_LABEL_CHARS &&
2036
+ cells.some((cell) => /\d/.test(cell)) &&
2037
+ cells.every((cell) => !/\p{L}/u.test(cell))) {
2038
+ return true;
2039
+ }
1601
2040
  let lastLetter = content.length - 1;
1602
2041
  while (lastLetter >= 0 && !/\p{L}/u.test(content.charAt(lastLetter)))
1603
2042
  lastLetter--;
1604
2043
  const tail = content.slice(lastLetter + 1);
2044
+ if (lastLetter < MAX_ROW_LABEL_CHARS && tail.startsWith('\t') && NIL_CELLS_RE.test(tail.trim())) {
2045
+ return true;
2046
+ }
1605
2047
  if (!/\d/.test(tail))
1606
2048
  return false;
1607
2049
  if (lastLetter === -1)
@@ -1632,11 +2074,100 @@ function labelsTableRow(text, after) {
1632
2074
  const below = nextContentLine(text, next.end);
1633
2075
  return below !== undefined && isFigureRow(below.line);
1634
2076
  }
2077
+ /**
2078
+ * Whether a line whose label equals a `section` value labels a table row: its
2079
+ * own later fields are figures, read with a tab as the cell separator
2080
+ * (`content` a table row whose first tab is at `tab`, #257: "Revenue→→$→9,350"),
2081
+ * or {@link labelsTableRow} reads figures on the lines below it.
2082
+ */
2083
+ function labelsRow(text, content, tab, after) {
2084
+ return (tab !== -1 && isFigureRow(content.slice(tab))) || labelsTableRow(text, after);
2085
+ }
2086
+ /**
2087
+ * Whether the fields after a table row's label (`later`, from its first tab)
2088
+ * are column headers (#257): two or more fields with text, each a header cell
2089
+ * ({@link isColumnHeaderCell}). JPMorgan Chase's DEF 14A (0000019617-26-000096)
2090
+ * prints its voting table's header as "Proposal→Voting options→Vote
2091
+ * requirement→Effect of abstentions1→…", and as an equal line its first cell
2092
+ * took `proposal` from the proposal lines before it. A row with one later field
2093
+ * keeps its equal-line reading: a side heading beside its text ("Competition→We
2094
+ * face intense competition…") or a two-column row ("Proposal→Recommendation of
2095
+ * the Board", Apple's DEF 14A). One pass over the row's fields.
2096
+ */
2097
+ function isColumnHeaderRow(later) {
2098
+ let cells = 0;
2099
+ for (const field of later.split('\t')) {
2100
+ const cell = field.trim();
2101
+ if (cell.length === 0)
2102
+ continue;
2103
+ if (!isColumnHeaderCell(cell))
2104
+ return false;
2105
+ cells++;
2106
+ }
2107
+ return cells >= 2;
2108
+ }
2109
+ /**
2110
+ * Whether a trimmed table cell reads as a column header: at most
2111
+ * {@link MAX_ROW_LABEL_CHARS} characters, ending on no period (closing quotes
2112
+ * and brackets passed over), holding a letter and no digit before its last
2113
+ * letter — a footnote mark after it is passed ("Effect of abstentions1"). A
2114
+ * sentence, a longer cell, or a figure with its unit ("$193.5 billion (1)",
2115
+ * NVIDIA's DEF 14A 0001045810-26-000036) is not one.
2116
+ */
2117
+ function isColumnHeaderCell(cell) {
2118
+ if (cell.length > MAX_ROW_LABEL_CHARS || /\.["'”’)\]]*$/.test(cell))
2119
+ return false;
2120
+ let lastLetter = cell.length - 1;
2121
+ while (lastLetter >= 0 && !/\p{L}/u.test(cell.charAt(lastLetter)))
2122
+ lastLetter--;
2123
+ return lastLetter !== -1 && !/\d/.test(cell.slice(0, lastLetter));
2124
+ }
2125
+ /**
2126
+ * Whether a later field of a table row (`later`, from its first tab) opens on
2127
+ * `needle` with a figure after it, so the row ranks as a line starting with the
2128
+ * value (#257). JPMorgan Chase's DEF 14A (0000019617-26-000096) prints its
2129
+ * highlights as label-and-figure cells, "Revenue $182.4B Reported→…→Net income
2130
+ * $57.0B→…" over "$185.6B Managed1,2→…→Earnings per share (“EPS”) $20.02→…":
2131
+ * read by its first field alone, `net income` passed the firm-wide row for a
2132
+ * segment's and `earnings per share` landed nowhere. A field opening lowercase
2133
+ * is prose, a field equal to the value is a label cell, and a field with no
2134
+ * digit past the value is a label, not a figure ("Human capital management" in
2135
+ * a skills matrix). One pass over the row's fields.
2136
+ */
2137
+ function laterFieldLabelsFigure(later, needle) {
2138
+ for (const field of later.split('\t')) {
2139
+ const cell = field.trim();
2140
+ if (/^\p{Ll}/u.test(cell))
2141
+ continue;
2142
+ const key = headingKey(cell);
2143
+ if (key !== needle &&
2144
+ startsWithTitle(cell, key, needle) &&
2145
+ /\d/.test(key.slice(needle.length))) {
2146
+ return true;
2147
+ }
2148
+ }
2149
+ return false;
2150
+ }
2151
+ /**
2152
+ * A page reference alone on its line, parenthesized, in any case: "(page 34)",
2153
+ * "(See page 126)", "(pages 34 and 35)", "(pages 34-36, 40)", "(page A-1)", a
2154
+ * period after it optional. A merger proxy's summary prints one under each
2155
+ * entry's title (#275). Each separator opens on a comma or `and`, so a
2156
+ * whitespace run backtracks one character at a time; anchored, so linear.
2157
+ */
2158
+ const PAGE_REFERENCE_LINE_RE = new RegExp(String.raw `^[^\S\n]*\((?:see[^\S\n]+)?pages?[^\S\n]+${PAGE_SPAN}(?:[^\S\n]*(?:,[^\S\n]*(?:and[^\S\n]+)?|and[^\S\n]+)${PAGE_SPAN})*\)\.?[^\S\n]*$`, 'i');
1635
2159
  /**
1636
2160
  * The document line `section` names — a mixed-case subheading ("Liquidity and
1637
2161
  * Capital Resources") that {@link detectHeadings} never lists (#166). Lines
1638
- * compare by {@link headingKey} on both sides, in three tiers:
1639
- * 1. A line equal to the needle that labels no table row.
2162
+ * compare by {@link headingKey} on both sides, in four tiers:
2163
+ * 1. A line equal to the needle that labels no table row and heads no table's
2164
+ * columns. A summary entry — an equal line whose next line with content is a
2165
+ * page reference ({@link PAGE_REFERENCE_LINE_RE}) — lands only when no other
2166
+ * line of this tier does (#275): ADT's DEFM14A (0001628280-26-076564) prints
2167
+ * "Background of the Merger" over "(page 34)" and a one-sentence pointer, and
2168
+ * as the first equal line it took the value from the section at 145951. Its
2169
+ * link is not followed, since some filing agents link a page reference to the
2170
+ * top of the printed page rather than the section.
1640
2171
  * 2. Only when tier 1 finds none: an equal line that labels a table row
1641
2172
  * ({@link labelsTableRow}, #184). Every line equal to `revenue` in
1642
2173
  * Microsoft's 2004 10-K labels one (the selected-data row, a segment table's
@@ -1649,12 +2180,20 @@ function labelsTableRow(text, after) {
1649
2180
  * 2026") — unless it runs on into a longer title
1650
2181
  * ({@link continuesIntoLongerTitle}). Equality goes first because the prefix
1651
2182
  * tier alone would take a bullet such as "Competition among vendors…" ahead
1652
- * of the "Competition" heading.
2183
+ * of the "Competition" heading. A table row whose later field opens on the
2184
+ * needle and a figure ranks here too, landing at the row's start
2185
+ * ({@link laterFieldLabelsFigure}, #257).
2186
+ * 4. Only when none of those finds one: an equal line that heads a table's
2187
+ * columns and labels no row ({@link isColumnHeaderRow}, #257). JPMorgan
2188
+ * Chase's DEF 14A voting-table header "Proposal→Voting options→…" took
2189
+ * `proposal` from its "PROPOSAL 1:" lines; a figure-row label ranks ahead of
2190
+ * a prefix line (#184), so the header goes after it. Demoted rather than
2191
+ * skipped, a header that is the value's only line still lands.
1653
2192
  *
1654
2193
  * The result says which tier hit, because `section` ranks them apart (#177): a
1655
2194
  * tier-1 line (`equal: true`) ahead of a heading that only contains the value,
1656
- * a row label or prefix line (`equal: false`) after every heading. One pass
1657
- * yields all three, so a caller needing each pays for one scan.
2195
+ * a row label, prefix line, or column header (`equal: false`) after every
2196
+ * heading. One pass yields all four, so a caller needing each pays for one scan.
1658
2197
  *
1659
2198
  * Every tier also compares the line's key with a leading 20-F sub-item label
1660
2199
  * removed ({@link withoutSubItemLabel}, #175), so `risk factors` reaches "3D.
@@ -1671,15 +2210,17 @@ function labelsTableRow(text, after) {
1671
2210
  * on this Form 10-K…"), or is a TOC row ({@link isTocRow}). The first remaining
1672
2211
  * line of the best tier wins; its offset is the line's first non-blank
1673
2212
  * character. One forward pass over the text, the row-label test reading at most
1674
- * two content lines past an equal line; a line too short to key as the needle is
1675
- * never folded.
2213
+ * two content lines past an equal line and the summary-entry test one; a line
2214
+ * too short to key as the needle is never folded.
1676
2215
  */
1677
2216
  export function matchSectionLine(text, section) {
1678
2217
  const needle = headingKey(section);
1679
2218
  if (needle.length === 0)
1680
2219
  return;
2220
+ let summaryHit;
1681
2221
  let labelHit;
1682
2222
  let prefixHit;
2223
+ let headerHit;
1683
2224
  for (let start = 0; start <= text.length;) {
1684
2225
  const newline = text.indexOf('\n', start);
1685
2226
  const end = newline === -1 ? text.length : newline;
@@ -1689,17 +2230,21 @@ export function matchSectionLine(text, section) {
1689
2230
  // The key of a line whose marker runs into its title gains a space (#180).
1690
2231
  if (line.length + 1 < needle.length)
1691
2232
  continue;
1692
- const key = headingKey(line);
2233
+ const content = line.trimStart();
2234
+ // A table row (#257) is compared by its first field with text, its label.
2235
+ const tab = content.indexOf('\t');
2236
+ const label = tab === -1 ? line : content.slice(0, tab);
2237
+ const key = headingKey(label);
1693
2238
  const unlabelled = withoutSubItemLabel(key);
1694
2239
  const equal = key === needle || unlabelled === needle;
1695
2240
  if (!equal &&
1696
2241
  (prefixHit !== undefined ||
1697
- !(startsWithTitle(line, key, needle) ||
2242
+ !(startsWithTitle(label, key, needle) ||
1698
2243
  (unlabelled !== undefined &&
1699
- startsWithTitle(line.trimStart().replace(/^\S+\s+/, ''), unlabelled, needle))))) {
2244
+ startsWithTitle(label.trimStart().replace(/^\S+\s+/, ''), unlabelled, needle)) ||
2245
+ (tab !== -1 && laterFieldLabelsFigure(content.slice(tab), needle))))) {
1700
2246
  continue;
1701
2247
  }
1702
- const content = line.trimStart();
1703
2248
  if (/^\p{Ll}/u.test(content))
1704
2249
  continue;
1705
2250
  if (followsMidSentence(text, lineStart) || isWrappedProse(text, lineStart, content))
@@ -1709,12 +2254,19 @@ export function matchSectionLine(text, section) {
1709
2254
  const offset = lineStart + line.length - content.length;
1710
2255
  if (!equal)
1711
2256
  prefixHit = offset;
1712
- else if (!labelsTableRow(text, start))
1713
- return { equal, offset };
1714
- else
2257
+ else if (PAGE_REFERENCE_LINE_RE.test(nextContentLine(text, start)?.line ?? '')) {
2258
+ summaryHit ??= offset;
2259
+ }
2260
+ else if (labelsRow(text, content, tab, start))
1715
2261
  labelHit ??= offset;
2262
+ else if (tab !== -1 && isColumnHeaderRow(content.slice(tab)))
2263
+ headerHit ??= offset;
2264
+ else
2265
+ return { equal, offset };
1716
2266
  }
1717
- const fallback = labelHit ?? prefixHit;
2267
+ if (summaryHit !== undefined)
2268
+ return { equal: true, offset: summaryHit };
2269
+ const fallback = labelHit ?? prefixHit ?? headerHit;
1718
2270
  return fallback === undefined ? undefined : { equal: false, offset: fallback };
1719
2271
  }
1720
2272
  /** The offset of the line {@link matchSectionLine} lands on, from its best tier. */