officeparser 7.2.3 → 7.3.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.
- package/README.md +148 -9
- package/dist/OfficeGenerator.js +4 -0
- package/dist/OfficeParser.d.ts +2 -0
- package/dist/OfficeParser.js +6 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +3 -2
- package/dist/generators/BaseGenerator.d.ts +11 -0
- package/dist/generators/BaseGenerator.js +29 -0
- package/dist/generators/CsvGenerator.d.ts +9 -1
- package/dist/generators/CsvGenerator.js +24 -14
- package/dist/generators/EpubGenerator.d.ts +18 -0
- package/dist/generators/EpubGenerator.js +242 -0
- package/dist/generators/HtmlGenerator.d.ts +12 -0
- package/dist/generators/HtmlGenerator.js +266 -51
- package/dist/generators/MarkdownGenerator.d.ts +16 -0
- package/dist/generators/MarkdownGenerator.js +173 -24
- package/dist/generators/PdfGenerator.js +32 -0
- package/dist/generators/RtfGenerator.js +12 -15
- package/dist/generators/TextGenerator.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/officeparser.browser.d.ts +143 -6
- package/dist/officeparser.browser.iife.js +284 -188
- package/dist/officeparser.browser.mjs +284 -188
- package/dist/officeparser.browser.slim.d.ts +143 -6
- package/dist/officeparser.browser.slim.iife.js +284 -188
- package/dist/officeparser.browser.slim.mjs +284 -188
- package/dist/parsers/EpubParser.d.ts +8 -0
- package/dist/parsers/EpubParser.js +217 -0
- package/dist/parsers/HtmlParser.js +284 -20
- package/dist/parsers/MarkdownParser.js +424 -33
- package/dist/parsers/PdfParser.js +4 -1
- package/dist/sbom.cdx.json +1695 -0
- package/dist/types.d.ts +142 -6
- package/dist/types.js +2 -0
- package/dist/utils/errorUtils.js +3 -2
- package/dist/utils/sanitize.d.ts +99 -0
- package/dist/utils/sanitize.js +228 -0
- package/dist/utils/zipUtils.js +76 -26
- package/package.json +9 -5
|
@@ -41,6 +41,8 @@ export declare enum OfficeErrorType {
|
|
|
41
41
|
ZIP_ENTRY_INVALID_SIZE = "ZIP_ENTRY_INVALID_SIZE",
|
|
42
42
|
/** ZIP uncompressed size limit exceeded */
|
|
43
43
|
ZIP_SIZE_LIMIT_EXCEEDED = "ZIP_SIZE_LIMIT_EXCEEDED",
|
|
44
|
+
/** Document element/structure nesting exceeded the safe recursion depth */
|
|
45
|
+
MAX_NESTING_DEPTH_EXCEEDED = "MAX_NESTING_DEPTH_EXCEEDED",
|
|
44
46
|
/** Embedding call timed out */
|
|
45
47
|
EMBEDDING_TIMEOUT = "EMBEDDING_TIMEOUT"
|
|
46
48
|
}
|
|
@@ -398,7 +400,7 @@ export interface OfficeIssue {
|
|
|
398
400
|
/**
|
|
399
401
|
* The result of a document conversion operation.
|
|
400
402
|
*/
|
|
401
|
-
export type ConversionValue<D extends UniversalGeneratorFormat> = D extends "pdf" ? Uint8Array | string : D extends "chunks" ? OfficeChunk[] : D extends "csv" ? string | Uint8Array : string;
|
|
403
|
+
export type ConversionValue<D extends UniversalGeneratorFormat> = D extends "pdf" ? Uint8Array | string : D extends "chunks" ? OfficeChunk[] : D extends "csv" ? string | Uint8Array : D extends "epub" ? Uint8Array : string;
|
|
402
404
|
export interface ConversionResult<D extends UniversalGeneratorFormat> {
|
|
403
405
|
/** The actual generated content (HTML, Markdown, Text, OfficeChunk[], etc.). */
|
|
404
406
|
value: ConversionValue<D>;
|
|
@@ -408,7 +410,7 @@ export interface ConversionResult<D extends UniversalGeneratorFormat> {
|
|
|
408
410
|
/**
|
|
409
411
|
* Universal formats supported by all source types for generation.
|
|
410
412
|
*/
|
|
411
|
-
export type UniversalGeneratorFormat = "text" | "md" | "html" | "pdf" | "csv" | "rtf" | "chunks";
|
|
413
|
+
export type UniversalGeneratorFormat = "text" | "md" | "html" | "pdf" | "csv" | "rtf" | "chunks" | "epub";
|
|
412
414
|
/**
|
|
413
415
|
* Allowed destination formats for a given source type.
|
|
414
416
|
* Currently, all generators are universal across all source formats.
|
|
@@ -603,15 +605,64 @@ export interface HtmlInjectionConfig {
|
|
|
603
605
|
/** Raw HTML injected immediately before the closing </body> tag */
|
|
604
606
|
bodyEnd?: string;
|
|
605
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Granular control over which parts of the full HTML "document envelope" are emitted.
|
|
610
|
+
* Shorthand: `standalone: true` == every part on (a complete document); `standalone: false` ==
|
|
611
|
+
* every part off (a bare content fragment). When an object is passed, any field you omit
|
|
612
|
+
* defaults to its "on" (standalone) value.
|
|
613
|
+
*/
|
|
614
|
+
export interface StandaloneConfig {
|
|
615
|
+
/**
|
|
616
|
+
* Wrap the output in `<!DOCTYPE html><html><head>…</head><body>…</body></html>`.
|
|
617
|
+
* When false, only the inner content fragment is emitted. Defaults to true.
|
|
618
|
+
*/
|
|
619
|
+
document?: boolean;
|
|
620
|
+
/**
|
|
621
|
+
* Emit `<title>` and `<meta>` tags (author, description, dates, custom properties) in the head.
|
|
622
|
+
* Only meaningful when `document` is true. Defaults to true.
|
|
623
|
+
*/
|
|
624
|
+
metaTags?: boolean;
|
|
625
|
+
/**
|
|
626
|
+
* How the library's built-in CSS is delivered:
|
|
627
|
+
* - `'full'` — the complete premium stylesheet using global selectors (`body`, `h1`, `table`, …).
|
|
628
|
+
* This is what `standalone: true` has always emitted.
|
|
629
|
+
* - `'scoped'` — the same styling, scoped under the fragment's container via CSS `@scope` so it
|
|
630
|
+
* cannot leak into a host page's own styles. Requires a modern browser engine (Chrome 118+,
|
|
631
|
+
* Safari 17.4+, Firefox 128+).
|
|
632
|
+
* - `'none'` — no stylesheet is emitted; the host page (or EPUB reader, or rich-text editor)
|
|
633
|
+
* supplies its own styling.
|
|
634
|
+
* The boolean shorthand for `standalone` maps `true` → `'full'`, `false` → `'none'`.
|
|
635
|
+
* Defaults to `'full'`.
|
|
636
|
+
*/
|
|
637
|
+
styles?: "full" | "scoped" | "none";
|
|
638
|
+
/**
|
|
639
|
+
* Emit injected `<script>` tags: the Chart.js loader (when `includeCharts` is true and charts
|
|
640
|
+
* are present) and the spreadsheet interactivity script. Defaults to true.
|
|
641
|
+
*/
|
|
642
|
+
scripts?: boolean;
|
|
643
|
+
/**
|
|
644
|
+
* Apply `injections.headStart` / `injections.headEnd`. Only meaningful when `document` is true
|
|
645
|
+
* (there is no `<head>` to inject into otherwise). Defaults to true.
|
|
646
|
+
*/
|
|
647
|
+
headInjections?: boolean;
|
|
648
|
+
/**
|
|
649
|
+
* Apply `injections.bodyStart` / `injections.bodyEnd`. Applies even when generating a bare
|
|
650
|
+
* fragment (`document: false`), since these wrap body *content*, not the document shell.
|
|
651
|
+
* Defaults to true.
|
|
652
|
+
*/
|
|
653
|
+
bodyInjections?: boolean;
|
|
654
|
+
}
|
|
606
655
|
/**
|
|
607
656
|
* Configuration options for HTML generation.
|
|
608
657
|
*/
|
|
609
658
|
export interface HtmlGeneratorConfig {
|
|
610
659
|
/**
|
|
611
660
|
* Whether to wrap the output in a full HTML document structure (e.g., <html>, <head>, etc.).
|
|
661
|
+
* Pass an object instead of a boolean for granular control over individual parts of the
|
|
662
|
+
* envelope (document shell, meta tags, styles, scripts, injections) - see `StandaloneConfig`.
|
|
612
663
|
* Defaults to true.
|
|
613
664
|
*/
|
|
614
|
-
standalone?: boolean;
|
|
665
|
+
standalone?: boolean | StandaloneConfig;
|
|
615
666
|
/**
|
|
616
667
|
* URL for the Chart.js library to use when 'includeCharts' is true.
|
|
617
668
|
* Defaults to 'https://cdn.jsdelivr.net/npm/chart.js'.
|
|
@@ -1032,11 +1083,11 @@ export interface OfficeChunk {
|
|
|
1032
1083
|
/**
|
|
1033
1084
|
* Supported file types for parsing.
|
|
1034
1085
|
*/
|
|
1035
|
-
export type SupportedFileType = "docx" | "pptx" | "xlsx" | "odt" | "odp" | "ods" | "pdf" | "rtf" | "md" | "html" | "csv";
|
|
1086
|
+
export type SupportedFileType = "docx" | "pptx" | "xlsx" | "odt" | "odp" | "ods" | "pdf" | "rtf" | "md" | "html" | "csv" | "epub";
|
|
1036
1087
|
/**
|
|
1037
1088
|
* Types of content nodes in the AST.
|
|
1038
1089
|
*/
|
|
1039
|
-
export type OfficeContentNodeType = "paragraph" | "heading" | "table" | "list" | "text" | "image" | "chart" | "drawing" | "slide" | "note" | "sheet" | "row" | "cell" | "page" | "break" | "code" | "comment" | "header" | "footer" | "slideMaster";
|
|
1090
|
+
export type OfficeContentNodeType = "paragraph" | "heading" | "table" | "list" | "text" | "image" | "chart" | "drawing" | "slide" | "note" | "sheet" | "row" | "cell" | "page" | "break" | "code" | "comment" | "header" | "footer" | "slideMaster" | "embed" | "admonition" | "definitionList" | "definitionTerm" | "definitionDescription";
|
|
1040
1091
|
/**
|
|
1041
1092
|
* Supported MIME types for attachments.
|
|
1042
1093
|
*/
|
|
@@ -1230,6 +1281,10 @@ export interface ListMetadata {
|
|
|
1230
1281
|
style?: string;
|
|
1231
1282
|
/** Unique anchor IDs for internal linking. */
|
|
1232
1283
|
anchorIds?: string[];
|
|
1284
|
+
/** True when this list item is a GFM task-list item (checkbox), regardless of checked state. */
|
|
1285
|
+
isTask?: boolean;
|
|
1286
|
+
/** Checked state for a task-list item. Only meaningful when isTask is true. */
|
|
1287
|
+
checked?: boolean;
|
|
1233
1288
|
}
|
|
1234
1289
|
/**
|
|
1235
1290
|
* Metadata for a table cell (primarily used in Excel/spreadsheet parsing).
|
|
@@ -1269,6 +1324,11 @@ export interface CellMetadata {
|
|
|
1269
1324
|
export interface TableMetadata {
|
|
1270
1325
|
/** Unique anchor IDs for internal linking. */
|
|
1271
1326
|
anchorIds?: string[];
|
|
1327
|
+
/**
|
|
1328
|
+
* Layout alignment of the table on the page (e.g. inscript-editor's `CustomTable`).
|
|
1329
|
+
* @example 'center'
|
|
1330
|
+
*/
|
|
1331
|
+
align?: "left" | "center" | "right";
|
|
1272
1332
|
}
|
|
1273
1333
|
/**
|
|
1274
1334
|
* Metadata for a chart node in the document.
|
|
@@ -1309,6 +1369,42 @@ export interface ImageMetadata {
|
|
|
1309
1369
|
url?: string;
|
|
1310
1370
|
/** Unique anchor IDs for internal linking. */
|
|
1311
1371
|
anchorIds?: string[];
|
|
1372
|
+
/**
|
|
1373
|
+
* Display width of the image (e.g. inscript-editor's `CustomImage`), as a CSS length or percentage.
|
|
1374
|
+
* @example "50%"
|
|
1375
|
+
*/
|
|
1376
|
+
width?: string;
|
|
1377
|
+
/**
|
|
1378
|
+
* Layout alignment of the image (e.g. inscript-editor's `CustomImage`).
|
|
1379
|
+
* @example 'center'
|
|
1380
|
+
*/
|
|
1381
|
+
align?: "left" | "center" | "right";
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Metadata for an embedded external media node (e.g. a YouTube video).
|
|
1385
|
+
* Markdown has no native syntax for this - see `MarkdownGenerator`'s `embed` case.
|
|
1386
|
+
*/
|
|
1387
|
+
export interface EmbedMetadata {
|
|
1388
|
+
/** The kind of embed. Only 'youtube' is supported today; the shape is generic for future providers. */
|
|
1389
|
+
embedType: "youtube";
|
|
1390
|
+
/** The provider-specific video ID (e.g. the 11-character YouTube video ID). */
|
|
1391
|
+
videoId: string;
|
|
1392
|
+
/** The original/canonical URL of the embedded media, if known. */
|
|
1393
|
+
url?: string;
|
|
1394
|
+
/** Display width, as a CSS length or percentage. */
|
|
1395
|
+
width?: string;
|
|
1396
|
+
/** Layout alignment of the embed. */
|
|
1397
|
+
align?: "left" | "center" | "right";
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Metadata for an admonition/alert node (e.g. GitHub's `> [!NOTE]` or GLFM's `:::note`).
|
|
1401
|
+
* `MarkdownParser` accepts both syntaxes; `MarkdownGenerator` only ever writes the
|
|
1402
|
+
* blockquote form. Children are block content (paragraphs) wrapped by the admonition.
|
|
1403
|
+
*/
|
|
1404
|
+
export interface AdmonitionMetadata {
|
|
1405
|
+
admonitionType: "note" | "tip" | "important" | "warning" | "caution";
|
|
1406
|
+
/** Optional custom title; falls back to the type label. */
|
|
1407
|
+
title?: string;
|
|
1312
1408
|
}
|
|
1313
1409
|
/**
|
|
1314
1410
|
* Metadata for PDF page nodes.
|
|
@@ -1339,6 +1435,25 @@ export interface TextMetadata {
|
|
|
1339
1435
|
* - 'external': Link to an external URL
|
|
1340
1436
|
*/
|
|
1341
1437
|
linkType?: "internal" | "external";
|
|
1438
|
+
/**
|
|
1439
|
+
* When set, this text is an abbreviation and this is its full-form expansion,
|
|
1440
|
+
* rendered as `<abbr title="...">`. Populated from Markdown Extra's
|
|
1441
|
+
* `*[HTML]: Hypertext Markup Language` syntax or an HTML `<abbr>` tag.
|
|
1442
|
+
*/
|
|
1443
|
+
abbreviationTitle?: string;
|
|
1444
|
+
/**
|
|
1445
|
+
* When set, this text is a Pandoc/MultiMarkdown-style citation reference
|
|
1446
|
+
* (`[@citekey]`), and this is the bare citekey (e.g. "smith2024"). Bibliography
|
|
1447
|
+
* resolution (author/year display, .bib management) is left to the consuming app.
|
|
1448
|
+
*/
|
|
1449
|
+
citationKey?: string;
|
|
1450
|
+
/**
|
|
1451
|
+
* True when this is an Obsidian-style wikilink (`[[page]]` / `[[page|alias]]`).
|
|
1452
|
+
* `link` holds the bare page name and `linkType` is always 'internal'; the
|
|
1453
|
+
* per-workspace enable/disable toggle lives in markdownwriter, not here -
|
|
1454
|
+
* officeParser always parses/generates the syntax.
|
|
1455
|
+
*/
|
|
1456
|
+
wikilink?: boolean;
|
|
1342
1457
|
}
|
|
1343
1458
|
/**
|
|
1344
1459
|
* Metadata for note nodes (footnotes/endnotes).
|
|
@@ -1392,6 +1507,12 @@ export interface CodeMetadata {
|
|
|
1392
1507
|
language?: string;
|
|
1393
1508
|
/** Unique anchor IDs for internal linking. */
|
|
1394
1509
|
anchorIds?: string[];
|
|
1510
|
+
/**
|
|
1511
|
+
* When set, this node is a LaTeX math expression rather than a code block. `node.text`
|
|
1512
|
+
* holds the bare LaTeX (delimiters excluded); 'inline' round-trips as `$...$`,
|
|
1513
|
+
* 'block' as `$$...$$`. Matches inscript-editor's math node (Roadmap Step 11.5).
|
|
1514
|
+
*/
|
|
1515
|
+
math?: "inline" | "block";
|
|
1395
1516
|
}
|
|
1396
1517
|
/**
|
|
1397
1518
|
* Metadata for a comment/annotation.
|
|
@@ -1411,7 +1532,7 @@ export interface HeaderFooterMetadata {
|
|
|
1411
1532
|
/**
|
|
1412
1533
|
* Union type for content metadata.
|
|
1413
1534
|
*/
|
|
1414
|
-
export type ContentMetadata = SlideMetadata | SheetMetadata | HeadingMetadata | ListMetadata | CellMetadata | ImageMetadata | ChartMetadata | PageMetadata | ParagraphMetadata | TextMetadata | NoteMetadata | BreakMetadata | CodeMetadata | CommentMetadata | HeaderFooterMetadata | TableMetadata | undefined;
|
|
1535
|
+
export type ContentMetadata = SlideMetadata | SheetMetadata | HeadingMetadata | ListMetadata | CellMetadata | ImageMetadata | ChartMetadata | PageMetadata | ParagraphMetadata | TextMetadata | NoteMetadata | BreakMetadata | CodeMetadata | CommentMetadata | HeaderFooterMetadata | TableMetadata | EmbedMetadata | AdmonitionMetadata | undefined;
|
|
1415
1536
|
/**
|
|
1416
1537
|
* Represents a node in the document content tree.
|
|
1417
1538
|
* This is the core building block of the parsed document structure.
|
|
@@ -1573,6 +1694,21 @@ export type OfficeContentNode = BaseContentNode & ({
|
|
|
1573
1694
|
} | {
|
|
1574
1695
|
type: "slideMaster";
|
|
1575
1696
|
metadata?: SlideMetadata;
|
|
1697
|
+
} | {
|
|
1698
|
+
type: "embed";
|
|
1699
|
+
metadata?: EmbedMetadata;
|
|
1700
|
+
} | {
|
|
1701
|
+
type: "admonition";
|
|
1702
|
+
metadata?: AdmonitionMetadata;
|
|
1703
|
+
} | {
|
|
1704
|
+
type: "definitionList";
|
|
1705
|
+
metadata?: undefined;
|
|
1706
|
+
} | {
|
|
1707
|
+
type: "definitionTerm";
|
|
1708
|
+
metadata?: undefined;
|
|
1709
|
+
} | {
|
|
1710
|
+
type: "definitionDescription";
|
|
1711
|
+
metadata?: undefined;
|
|
1576
1712
|
});
|
|
1577
1713
|
/**
|
|
1578
1714
|
* Structured information extracted from a chart.
|
|
@@ -1877,6 +2013,7 @@ export declare class OfficeParser {
|
|
|
1877
2013
|
* - `.csv` → CsvParser
|
|
1878
2014
|
* - `.md` → MarkdownParser
|
|
1879
2015
|
* - `.html` → HtmlParser
|
|
2016
|
+
* - `.epub` → EpubParser
|
|
1880
2017
|
*
|
|
1881
2018
|
* @param file - File path (string), Buffer, or ArrayBuffer containing the document
|
|
1882
2019
|
* @param config - Optional configuration object (defaults applied for all omitted options)
|