@cyanheads/secedgar-mcp-server 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +23 -22
- package/CLAUDE.md +23 -22
- package/README.md +21 -9
- package/changelog/0.20.x/0.20.1.md +39 -0
- package/changelog/template.md +10 -8
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/company-search.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/company-search.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/compare-companies.tool.js +35 -21
- package/dist/mcp-server/tools/definitions/compare-companies.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.js +28 -5
- package/dist/mcp-server/tools/definitions/dataframe-query.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.js +4 -2
- package/dist/mcp-server/tools/definitions/fetch-frames.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/find-holders.tool.js +3 -3
- package/dist/mcp-server/tools/definitions/find-holders.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/get-beneficial-owners.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts +14 -2
- package/dist/mcp-server/tools/definitions/get-filing.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-filing.tool.js +220 -86
- package/dist/mcp-server/tools/definitions/get-filing.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-financials.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-financials.tool.js +82 -18
- package/dist/mcp-server/tools/definitions/get-financials.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js +3 -3
- package/dist/mcp-server/tools/definitions/get-fund-holdings.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts +18 -2
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js +299 -104
- package/dist/mcp-server/tools/definitions/get-insider-transactions.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js +5 -5
- package/dist/mcp-server/tools/definitions/get-institutional-holdings.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/get-material-events.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js +24 -22
- package/dist/mcp-server/tools/definitions/get-snapshot.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +17 -2
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-concepts.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-concepts.tool.js +16 -11
- package/dist/mcp-server/tools/definitions/search-concepts.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts +2 -0
- package/dist/mcp-server/tools/definitions/search-filings.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-filings.tool.js +88 -40
- package/dist/mcp-server/tools/definitions/search-filings.tool.js.map +1 -1
- package/dist/services/edgar/call-scope.d.ts +13 -1
- package/dist/services/edgar/call-scope.d.ts.map +1 -1
- package/dist/services/edgar/call-scope.js +4 -1
- package/dist/services/edgar/call-scope.js.map +1 -1
- package/dist/services/edgar/concept-map.d.ts.map +1 -1
- package/dist/services/edgar/concept-map.js +18 -2
- package/dist/services/edgar/concept-map.js.map +1 -1
- package/dist/services/edgar/concept-series.d.ts +32 -1
- package/dist/services/edgar/concept-series.d.ts.map +1 -1
- package/dist/services/edgar/concept-series.js +72 -1
- package/dist/services/edgar/concept-series.js.map +1 -1
- package/dist/services/edgar/edgar-api-service.d.ts +2 -12
- package/dist/services/edgar/edgar-api-service.d.ts.map +1 -1
- package/dist/services/edgar/edgar-api-service.js +18 -31
- package/dist/services/edgar/edgar-api-service.js.map +1 -1
- package/dist/services/edgar/filing-to-text.d.ts +20 -8
- package/dist/services/edgar/filing-to-text.d.ts.map +1 -1
- package/dist/services/edgar/filing-to-text.js +583 -51
- package/dist/services/edgar/filing-to-text.js.map +1 -1
- package/dist/services/edgar/fiscal-periods.d.ts +2 -0
- package/dist/services/edgar/fiscal-periods.d.ts.map +1 -1
- package/dist/services/edgar/fiscal-periods.js +1 -1
- package/dist/services/edgar/fiscal-periods.js.map +1 -1
- package/dist/services/edgar/types.d.ts +9 -6
- package/dist/services/edgar/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/server.json +3 -3
- package/skills/secedgar-guide/SKILL.md +16 -2
|
@@ -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',
|
|
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
|
-
/**
|
|
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")
|
|
876
|
-
* number
|
|
877
|
-
* the cell First Bancorp's 8-K TOC prints,
|
|
878
|
-
* deduping against its body Item and took
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
|
|
885
|
-
|
|
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 [,
|
|
1115
|
-
if (
|
|
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(
|
|
1464
|
+
if (isRunTogetherToc(line))
|
|
1119
1465
|
continue;
|
|
1120
1466
|
}
|
|
1121
1467
|
else {
|
|
1122
|
-
|
|
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(
|
|
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 [,
|
|
1135
|
-
if (
|
|
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,
|
|
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")
|
|
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 =
|
|
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
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
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
|
-
|
|
1494
|
-
|
|
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
|
-
* "-").
|
|
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 (
|
|
2032
|
+
if (NIL_CELLS_RE.test(content))
|
|
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))) {
|
|
1600
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,86 @@ 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
|
+
}
|
|
1635
2151
|
/**
|
|
1636
2152
|
* The document line `section` names — a mixed-case subheading ("Liquidity and
|
|
1637
2153
|
* Capital Resources") that {@link detectHeadings} never lists (#166). Lines
|
|
1638
|
-
* compare by {@link headingKey} on both sides, in
|
|
1639
|
-
* 1. A line equal to the needle that labels no table row
|
|
2154
|
+
* compare by {@link headingKey} on both sides, in four tiers:
|
|
2155
|
+
* 1. A line equal to the needle that labels no table row and heads no table's
|
|
2156
|
+
* columns.
|
|
1640
2157
|
* 2. Only when tier 1 finds none: an equal line that labels a table row
|
|
1641
2158
|
* ({@link labelsTableRow}, #184). Every line equal to `revenue` in
|
|
1642
2159
|
* Microsoft's 2004 10-K labels one (the selected-data row, a segment table's
|
|
@@ -1649,12 +2166,20 @@ function labelsTableRow(text, after) {
|
|
|
1649
2166
|
* 2026") — unless it runs on into a longer title
|
|
1650
2167
|
* ({@link continuesIntoLongerTitle}). Equality goes first because the prefix
|
|
1651
2168
|
* tier alone would take a bullet such as "Competition among vendors…" ahead
|
|
1652
|
-
* of the "Competition" heading.
|
|
2169
|
+
* of the "Competition" heading. A table row whose later field opens on the
|
|
2170
|
+
* needle and a figure ranks here too, landing at the row's start
|
|
2171
|
+
* ({@link laterFieldLabelsFigure}, #257).
|
|
2172
|
+
* 4. Only when none of those finds one: an equal line that heads a table's
|
|
2173
|
+
* columns and labels no row ({@link isColumnHeaderRow}, #257). JPMorgan
|
|
2174
|
+
* Chase's DEF 14A voting-table header "Proposal→Voting options→…" took
|
|
2175
|
+
* `proposal` from its "PROPOSAL 1:" lines; a figure-row label ranks ahead of
|
|
2176
|
+
* a prefix line (#184), so the header goes after it. Demoted rather than
|
|
2177
|
+
* skipped, a header that is the value's only line still lands.
|
|
1653
2178
|
*
|
|
1654
2179
|
* The result says which tier hit, because `section` ranks them apart (#177): a
|
|
1655
2180
|
* tier-1 line (`equal: true`) ahead of a heading that only contains the value,
|
|
1656
|
-
* a row label
|
|
1657
|
-
* yields all
|
|
2181
|
+
* a row label, prefix line, or column header (`equal: false`) after every
|
|
2182
|
+
* heading. One pass yields all four, so a caller needing each pays for one scan.
|
|
1658
2183
|
*
|
|
1659
2184
|
* Every tier also compares the line's key with a leading 20-F sub-item label
|
|
1660
2185
|
* removed ({@link withoutSubItemLabel}, #175), so `risk factors` reaches "3D.
|
|
@@ -1680,6 +2205,7 @@ export function matchSectionLine(text, section) {
|
|
|
1680
2205
|
return;
|
|
1681
2206
|
let labelHit;
|
|
1682
2207
|
let prefixHit;
|
|
2208
|
+
let headerHit;
|
|
1683
2209
|
for (let start = 0; start <= text.length;) {
|
|
1684
2210
|
const newline = text.indexOf('\n', start);
|
|
1685
2211
|
const end = newline === -1 ? text.length : newline;
|
|
@@ -1689,17 +2215,21 @@ export function matchSectionLine(text, section) {
|
|
|
1689
2215
|
// The key of a line whose marker runs into its title gains a space (#180).
|
|
1690
2216
|
if (line.length + 1 < needle.length)
|
|
1691
2217
|
continue;
|
|
1692
|
-
const
|
|
2218
|
+
const content = line.trimStart();
|
|
2219
|
+
// A table row (#257) is compared by its first field with text, its label.
|
|
2220
|
+
const tab = content.indexOf('\t');
|
|
2221
|
+
const label = tab === -1 ? line : content.slice(0, tab);
|
|
2222
|
+
const key = headingKey(label);
|
|
1693
2223
|
const unlabelled = withoutSubItemLabel(key);
|
|
1694
2224
|
const equal = key === needle || unlabelled === needle;
|
|
1695
2225
|
if (!equal &&
|
|
1696
2226
|
(prefixHit !== undefined ||
|
|
1697
|
-
!(startsWithTitle(
|
|
2227
|
+
!(startsWithTitle(label, key, needle) ||
|
|
1698
2228
|
(unlabelled !== undefined &&
|
|
1699
|
-
startsWithTitle(
|
|
2229
|
+
startsWithTitle(label.trimStart().replace(/^\S+\s+/, ''), unlabelled, needle)) ||
|
|
2230
|
+
(tab !== -1 && laterFieldLabelsFigure(content.slice(tab), needle))))) {
|
|
1700
2231
|
continue;
|
|
1701
2232
|
}
|
|
1702
|
-
const content = line.trimStart();
|
|
1703
2233
|
if (/^\p{Ll}/u.test(content))
|
|
1704
2234
|
continue;
|
|
1705
2235
|
if (followsMidSentence(text, lineStart) || isWrappedProse(text, lineStart, content))
|
|
@@ -1709,12 +2239,14 @@ export function matchSectionLine(text, section) {
|
|
|
1709
2239
|
const offset = lineStart + line.length - content.length;
|
|
1710
2240
|
if (!equal)
|
|
1711
2241
|
prefixHit = offset;
|
|
1712
|
-
else if (
|
|
1713
|
-
return { equal, offset };
|
|
1714
|
-
else
|
|
2242
|
+
else if (labelsRow(text, content, tab, start))
|
|
1715
2243
|
labelHit ??= offset;
|
|
2244
|
+
else if (tab !== -1 && isColumnHeaderRow(content.slice(tab)))
|
|
2245
|
+
headerHit ??= offset;
|
|
2246
|
+
else
|
|
2247
|
+
return { equal, offset };
|
|
1716
2248
|
}
|
|
1717
|
-
const fallback = labelHit ?? prefixHit;
|
|
2249
|
+
const fallback = labelHit ?? prefixHit ?? headerHit;
|
|
1718
2250
|
return fallback === undefined ? undefined : { equal: false, offset: fallback };
|
|
1719
2251
|
}
|
|
1720
2252
|
/** The offset of the line {@link matchSectionLine} lands on, from its best tier. */
|