officeparser 7.6.2 → 7.8.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.
@@ -415,6 +415,18 @@ export interface HtmlParserConfig {
415
415
  * Defaults to false.
416
416
  */
417
417
  preserveIframes?: boolean | string[];
418
+ /**
419
+ * Import ambiguous "folk" embed forms in Markdown as embeds: a standalone Obsidian-style image
420
+ * whose URL is a YouTube link (`![](https://youtube.com/watch?v=ID)`), and the clickable
421
+ * thumbnail-link (`[![alt](https://img.youtube.com/vi/ID/…)](watch-url)`). Both become a
422
+ * `embedType: 'youtube'` embed (rendered from the validated id, so it is safe). Off by default:
423
+ * auto-upgrading an image/link to an embed is a heuristic that could mangle a genuinely-intended
424
+ * image link, so a consumer opts in. The unambiguous forms (`<div data-youtube-video>`, a bare
425
+ * YouTube `<iframe>`, the `::youtube` directive) are always recognized, independent of this flag.
426
+ *
427
+ * Defaults to false.
428
+ */
429
+ embedFolkForms?: boolean;
418
430
  }
419
431
  /**
420
432
  * Maps an input format string to its corresponding format-specific parser configuration, mirroring
@@ -883,6 +895,15 @@ export interface HtmlGeneratorConfig {
883
895
  * `HtmlParser` reads every shape this emits, so output stays self-round-trippable.
884
896
  */
885
897
  sourceAttributes?: boolean;
898
+ /**
899
+ * Emit a generic (non-YouTube) iframe embed as a gated placeholder,
900
+ * `<div data-embed-gated data-embed-src="…" …>`, instead of a live `<iframe>`. The gated shape
901
+ * never auto-loads its src: an editor renders a click-to-load placeholder from it, and
902
+ * `HtmlParser` reads it back to the same `embed` node. The src is scheme-checked (`sanitizeUrl`)
903
+ * on emit. Off by default; the default output (a live `<iframe>`) is unchanged. YouTube embeds
904
+ * are unaffected (they already render from a validated id).
905
+ */
906
+ gatedEmbeds?: boolean;
886
907
  }
887
908
  /**
888
909
  * Configuration options for PDF generation.
@@ -1039,6 +1060,49 @@ export interface CsvGeneratorConfig {
1039
1060
  * historical output exactly (every feature on, GitHub-style admonitions).
1040
1061
  */
1041
1062
  export type MarkdownDialectPreset = "extended" | "github" | "gitlab" | "obsidian" | "pandoc" | "commonmark";
1063
+ /** Admonition syntax: `'blockquote'` = GitHub `> [!NOTE]`, `'fence'` = GitLab `:::note`,
1064
+ * `'fence-attribute'` = Pandoc `::: {.note}`, `'none'` = plain bold-labeled blockquote. */
1065
+ export type AdmonitionSyntax = "blockquote" | "fence" | "fence-attribute" | "none";
1066
+ /** `==text==` highlight (`'equals'`), or `'none'` to disable. */
1067
+ export type HighlightSyntax = "equals" | "none";
1068
+ /** GFM `~~text~~` strikethrough (`'tilde'`), or `'none'`. */
1069
+ export type StrikethroughSyntax = "tilde" | "none";
1070
+ /** `Term`/`: Description` definition lists (`'colon'`), or `'none'`. */
1071
+ export type DefinitionListSyntax = "colon" | "none";
1072
+ /** `[^id]` footnotes (`'caret'`), or `'none'`. */
1073
+ export type FootnoteSyntax = "caret" | "none";
1074
+ /** `[@citekey]` citations (`'at'`), or `'none'`. */
1075
+ export type CitationSyntax = "at" | "none";
1076
+ /** `[[Page]]` wikilinks (`'double-bracket'`), or `'none'`. */
1077
+ export type WikilinkSyntax = "double-bracket" | "none";
1078
+ /** `{width=50%}` attribute lists (`'brace'`), or `'none'`. */
1079
+ export type AttributeListSyntax = "brace" | "none";
1080
+ /**
1081
+ * How an `embed` node is written to Markdown:
1082
+ * - `'html'` (default): the single-line `<div data-youtube-video="ID">` / `<iframe src=...>` block
1083
+ * this library has always emitted. Round-trips through officeParser, but renders as an invisible
1084
+ * empty box on GitHub.
1085
+ * - `'directive'`: a remark-directive leaf, `::youtube[Label]{id=... width=... align=...}` /
1086
+ * `::embed[Label]{src=... width=... height=... align=...}`. Round-trips within an editor that
1087
+ * understands it; renders verbatim (not just the label) on GitHub, so it is an editor format, not
1088
+ * a GitHub-interop one.
1089
+ * - `'link'`: a plain `[YouTube](url)` / `[Embed](url)`.
1090
+ * - `'thumbnail'`: a YouTube-only clickable thumbnail `[![Label](.../vi/ID/hqdefault.jpg)](watch)`,
1091
+ * the best GitHub degrade; a non-YouTube embed falls back to `'link'`.
1092
+ */
1093
+ export type EmbedSyntax = "html" | "directive" | "link" | "thumbnail";
1094
+ /**
1095
+ * @deprecated Legacy flavor names for `MarkdownDialectConfig.admonitions`. Use the syntax names
1096
+ * instead: `'github'` -> `'blockquote'`, `'gitlab'` -> `'fence'`, `'pandoc'` -> `'fence-attribute'`.
1097
+ * These aliases still resolve to the same output and will be removed in the next major version.
1098
+ */
1099
+ export type DeprecatedAdmonitionFlavor = "github" | "gitlab" | "pandoc";
1100
+ /**
1101
+ * @deprecated Boolean toggles for dialect capability fields are deprecated in favor of the
1102
+ * syntax-name unions: `true` maps to that field's on-value (e.g. `'tilde'`), `false` maps to
1103
+ * `'none'`. Booleans keep working via coercion and will be removed in the next major version.
1104
+ */
1105
+ export type DeprecatedDialectToggle = boolean;
1042
1106
  /**
1043
1107
  * Granular control over which native Markdown syntax the generator emits for constructs that
1044
1108
  * differ across real-world dialects (e.g. GitHub's `> [!NOTE]` vs GitLab's `:::note` vs Pandoc's
@@ -1050,25 +1114,60 @@ export type MarkdownDialectPreset = "extended" | "github" | "gitlab" | "obsidian
1050
1114
  export interface MarkdownDialectConfig {
1051
1115
  /** Base preset any omitted field inherits from. Defaults to 'extended'. */
1052
1116
  extends?: MarkdownDialectPreset;
1053
- /** Admonition syntax: GitHub `> [!NOTE]`, GitLab `:::note`, Pandoc `::: {.note}`, or `'none'`
1054
- * to degrade to a plain bold-labeled blockquote with no special marker. */
1055
- admonitions?: "github" | "gitlab" | "pandoc" | "none";
1056
- /** Markdown Extra/Pandoc-style `Term\n: Description` definition lists. */
1057
- definitionLists?: boolean;
1058
- /** `[^id]` footnote references/definitions. When false, note content is inlined as a
1059
- * parenthetical right at the reference point instead of using footnote syntax. */
1060
- footnotes?: boolean;
1061
- /** Pandoc-style `[@citekey]` citations. When false, emits `[citekey]` (brackets, no `@`). */
1062
- citations?: boolean;
1063
- /** Obsidian-style `[[Page]]`/`[[Page|Alias]]` wikilinks. When false, falls back to a plain
1064
- * `[text](url)` link using the same target. */
1065
- wikilinks?: boolean;
1066
- /** Inline `$...$`/block `$$...$$` math delimiters, or `'none'` for bare LaTeX text. */
1117
+ /**
1118
+ * Admonition syntax: `'blockquote'` = GitHub `> [!NOTE]`, `'fence'` = GitLab `:::note`,
1119
+ * `'fence-attribute'` = Pandoc `::: {.note}`, `'none'` = a plain bold-labeled blockquote with no
1120
+ * special marker. Omit to inherit from the `extends` preset. The legacy flavor names
1121
+ * `'github'`/`'gitlab'`/`'pandoc'` are accepted as deprecated aliases (see
1122
+ * `DeprecatedAdmonitionFlavor`) and will be removed in the next major version.
1123
+ */
1124
+ admonitions?: AdmonitionSyntax | DeprecatedAdmonitionFlavor;
1125
+ /**
1126
+ * Markdown Extra/Pandoc-style `Term`/`: Description` definition lists (`'colon'`), or `'none'`
1127
+ * to render terms and descriptions as plain paragraphs. Omit to inherit from `extends`. Passing
1128
+ * a boolean is deprecated: `true` = `'colon'`, `false` = `'none'` (removed next major).
1129
+ */
1130
+ definitionLists?: DefinitionListSyntax | DeprecatedDialectToggle;
1131
+ /**
1132
+ * `[^id]` footnote references/definitions (`'caret'`), or `'none'` to inline note content as a
1133
+ * parenthetical right at the reference point. Omit to inherit from `extends`. Passing a boolean
1134
+ * is deprecated: `true` = `'caret'`, `false` = `'none'` (removed next major).
1135
+ */
1136
+ footnotes?: FootnoteSyntax | DeprecatedDialectToggle;
1137
+ /**
1138
+ * Pandoc-style `[@citekey]` citations (`'at'`), or `'none'` to emit `[citekey]` (brackets, no
1139
+ * `@`). Omit to inherit from `extends`. Passing a boolean is deprecated: `true` = `'at'`,
1140
+ * `false` = `'none'` (removed next major).
1141
+ */
1142
+ citations?: CitationSyntax | DeprecatedDialectToggle;
1143
+ /**
1144
+ * Obsidian-style `[[Page]]`/`[[Page|Alias]]` wikilinks (`'double-bracket'`), or `'none'` to fall
1145
+ * back to a plain `[text](url)` link using the same target. Omit to inherit from `extends`.
1146
+ * Passing a boolean is deprecated: `true` = `'double-bracket'`, `false` = `'none'` (removed next major).
1147
+ */
1148
+ wikilinks?: WikilinkSyntax | DeprecatedDialectToggle;
1149
+ /** Inline `$...$`/block `$$...$$` math delimiters (`'dollar'`), or `'none'` for bare LaTeX text. */
1067
1150
  math?: "dollar" | "none";
1068
- /** Pandoc-style `{width=50% .centered}` attribute lists after images/tables. */
1069
- attributeLists?: boolean;
1070
- /** GFM `~~text~~` strikethrough (not part of base CommonMark). */
1071
- strikethrough?: boolean;
1151
+ /**
1152
+ * Pandoc-style `{width=50% .centered}` attribute lists after images/tables (`'brace'`), or
1153
+ * `'none'`. Omit to inherit from `extends`. Passing a boolean is deprecated: `true` = `'brace'`,
1154
+ * `false` = `'none'` (removed next major).
1155
+ */
1156
+ attributeLists?: AttributeListSyntax | DeprecatedDialectToggle;
1157
+ /**
1158
+ * GFM `~~text~~` strikethrough (`'tilde'`; not part of base CommonMark), or `'none'`. Omit to
1159
+ * inherit from `extends`. Passing a boolean is deprecated: `true` = `'tilde'`, `false` = `'none'`
1160
+ * (removed next major).
1161
+ */
1162
+ strikethrough?: StrikethroughSyntax | DeprecatedDialectToggle;
1163
+ /**
1164
+ * `==text==` highlight (`'equals'`; Obsidian/extended flavors, NOT GFM or CommonMark where `==`
1165
+ * is literal text), or `'none'`. When `'equals'`, a highlighted run round-trips as `==text==`
1166
+ * and `==text==` is read back as a highlight; when `'none'`, a highlight falls back to an HTML
1167
+ * `<mark>`/`<span>` per `fallbackToHtml.inlineFormatting`, and `==text==` stays literal on parse.
1168
+ * Omit to inherit from `extends`.
1169
+ */
1170
+ highlight?: HighlightSyntax;
1072
1171
  /** Unordered list bullet character. */
1073
1172
  bulletListMarker?: "-" | "*" | "+";
1074
1173
  /** Ordered list marker punctuation. */
@@ -1078,6 +1177,13 @@ export interface MarkdownDialectConfig {
1078
1177
  /** Table syntax: native GFM pipe tables, or forced HTML `<table>` (required for strict
1079
1178
  * CommonMark, which has no table syntax of its own). */
1080
1179
  tables?: "native" | "html";
1180
+ /**
1181
+ * How an `embed` node is written to Markdown (`'html'` | `'directive'` | `'link'` |
1182
+ * `'thumbnail'`; see `EmbedSyntax`). This is the authority for embed form. When omitted, the
1183
+ * deprecated `fallbackToHtml.embeds` boolean is honored (`true`/unset maps to `'html'`, `false`
1184
+ * to `'link'`), then the default `'html'`.
1185
+ */
1186
+ embeds?: EmbedSyntax;
1081
1187
  }
1082
1188
  /**
1083
1189
  * Granular control over when the Markdown generator falls back to raw HTML tags for features
@@ -1094,10 +1200,22 @@ export interface FallbackToHtmlConfig {
1094
1200
  anchors?: boolean;
1095
1201
  /** Nested-table and merged-cell (colspan/rowspan) HTML `<table>` fallback. */
1096
1202
  tables?: boolean;
1097
- /** YouTube embed `<div data-youtube-video>` vs. a plain link. */
1203
+ /**
1204
+ * YouTube embed `<div data-youtube-video>` vs. a plain link.
1205
+ * @deprecated Use `mdConfig.dialect.embeds` (`EmbedSyntax`) instead, which also selects the
1206
+ * `'directive'` and `'thumbnail'` forms. When `dialect.embeds` is unset this boolean is still
1207
+ * honored (`true` maps to `'html'`, `false` to `'link'`); it will be removed in the next major.
1208
+ */
1098
1209
  embeds?: boolean;
1099
1210
  /** Multi-line table cell content joined with `<br>` instead of a space. */
1100
1211
  cellLineBreaks?: boolean;
1212
+ /**
1213
+ * Multi-paragraph list-item content (an HTML `<li>` with several `<p>` children) joined with
1214
+ * `<br>` instead of a space, so it stays on the item's single Markdown line. Block children of
1215
+ * an item (a code fence or table inside `<li>`) degrade under this join, the same way they do
1216
+ * inside a table cell under `cellLineBreaks`.
1217
+ */
1218
+ itemLineBreaks?: boolean;
1101
1219
  /**
1102
1220
  * Inline text color, highlight, and font size via a `<span style="color:...;background-color:...;
1103
1221
  * font-size:...">` run, which the Markdown parser reads back. These have no Markdown syntax and
@@ -1604,6 +1722,12 @@ export interface CellMetadata {
1604
1722
  * @example 0 for column A, 1 for column B, etc.
1605
1723
  */
1606
1724
  col: number;
1725
+ /**
1726
+ * Text alignment for this cell's column, from the GFM pipe-table separator row
1727
+ * (`:---` left, `:---:` center, `---:` right). All cells in a column carry the same value;
1728
+ * the Markdown generator reads it from the header row to emit the separator.
1729
+ */
1730
+ align?: "left" | "center" | "right";
1607
1731
  /**
1608
1732
  * The number of rows this cell spans (merges).
1609
1733
  * @example 2 if the cell is merged with the one below it.
@@ -1682,6 +1806,8 @@ export interface ImageMetadata {
1682
1806
  * @example 'center'
1683
1807
  */
1684
1808
  align?: "left" | "center" | "right";
1809
+ /** Advisory image title (Markdown `![alt](url "title")`, HTML `<img title>`), if any. */
1810
+ title?: string;
1685
1811
  }
1686
1812
  /**
1687
1813
  * Metadata for an embedded external media node (e.g. a YouTube video).
@@ -1699,10 +1825,13 @@ export interface EmbedMetadata {
1699
1825
  url?: string;
1700
1826
  /** Display width, as a CSS length or percentage. */
1701
1827
  width?: string;
1702
- /** Display height, as a CSS length or percentage (generic iframes). */
1828
+ /** Display height, as a CSS length or percentage. */
1703
1829
  height?: string;
1704
1830
  /** Layout alignment of the embed. */
1705
1831
  align?: "left" | "center" | "right";
1832
+ /** Human-readable label for the embed (e.g. the `[Label]` of a `::youtube[Label]{...}` leaf
1833
+ * directive, or a gated embed's caption). Purely descriptive; never a trust or render input. */
1834
+ label?: string;
1706
1835
  }
1707
1836
  /**
1708
1837
  * Metadata for an admonition/alert node (e.g. GitHub's `> [!NOTE]` or GLFM's `:::note`).
@@ -1765,6 +1894,8 @@ export interface TextMetadata {
1765
1894
  * officeParser always parses/generates the syntax.
1766
1895
  */
1767
1896
  wikilink?: boolean;
1897
+ /** Advisory link title (Markdown `[text](url "title")`, HTML `<a title>`), if any. */
1898
+ title?: string;
1768
1899
  }
1769
1900
  /**
1770
1901
  * Metadata for note nodes (footnotes/endnotes).