@scrider/formatter 1.10.1 → 1.10.3
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/dist/index.cjs +111 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -58
- package/dist/index.d.ts +110 -58
- package/dist/index.js +108 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,13 +2,55 @@ import { AttributeMap, Op, Delta, InsertOp } from '@scrider/delta';
|
|
|
2
2
|
export * from '@scrider/delta';
|
|
3
3
|
export { InsertOp as ContentOp } from '@scrider/delta';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Simple Table HTML presentation options for deltaToHtml (clipboard, export).
|
|
7
|
+
* Structural data stays in Delta (table-row, table-col-align); this only affects inline styles.
|
|
8
|
+
*/
|
|
9
|
+
/** Column/cell horizontal alignment (GFM subset). */
|
|
10
|
+
type TableCellAlign = 'left' | 'center' | 'right';
|
|
11
|
+
/** Optional styling when serializing Simple Tables to HTML. */
|
|
12
|
+
interface TablePresentation {
|
|
13
|
+
/** Full 1px border on all cell sides. When true, `line` is ignored. */
|
|
14
|
+
grid?: boolean;
|
|
15
|
+
/** Bottom border only (DeepSeek / ChatGPT). Used when `grid` is not true. */
|
|
16
|
+
line?: boolean;
|
|
17
|
+
/** Border color as explicit hex (e.g. `#e7e7e7`). */
|
|
18
|
+
borderColor?: string;
|
|
19
|
+
/** Background on header cells (`th`). */
|
|
20
|
+
headerShade?: boolean;
|
|
21
|
+
/** Background on even table rows in the body (see `isZebraBodyRow`). */
|
|
22
|
+
zebraRows?: boolean;
|
|
23
|
+
/** `font-weight: bold` on `th`. */
|
|
24
|
+
headerBold?: boolean;
|
|
25
|
+
/** `text-align: center` on `th` (GitHub-style header). */
|
|
26
|
+
headerCenter?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Alignment for cells without `table-col-align` in Delta. Never overrides GFM column align.
|
|
29
|
+
* @default 'left'
|
|
30
|
+
*/
|
|
31
|
+
defaultCellAlign?: TableCellAlign;
|
|
32
|
+
}
|
|
33
|
+
interface ResolvedTablePresentation {
|
|
34
|
+
grid: boolean;
|
|
35
|
+
line: boolean;
|
|
36
|
+
borderColor: string;
|
|
37
|
+
headerShade: boolean;
|
|
38
|
+
zebraRows: boolean;
|
|
39
|
+
headerBold: boolean;
|
|
40
|
+
headerCenter: boolean;
|
|
41
|
+
defaultCellAlign: TableCellAlign;
|
|
42
|
+
}
|
|
43
|
+
declare function resolveTablePresentation(presentation?: TablePresentation): ResolvedTablePresentation;
|
|
44
|
+
/** Match CSS `tr:nth-child(even) td` when header rows precede body in `<table>`. */
|
|
45
|
+
declare function isZebraBodyRow(headerRowCount: number, bodyRowIndex: number): boolean;
|
|
46
|
+
|
|
5
47
|
/**
|
|
6
48
|
* Document-level metadata (Scrider format extension).
|
|
7
49
|
*
|
|
8
50
|
* Concrete schema for the opaque `scrider-metadata` sibling field defined in
|
|
9
51
|
* `@scrider/delta` (`ScriderDocument`). It carries document-wide defaults ONCE
|
|
10
|
-
* (line spacing, paragraph spacing, indent, heading policy, fonts
|
|
11
|
-
* duplicating them as block attributes on every `\n`.
|
|
52
|
+
* (line spacing, paragraph spacing, indent, heading policy, fonts, table
|
|
53
|
+
* presentation) instead of duplicating them as block attributes on every `\n`.
|
|
12
54
|
*
|
|
13
55
|
* Layering:
|
|
14
56
|
* - `@scrider/delta` treats the value as opaque `Record<string, unknown>` — it
|
|
@@ -18,11 +60,15 @@ export { InsertOp as ContentOp } from '@scrider/delta';
|
|
|
18
60
|
* export projection).
|
|
19
61
|
*
|
|
20
62
|
* All fields are optional and additive: extending the interface never changes the
|
|
21
|
-
* op-stream and is backward compatible.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
63
|
+
* op-stream and is backward compatible.
|
|
64
|
+
*
|
|
65
|
+
* Projection:
|
|
66
|
+
* - Spacing / indent → {@link documentMetadataToPresentation} (paragraph CSS).
|
|
67
|
+
* - Heading policy → {@link resolveHeadingPolicy} / heading block styles on `h1`–`h6`.
|
|
68
|
+
* - `tablePresentation` → same shape as `DeltaToHtmlOptions.tablePresentation`
|
|
69
|
+
* (used when the explicit option is omitted).
|
|
25
70
|
*/
|
|
71
|
+
|
|
26
72
|
interface ScriderDocumentMetadata {
|
|
27
73
|
/** Line spacing multiplier, e.g. `1.5`. */
|
|
28
74
|
lineSpacing?: number;
|
|
@@ -34,16 +80,35 @@ interface ScriderDocumentMetadata {
|
|
|
34
80
|
textIndentCm?: number;
|
|
35
81
|
/** Extra left indent in cm on top-level `<ul>`/`<ol>` (shifts marker + text). */
|
|
36
82
|
listBlockIndentCm?: number;
|
|
37
|
-
/** Document heading horizontal alignment policy. */
|
|
83
|
+
/** Document heading horizontal alignment policy. Presence = policy on. */
|
|
38
84
|
headingAlign?: 'left' | 'center' | 'right';
|
|
39
|
-
/** Document heading bold policy. */
|
|
85
|
+
/** Document heading bold policy. `true` = force bold on `h1`–`h6`. */
|
|
40
86
|
headingBold?: boolean;
|
|
41
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Named heading size-grid preset id (`scrider` | `google` | `word` | `browser` | `githubEm`).
|
|
89
|
+
* Ignored when {@link headingAuto} is true.
|
|
90
|
+
*/
|
|
42
91
|
headingSizeGridPreset?: string;
|
|
92
|
+
/**
|
|
93
|
+
* When true, headings use browser/CSS natural size (no size-grid projection).
|
|
94
|
+
* Mutually exclusive with {@link headingSizeGridPreset} in Settings UI.
|
|
95
|
+
*/
|
|
96
|
+
headingAuto?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Heading decoration preset (`none` | `scrider` | `github`).
|
|
99
|
+
* Editor: `data-scrider-heading-decoration`. Export: PDF/HTML vertical rhythm + rules.
|
|
100
|
+
*/
|
|
101
|
+
headingDecoration?: 'none' | 'scrider' | 'github';
|
|
43
102
|
/** Default document font family (bare family name, e.g. `Georgia`). */
|
|
44
103
|
defaultFont?: string;
|
|
45
104
|
/** Default document font size as a CSS length, e.g. `12pt`. */
|
|
46
105
|
defaultFontSize?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Simple / view table chrome (borders, header shade, zebra). Same shape as
|
|
108
|
+
* `DeltaToHtmlOptions.tablePresentation`. Persisted with the document so export
|
|
109
|
+
* matches Settings without a separate channel.
|
|
110
|
+
*/
|
|
111
|
+
tablePresentation?: TablePresentation;
|
|
47
112
|
}
|
|
48
113
|
|
|
49
114
|
/**
|
|
@@ -1504,13 +1569,12 @@ interface ResolvedDocumentPresentation {
|
|
|
1504
1569
|
declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
|
|
1505
1570
|
/**
|
|
1506
1571
|
* Project {@link ScriderDocumentMetadata} onto an HTML {@link DocumentPresentation}
|
|
1507
|
-
* (export / clipboard inline CSS).
|
|
1572
|
+
* (export / clipboard inline CSS for paragraphs/lists).
|
|
1508
1573
|
*
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
* can fall back cleanly.
|
|
1574
|
+
* Maps line/paragraph spacing and indent only. Heading policy is projected
|
|
1575
|
+
* separately via {@link resolveHeadingPolicy} / {@link headingPolicyStyleParts}
|
|
1576
|
+
* onto `h1`–`h6`. `tablePresentation` is read from metadata in `deltaToHtml`
|
|
1577
|
+
* when the explicit option is omitted. Returns `undefined` when nothing maps.
|
|
1514
1578
|
*/
|
|
1515
1579
|
declare function documentMetadataToPresentation(metadata: ScriderDocumentMetadata | undefined): DocumentPresentation | undefined;
|
|
1516
1580
|
/**
|
|
@@ -1532,46 +1596,32 @@ declare function documentPresentationStyleParts(tag: string, resolved: ResolvedD
|
|
|
1532
1596
|
declare function blockPresentationStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
|
|
1533
1597
|
|
|
1534
1598
|
/**
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1599
|
+
* Document-level heading policy projected to export HTML (`h1`–`h6` inline CSS).
|
|
1600
|
+
*
|
|
1601
|
+
* Editor applies the same policy via CSS vars (`--scrider-heading-*`, `--scrider-hN-size`).
|
|
1602
|
+
* Size maps mirror `editor-core` `HEADER_SIZE_PRESETS` — keep in sync.
|
|
1537
1603
|
*/
|
|
1538
|
-
|
|
1539
|
-
type
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
/** Background on even table rows in the body (see `isZebraBodyRow`). */
|
|
1551
|
-
zebraRows?: boolean;
|
|
1552
|
-
/** `font-weight: bold` on `th`. */
|
|
1553
|
-
headerBold?: boolean;
|
|
1554
|
-
/** `text-align: center` on `th` (GitHub-style header). */
|
|
1555
|
-
headerCenter?: boolean;
|
|
1556
|
-
/**
|
|
1557
|
-
* Alignment for cells without `table-col-align` in Delta. Never overrides GFM column align.
|
|
1558
|
-
* @default 'left'
|
|
1559
|
-
*/
|
|
1560
|
-
defaultCellAlign?: TableCellAlign;
|
|
1561
|
-
}
|
|
1562
|
-
interface ResolvedTablePresentation {
|
|
1563
|
-
grid: boolean;
|
|
1564
|
-
line: boolean;
|
|
1565
|
-
borderColor: string;
|
|
1566
|
-
headerShade: boolean;
|
|
1567
|
-
zebraRows: boolean;
|
|
1568
|
-
headerBold: boolean;
|
|
1569
|
-
headerCenter: boolean;
|
|
1570
|
-
defaultCellAlign: TableCellAlign;
|
|
1604
|
+
|
|
1605
|
+
type HeaderLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
1606
|
+
type HeaderSizeMap = Readonly<Record<HeaderLevel, string>>;
|
|
1607
|
+
type HeaderSizePresetName = 'scrider' | 'google' | 'word' | 'browser' | 'githubEm';
|
|
1608
|
+
/** Keep in sync with `@scrider/editor-core` `HEADER_SIZE_PRESETS`. */
|
|
1609
|
+
declare const HEADER_SIZE_PRESETS: Readonly<Record<HeaderSizePresetName, HeaderSizeMap>>;
|
|
1610
|
+
interface ResolvedHeadingPolicy {
|
|
1611
|
+
align: 'left' | 'center' | 'right' | undefined;
|
|
1612
|
+
bold: boolean;
|
|
1613
|
+
/** When set and `auto` is false, emit font-size on `hN` when Delta has no inline size. */
|
|
1614
|
+
sizePreset: HeaderSizePresetName | undefined;
|
|
1615
|
+
auto: boolean;
|
|
1571
1616
|
}
|
|
1572
|
-
declare function
|
|
1573
|
-
/**
|
|
1574
|
-
|
|
1617
|
+
declare function resolveHeadingPolicy(metadata: ScriderDocumentMetadata | undefined): ResolvedHeadingPolicy | undefined;
|
|
1618
|
+
/**
|
|
1619
|
+
* Inline styles for a heading block from document metadata.
|
|
1620
|
+
* Baked Delta attrs win: `align` on `\n` skips metadata align; presence of any
|
|
1621
|
+
* text with explicit `size` is not detectable at block level — size from preset
|
|
1622
|
+
* is always emitted when policy is on (matches editor CSS vars on `hN`).
|
|
1623
|
+
*/
|
|
1624
|
+
declare function headingPolicyStyleParts(tag: string, blockAttributes: AttributeMap | undefined, policy: ResolvedHeadingPolicy | undefined): string[];
|
|
1575
1625
|
|
|
1576
1626
|
/**
|
|
1577
1627
|
* Delta → HTML Conversion
|
|
@@ -1645,10 +1695,12 @@ interface DeltaToHtmlOptions {
|
|
|
1645
1695
|
/**
|
|
1646
1696
|
* Document-level metadata (Scrider format extension, `scrider-metadata`).
|
|
1647
1697
|
*
|
|
1648
|
-
* When {@link documentPresentation} is not provided,
|
|
1649
|
-
*
|
|
1650
|
-
* `
|
|
1651
|
-
*
|
|
1698
|
+
* When {@link documentPresentation} is not provided, spacing/indent fields are
|
|
1699
|
+
* projected via `documentMetadataToPresentation`. Heading policy
|
|
1700
|
+
* (`headingAlign` / `headingBold` / `headingSizeGridPreset` / `headingAuto`)
|
|
1701
|
+
* is projected onto `h1`–`h6`. When {@link tablePresentation} is omitted,
|
|
1702
|
+
* `metadata.tablePresentation` is used. An explicit `documentPresentation` /
|
|
1703
|
+
* `tablePresentation` always takes precedence. Does not change Delta.
|
|
1652
1704
|
*/
|
|
1653
1705
|
documentMetadata?: ScriderDocumentMetadata;
|
|
1654
1706
|
/**
|
|
@@ -2204,4 +2256,4 @@ declare function collectAdjacentTableLines<T extends {
|
|
|
2204
2256
|
*/
|
|
2205
2257
|
declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
|
|
2206
2258
|
|
|
2207
|
-
export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type RenderProfile, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, SCRIDER_TEXT_INDENT_KEY, type SanitizeOptions, type ScriderDocumentMetadata, TEXT_INDENT_BLOCK_TAGS, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockTextIndentStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToDom, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, renderDelta, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
|
|
2259
|
+
export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, HEADER_SIZE_PRESETS, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type RenderProfile, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, SCRIDER_TEXT_INDENT_KEY, type SanitizeOptions, type ScriderDocumentMetadata, TEXT_INDENT_BLOCK_TAGS, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockTextIndentStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToDom, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, headingPolicyStyleParts, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, renderDelta, resolveDocumentPresentation, resolveHeadingPolicy, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,55 @@ import { AttributeMap, Op, Delta, InsertOp } from '@scrider/delta';
|
|
|
2
2
|
export * from '@scrider/delta';
|
|
3
3
|
export { InsertOp as ContentOp } from '@scrider/delta';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Simple Table HTML presentation options for deltaToHtml (clipboard, export).
|
|
7
|
+
* Structural data stays in Delta (table-row, table-col-align); this only affects inline styles.
|
|
8
|
+
*/
|
|
9
|
+
/** Column/cell horizontal alignment (GFM subset). */
|
|
10
|
+
type TableCellAlign = 'left' | 'center' | 'right';
|
|
11
|
+
/** Optional styling when serializing Simple Tables to HTML. */
|
|
12
|
+
interface TablePresentation {
|
|
13
|
+
/** Full 1px border on all cell sides. When true, `line` is ignored. */
|
|
14
|
+
grid?: boolean;
|
|
15
|
+
/** Bottom border only (DeepSeek / ChatGPT). Used when `grid` is not true. */
|
|
16
|
+
line?: boolean;
|
|
17
|
+
/** Border color as explicit hex (e.g. `#e7e7e7`). */
|
|
18
|
+
borderColor?: string;
|
|
19
|
+
/** Background on header cells (`th`). */
|
|
20
|
+
headerShade?: boolean;
|
|
21
|
+
/** Background on even table rows in the body (see `isZebraBodyRow`). */
|
|
22
|
+
zebraRows?: boolean;
|
|
23
|
+
/** `font-weight: bold` on `th`. */
|
|
24
|
+
headerBold?: boolean;
|
|
25
|
+
/** `text-align: center` on `th` (GitHub-style header). */
|
|
26
|
+
headerCenter?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Alignment for cells without `table-col-align` in Delta. Never overrides GFM column align.
|
|
29
|
+
* @default 'left'
|
|
30
|
+
*/
|
|
31
|
+
defaultCellAlign?: TableCellAlign;
|
|
32
|
+
}
|
|
33
|
+
interface ResolvedTablePresentation {
|
|
34
|
+
grid: boolean;
|
|
35
|
+
line: boolean;
|
|
36
|
+
borderColor: string;
|
|
37
|
+
headerShade: boolean;
|
|
38
|
+
zebraRows: boolean;
|
|
39
|
+
headerBold: boolean;
|
|
40
|
+
headerCenter: boolean;
|
|
41
|
+
defaultCellAlign: TableCellAlign;
|
|
42
|
+
}
|
|
43
|
+
declare function resolveTablePresentation(presentation?: TablePresentation): ResolvedTablePresentation;
|
|
44
|
+
/** Match CSS `tr:nth-child(even) td` when header rows precede body in `<table>`. */
|
|
45
|
+
declare function isZebraBodyRow(headerRowCount: number, bodyRowIndex: number): boolean;
|
|
46
|
+
|
|
5
47
|
/**
|
|
6
48
|
* Document-level metadata (Scrider format extension).
|
|
7
49
|
*
|
|
8
50
|
* Concrete schema for the opaque `scrider-metadata` sibling field defined in
|
|
9
51
|
* `@scrider/delta` (`ScriderDocument`). It carries document-wide defaults ONCE
|
|
10
|
-
* (line spacing, paragraph spacing, indent, heading policy, fonts
|
|
11
|
-
* duplicating them as block attributes on every `\n`.
|
|
52
|
+
* (line spacing, paragraph spacing, indent, heading policy, fonts, table
|
|
53
|
+
* presentation) instead of duplicating them as block attributes on every `\n`.
|
|
12
54
|
*
|
|
13
55
|
* Layering:
|
|
14
56
|
* - `@scrider/delta` treats the value as opaque `Record<string, unknown>` — it
|
|
@@ -18,11 +60,15 @@ export { InsertOp as ContentOp } from '@scrider/delta';
|
|
|
18
60
|
* export projection).
|
|
19
61
|
*
|
|
20
62
|
* All fields are optional and additive: extending the interface never changes the
|
|
21
|
-
* op-stream and is backward compatible.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
63
|
+
* op-stream and is backward compatible.
|
|
64
|
+
*
|
|
65
|
+
* Projection:
|
|
66
|
+
* - Spacing / indent → {@link documentMetadataToPresentation} (paragraph CSS).
|
|
67
|
+
* - Heading policy → {@link resolveHeadingPolicy} / heading block styles on `h1`–`h6`.
|
|
68
|
+
* - `tablePresentation` → same shape as `DeltaToHtmlOptions.tablePresentation`
|
|
69
|
+
* (used when the explicit option is omitted).
|
|
25
70
|
*/
|
|
71
|
+
|
|
26
72
|
interface ScriderDocumentMetadata {
|
|
27
73
|
/** Line spacing multiplier, e.g. `1.5`. */
|
|
28
74
|
lineSpacing?: number;
|
|
@@ -34,16 +80,35 @@ interface ScriderDocumentMetadata {
|
|
|
34
80
|
textIndentCm?: number;
|
|
35
81
|
/** Extra left indent in cm on top-level `<ul>`/`<ol>` (shifts marker + text). */
|
|
36
82
|
listBlockIndentCm?: number;
|
|
37
|
-
/** Document heading horizontal alignment policy. */
|
|
83
|
+
/** Document heading horizontal alignment policy. Presence = policy on. */
|
|
38
84
|
headingAlign?: 'left' | 'center' | 'right';
|
|
39
|
-
/** Document heading bold policy. */
|
|
85
|
+
/** Document heading bold policy. `true` = force bold on `h1`–`h6`. */
|
|
40
86
|
headingBold?: boolean;
|
|
41
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Named heading size-grid preset id (`scrider` | `google` | `word` | `browser` | `githubEm`).
|
|
89
|
+
* Ignored when {@link headingAuto} is true.
|
|
90
|
+
*/
|
|
42
91
|
headingSizeGridPreset?: string;
|
|
92
|
+
/**
|
|
93
|
+
* When true, headings use browser/CSS natural size (no size-grid projection).
|
|
94
|
+
* Mutually exclusive with {@link headingSizeGridPreset} in Settings UI.
|
|
95
|
+
*/
|
|
96
|
+
headingAuto?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Heading decoration preset (`none` | `scrider` | `github`).
|
|
99
|
+
* Editor: `data-scrider-heading-decoration`. Export: PDF/HTML vertical rhythm + rules.
|
|
100
|
+
*/
|
|
101
|
+
headingDecoration?: 'none' | 'scrider' | 'github';
|
|
43
102
|
/** Default document font family (bare family name, e.g. `Georgia`). */
|
|
44
103
|
defaultFont?: string;
|
|
45
104
|
/** Default document font size as a CSS length, e.g. `12pt`. */
|
|
46
105
|
defaultFontSize?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Simple / view table chrome (borders, header shade, zebra). Same shape as
|
|
108
|
+
* `DeltaToHtmlOptions.tablePresentation`. Persisted with the document so export
|
|
109
|
+
* matches Settings without a separate channel.
|
|
110
|
+
*/
|
|
111
|
+
tablePresentation?: TablePresentation;
|
|
47
112
|
}
|
|
48
113
|
|
|
49
114
|
/**
|
|
@@ -1504,13 +1569,12 @@ interface ResolvedDocumentPresentation {
|
|
|
1504
1569
|
declare function resolveDocumentPresentation(presentation?: DocumentPresentation): ResolvedDocumentPresentation | undefined;
|
|
1505
1570
|
/**
|
|
1506
1571
|
* Project {@link ScriderDocumentMetadata} onto an HTML {@link DocumentPresentation}
|
|
1507
|
-
* (export / clipboard inline CSS).
|
|
1572
|
+
* (export / clipboard inline CSS for paragraphs/lists).
|
|
1508
1573
|
*
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
* can fall back cleanly.
|
|
1574
|
+
* Maps line/paragraph spacing and indent only. Heading policy is projected
|
|
1575
|
+
* separately via {@link resolveHeadingPolicy} / {@link headingPolicyStyleParts}
|
|
1576
|
+
* onto `h1`–`h6`. `tablePresentation` is read from metadata in `deltaToHtml`
|
|
1577
|
+
* when the explicit option is omitted. Returns `undefined` when nothing maps.
|
|
1514
1578
|
*/
|
|
1515
1579
|
declare function documentMetadataToPresentation(metadata: ScriderDocumentMetadata | undefined): DocumentPresentation | undefined;
|
|
1516
1580
|
/**
|
|
@@ -1532,46 +1596,32 @@ declare function documentPresentationStyleParts(tag: string, resolved: ResolvedD
|
|
|
1532
1596
|
declare function blockPresentationStyleParts(tag: string, blockAttributes: AttributeMap | undefined, resolved: ResolvedDocumentPresentation | undefined): string[];
|
|
1533
1597
|
|
|
1534
1598
|
/**
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1599
|
+
* Document-level heading policy projected to export HTML (`h1`–`h6` inline CSS).
|
|
1600
|
+
*
|
|
1601
|
+
* Editor applies the same policy via CSS vars (`--scrider-heading-*`, `--scrider-hN-size`).
|
|
1602
|
+
* Size maps mirror `editor-core` `HEADER_SIZE_PRESETS` — keep in sync.
|
|
1537
1603
|
*/
|
|
1538
|
-
|
|
1539
|
-
type
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
/** Background on even table rows in the body (see `isZebraBodyRow`). */
|
|
1551
|
-
zebraRows?: boolean;
|
|
1552
|
-
/** `font-weight: bold` on `th`. */
|
|
1553
|
-
headerBold?: boolean;
|
|
1554
|
-
/** `text-align: center` on `th` (GitHub-style header). */
|
|
1555
|
-
headerCenter?: boolean;
|
|
1556
|
-
/**
|
|
1557
|
-
* Alignment for cells without `table-col-align` in Delta. Never overrides GFM column align.
|
|
1558
|
-
* @default 'left'
|
|
1559
|
-
*/
|
|
1560
|
-
defaultCellAlign?: TableCellAlign;
|
|
1561
|
-
}
|
|
1562
|
-
interface ResolvedTablePresentation {
|
|
1563
|
-
grid: boolean;
|
|
1564
|
-
line: boolean;
|
|
1565
|
-
borderColor: string;
|
|
1566
|
-
headerShade: boolean;
|
|
1567
|
-
zebraRows: boolean;
|
|
1568
|
-
headerBold: boolean;
|
|
1569
|
-
headerCenter: boolean;
|
|
1570
|
-
defaultCellAlign: TableCellAlign;
|
|
1604
|
+
|
|
1605
|
+
type HeaderLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
1606
|
+
type HeaderSizeMap = Readonly<Record<HeaderLevel, string>>;
|
|
1607
|
+
type HeaderSizePresetName = 'scrider' | 'google' | 'word' | 'browser' | 'githubEm';
|
|
1608
|
+
/** Keep in sync with `@scrider/editor-core` `HEADER_SIZE_PRESETS`. */
|
|
1609
|
+
declare const HEADER_SIZE_PRESETS: Readonly<Record<HeaderSizePresetName, HeaderSizeMap>>;
|
|
1610
|
+
interface ResolvedHeadingPolicy {
|
|
1611
|
+
align: 'left' | 'center' | 'right' | undefined;
|
|
1612
|
+
bold: boolean;
|
|
1613
|
+
/** When set and `auto` is false, emit font-size on `hN` when Delta has no inline size. */
|
|
1614
|
+
sizePreset: HeaderSizePresetName | undefined;
|
|
1615
|
+
auto: boolean;
|
|
1571
1616
|
}
|
|
1572
|
-
declare function
|
|
1573
|
-
/**
|
|
1574
|
-
|
|
1617
|
+
declare function resolveHeadingPolicy(metadata: ScriderDocumentMetadata | undefined): ResolvedHeadingPolicy | undefined;
|
|
1618
|
+
/**
|
|
1619
|
+
* Inline styles for a heading block from document metadata.
|
|
1620
|
+
* Baked Delta attrs win: `align` on `\n` skips metadata align; presence of any
|
|
1621
|
+
* text with explicit `size` is not detectable at block level — size from preset
|
|
1622
|
+
* is always emitted when policy is on (matches editor CSS vars on `hN`).
|
|
1623
|
+
*/
|
|
1624
|
+
declare function headingPolicyStyleParts(tag: string, blockAttributes: AttributeMap | undefined, policy: ResolvedHeadingPolicy | undefined): string[];
|
|
1575
1625
|
|
|
1576
1626
|
/**
|
|
1577
1627
|
* Delta → HTML Conversion
|
|
@@ -1645,10 +1695,12 @@ interface DeltaToHtmlOptions {
|
|
|
1645
1695
|
/**
|
|
1646
1696
|
* Document-level metadata (Scrider format extension, `scrider-metadata`).
|
|
1647
1697
|
*
|
|
1648
|
-
* When {@link documentPresentation} is not provided,
|
|
1649
|
-
*
|
|
1650
|
-
* `
|
|
1651
|
-
*
|
|
1698
|
+
* When {@link documentPresentation} is not provided, spacing/indent fields are
|
|
1699
|
+
* projected via `documentMetadataToPresentation`. Heading policy
|
|
1700
|
+
* (`headingAlign` / `headingBold` / `headingSizeGridPreset` / `headingAuto`)
|
|
1701
|
+
* is projected onto `h1`–`h6`. When {@link tablePresentation} is omitted,
|
|
1702
|
+
* `metadata.tablePresentation` is used. An explicit `documentPresentation` /
|
|
1703
|
+
* `tablePresentation` always takes precedence. Does not change Delta.
|
|
1652
1704
|
*/
|
|
1653
1705
|
documentMetadata?: ScriderDocumentMetadata;
|
|
1654
1706
|
/**
|
|
@@ -2204,4 +2256,4 @@ declare function collectAdjacentTableLines<T extends {
|
|
|
2204
2256
|
*/
|
|
2205
2257
|
declare function extractTableRegion(ops: readonly Op[], hintOpIdx: number): TableRegion | null;
|
|
2206
2258
|
|
|
2207
|
-
export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type RenderProfile, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, SCRIDER_TEXT_INDENT_KEY, type SanitizeOptions, type ScriderDocumentMetadata, TEXT_INDENT_BLOCK_TAGS, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockTextIndentStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToDom, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, renderDelta, resolveDocumentPresentation, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
|
|
2259
|
+
export { ALERT_TYPES, type AlertBlockData, type AlertType, type AlignType, BOX_FLOAT_VALUES, BOX_OVERFLOW_VALUES, type BlockContext, type BlockHandler, BlockHandlerRegistry, type BlockRenderOptions, type BoxBlockData, type BoxFloat, type BoxOpAttributes, type BoxOverflow, BrowserDOMAdapter, type CellAlign, type CellData, type CellHorizontalAlign, type CellVerticalAlign, type ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type DocumentPresentation, type EmbedIsolationOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatRenderContext, type FormatScope, HEADER_SIZE_PRESETS, type HtmlToDeltaOptions, LINE_HEIGHT_BLOCK_TAGS, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, PARAGRAPH_SPACING_BLOCK_TAGS, Registry, type RenderProfile, type ResolvedDocumentPresentation, type ResolvedTablePresentation, SCRIDER_LINE_HEIGHT_KEY, SCRIDER_MARGIN_AFTER_KEY, SCRIDER_MARGIN_BEFORE_KEY, SCRIDER_TEXT_INDENT_KEY, type SanitizeOptions, type ScriderDocumentMetadata, TEXT_INDENT_BLOCK_TAGS, type TableBlockData, type TableBlockFloat, type TableCellAlign, type TableCellCoords, type TableColAlignType, type TablePresentation, type TableRegion, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockLineHeightStyleParts, blockMarginAfterStyleParts, blockMarginBeforeStyleParts, blockParagraphMarginStyleParts, blockPresentationStyleParts, blockTextIndentStyleParts, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, codeWidgetFormat, collectAdjacentTableLines, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToDom, deltaToHtml, deltaToMarkdown, dividerFormat, documentMetadataToPresentation, documentPresentationStyleParts, escapeHtml, extractBoxOpAttributes, extractTableRegion, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, headingPolicyStyleParts, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isAdjacentSimpleTableGridBoundary, isElement, isRemarkAvailable, isTableNewlineOp, isTextNode, isValidColor, isValidHexColor, isZebraBodyRow, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, parseScriderLineHeightMultiplier, parseScriderMarginAfterEm, parseScriderMarginBeforeEm, parseScriderMarginEm, preloadRemark, renderDelta, resolveDocumentPresentation, resolveHeadingPolicy, resolveTablePresentation, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, softBreakFormat, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableCellCoordsFromAttributes, tableCellCoordsFromOp, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toCodeWidgetEmbedUrl, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
|
package/dist/index.js
CHANGED
|
@@ -3178,6 +3178,90 @@ function joinStyleParts(parts) {
|
|
|
3178
3178
|
return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
|
|
3179
3179
|
}
|
|
3180
3180
|
|
|
3181
|
+
// src/conversion/html/heading-presentation.ts
|
|
3182
|
+
var HEADER_SIZE_PRESETS = Object.freeze({
|
|
3183
|
+
scrider: Object.freeze({
|
|
3184
|
+
1: "32pt",
|
|
3185
|
+
2: "24pt",
|
|
3186
|
+
3: "20pt",
|
|
3187
|
+
4: "18pt",
|
|
3188
|
+
5: "16pt",
|
|
3189
|
+
6: "14pt"
|
|
3190
|
+
}),
|
|
3191
|
+
google: Object.freeze({
|
|
3192
|
+
1: "26pt",
|
|
3193
|
+
2: "20pt",
|
|
3194
|
+
3: "16pt",
|
|
3195
|
+
4: "14pt",
|
|
3196
|
+
5: "12pt",
|
|
3197
|
+
6: "11pt"
|
|
3198
|
+
}),
|
|
3199
|
+
word: Object.freeze({
|
|
3200
|
+
1: "22pt",
|
|
3201
|
+
2: "18pt",
|
|
3202
|
+
3: "16pt",
|
|
3203
|
+
4: "14pt",
|
|
3204
|
+
5: "12pt",
|
|
3205
|
+
6: "12pt"
|
|
3206
|
+
}),
|
|
3207
|
+
browser: Object.freeze({
|
|
3208
|
+
1: "24pt",
|
|
3209
|
+
2: "18pt",
|
|
3210
|
+
3: "14pt",
|
|
3211
|
+
4: "12pt",
|
|
3212
|
+
5: "10pt",
|
|
3213
|
+
6: "8pt"
|
|
3214
|
+
}),
|
|
3215
|
+
githubEm: Object.freeze({
|
|
3216
|
+
1: "32pt",
|
|
3217
|
+
2: "24pt",
|
|
3218
|
+
3: "20pt",
|
|
3219
|
+
4: "16pt",
|
|
3220
|
+
5: "14pt",
|
|
3221
|
+
6: "14pt"
|
|
3222
|
+
})
|
|
3223
|
+
});
|
|
3224
|
+
var HEADING_TAGS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
3225
|
+
function isHeaderSizePresetName(value) {
|
|
3226
|
+
return Object.prototype.hasOwnProperty.call(HEADER_SIZE_PRESETS, value);
|
|
3227
|
+
}
|
|
3228
|
+
function resolveHeadingPolicy(metadata) {
|
|
3229
|
+
if (!metadata) return void 0;
|
|
3230
|
+
const align = metadata.headingAlign === "left" || metadata.headingAlign === "center" || metadata.headingAlign === "right" ? metadata.headingAlign : void 0;
|
|
3231
|
+
const bold = metadata.headingBold === true;
|
|
3232
|
+
const auto = metadata.headingAuto === true;
|
|
3233
|
+
const presetRaw = metadata.headingSizeGridPreset;
|
|
3234
|
+
const sizePreset = !auto && typeof presetRaw === "string" && isHeaderSizePresetName(presetRaw) ? presetRaw : void 0;
|
|
3235
|
+
if (align === void 0 && !bold && sizePreset === void 0 && !auto) {
|
|
3236
|
+
return void 0;
|
|
3237
|
+
}
|
|
3238
|
+
return { align, bold, sizePreset, auto };
|
|
3239
|
+
}
|
|
3240
|
+
function headingLevelFromTag(tag) {
|
|
3241
|
+
if (!HEADING_TAGS.has(tag)) return void 0;
|
|
3242
|
+
const n = Number(tag.slice(1));
|
|
3243
|
+
if (n >= 1 && n <= 6) return n;
|
|
3244
|
+
return void 0;
|
|
3245
|
+
}
|
|
3246
|
+
function headingPolicyStyleParts(tag, blockAttributes, policy) {
|
|
3247
|
+
if (!policy) return [];
|
|
3248
|
+
const level = headingLevelFromTag(tag);
|
|
3249
|
+
if (level === void 0) return [];
|
|
3250
|
+
const parts = [];
|
|
3251
|
+
const bakedAlign = blockAttributes?.align;
|
|
3252
|
+
if (policy.align && policy.align !== "left" && !(typeof bakedAlign === "string" && bakedAlign.length > 0)) {
|
|
3253
|
+
parts.push(`text-align: ${policy.align}`);
|
|
3254
|
+
}
|
|
3255
|
+
if (policy.bold) {
|
|
3256
|
+
parts.push("font-weight: bold");
|
|
3257
|
+
}
|
|
3258
|
+
if (policy.sizePreset) {
|
|
3259
|
+
const size = HEADER_SIZE_PRESETS[policy.sizePreset][level];
|
|
3260
|
+
if (size) parts.push(`font-size: ${size}`);
|
|
3261
|
+
}
|
|
3262
|
+
return parts;
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3181
3265
|
// src/conversion/html/table-presentation.ts
|
|
3182
3266
|
var DEFAULT_BORDER_COLOR = "#e7e7e7";
|
|
3183
3267
|
var DEFAULT_HEADER_BG = "#f5f5f5";
|
|
@@ -3342,6 +3426,12 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3342
3426
|
const resolvedDocumentPresentation = resolveDocumentPresentation(
|
|
3343
3427
|
options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
|
|
3344
3428
|
);
|
|
3429
|
+
const resolvedHeadingPolicy = resolveHeadingPolicy(options.documentMetadata);
|
|
3430
|
+
const effectiveTablePresentation = options.tablePresentation ?? options.documentMetadata?.tablePresentation;
|
|
3431
|
+
const optionsWithTable = {
|
|
3432
|
+
...options,
|
|
3433
|
+
...effectiveTablePresentation !== void 0 ? { tablePresentation: effectiveTablePresentation } : {}
|
|
3434
|
+
};
|
|
3345
3435
|
let html = "";
|
|
3346
3436
|
let listStack = [];
|
|
3347
3437
|
let counters = [];
|
|
@@ -3354,7 +3444,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3354
3444
|
listStack = [];
|
|
3355
3445
|
counters = [];
|
|
3356
3446
|
const tableLines = collectAdjacentTableLines(lines, i);
|
|
3357
|
-
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers,
|
|
3447
|
+
html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, optionsWithTable);
|
|
3358
3448
|
i += tableLines.length - 1;
|
|
3359
3449
|
continue;
|
|
3360
3450
|
}
|
|
@@ -3445,7 +3535,8 @@ function deltaToHtml(delta, options = {}) {
|
|
|
3445
3535
|
line.attributes,
|
|
3446
3536
|
pretty,
|
|
3447
3537
|
headingId,
|
|
3448
|
-
resolvedDocumentPresentation
|
|
3538
|
+
resolvedDocumentPresentation,
|
|
3539
|
+
resolvedHeadingPolicy
|
|
3449
3540
|
);
|
|
3450
3541
|
}
|
|
3451
3542
|
}
|
|
@@ -3765,19 +3856,23 @@ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hi
|
|
|
3765
3856
|
const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
|
|
3766
3857
|
return pretty ? html + "\n" : html;
|
|
3767
3858
|
}
|
|
3768
|
-
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
|
|
3859
|
+
function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
3769
3860
|
const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
|
|
3770
|
-
const styleAttr = getBlockStyleAttribute(
|
|
3861
|
+
const styleAttr = getBlockStyleAttribute(
|
|
3862
|
+
tag,
|
|
3863
|
+
attributes,
|
|
3864
|
+
resolvedDocumentPresentation,
|
|
3865
|
+
resolvedHeadingPolicy
|
|
3866
|
+
);
|
|
3771
3867
|
const innerContent = content || "<br>";
|
|
3772
3868
|
const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
|
|
3773
3869
|
return pretty ? html + "\n" : html;
|
|
3774
3870
|
}
|
|
3775
|
-
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
3776
|
-
const styles =
|
|
3777
|
-
tag,
|
|
3778
|
-
attributes,
|
|
3779
|
-
|
|
3780
|
-
);
|
|
3871
|
+
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation, resolvedHeadingPolicy) {
|
|
3872
|
+
const styles = [
|
|
3873
|
+
...blockPresentationStyleParts(tag, attributes, resolvedDocumentPresentation),
|
|
3874
|
+
...headingPolicyStyleParts(tag, attributes, resolvedHeadingPolicy)
|
|
3875
|
+
];
|
|
3781
3876
|
if (attributes) {
|
|
3782
3877
|
const alignVal = attributes.align;
|
|
3783
3878
|
if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
|
|
@@ -6097,6 +6192,7 @@ export {
|
|
|
6097
6192
|
BOX_OVERFLOW_VALUES,
|
|
6098
6193
|
BlockHandlerRegistry,
|
|
6099
6194
|
BrowserDOMAdapter,
|
|
6195
|
+
HEADER_SIZE_PRESETS,
|
|
6100
6196
|
LINE_HEIGHT_BLOCK_TAGS,
|
|
6101
6197
|
NODE_TYPE,
|
|
6102
6198
|
NodeDOMAdapter,
|
|
@@ -6151,6 +6247,7 @@ export {
|
|
|
6151
6247
|
getNamedColors,
|
|
6152
6248
|
headerFormat,
|
|
6153
6249
|
headerIdFormat,
|
|
6250
|
+
headingPolicyStyleParts,
|
|
6154
6251
|
htmlToDelta,
|
|
6155
6252
|
imageFormat,
|
|
6156
6253
|
indentFormat,
|
|
@@ -6179,6 +6276,7 @@ export {
|
|
|
6179
6276
|
preloadRemark,
|
|
6180
6277
|
renderDelta,
|
|
6181
6278
|
resolveDocumentPresentation,
|
|
6279
|
+
resolveHeadingPolicy,
|
|
6182
6280
|
resolveTablePresentation,
|
|
6183
6281
|
sanitizeDelta,
|
|
6184
6282
|
sizeFormat,
|