@scrider/formatter 1.0.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -67,6 +67,8 @@ interface DOMCSSStyleDeclaration {
67
67
  setProperty(property: string, value: string): void;
68
68
  color?: string;
69
69
  backgroundColor?: string;
70
+ fontFamily?: string;
71
+ fontSize?: string;
70
72
  fontWeight?: string;
71
73
  fontStyle?: string;
72
74
  textDecoration?: string;
@@ -788,6 +790,13 @@ declare const codeFormat: Format<boolean>;
788
790
  */
789
791
  declare const colorFormat: Format<string>;
790
792
 
793
+ /**
794
+ * Font family format
795
+ *
796
+ * Delta: { insert: "text", attributes: { font: "Times New Roman" } }
797
+ */
798
+ declare const fontFormat: Format<string>;
799
+
791
800
  /**
792
801
  * Italic format
793
802
  *
@@ -825,6 +834,15 @@ declare const linkFormat: Format<string>;
825
834
  */
826
835
  declare const markFormat: Format<boolean>;
827
836
 
837
+ /**
838
+ * Font size format
839
+ *
840
+ * Delta: { insert: "text", attributes: { size: "14pt" } }
841
+ *
842
+ * Value is a string with CSS unit (e.g. "14pt", "16px", "1.2em").
843
+ */
844
+ declare const sizeFormat: Format<string>;
845
+
828
846
  /**
829
847
  * Strikethrough format
830
848
  *
@@ -1655,4 +1673,4 @@ declare function markdownToDelta(markdown: string, options?: MarkdownToDeltaOpti
1655
1673
  */
1656
1674
  declare function markdownToDeltaSync(markdown: string, options?: MarkdownToDeltaOptions): Delta;
1657
1675
 
1658
- 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 ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type SanitizeOptions, type TableBlockData, type TableColAlignType, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTextNode, isValidColor, isValidHexColor, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, sanitizeDelta, slugify, slugifyWithDedup, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
1676
+ 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 ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type SanitizeOptions, type TableBlockData, type TableColAlignType, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTextNode, isValidColor, isValidHexColor, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,8 @@ interface DOMCSSStyleDeclaration {
67
67
  setProperty(property: string, value: string): void;
68
68
  color?: string;
69
69
  backgroundColor?: string;
70
+ fontFamily?: string;
71
+ fontSize?: string;
70
72
  fontWeight?: string;
71
73
  fontStyle?: string;
72
74
  textDecoration?: string;
@@ -788,6 +790,13 @@ declare const codeFormat: Format<boolean>;
788
790
  */
789
791
  declare const colorFormat: Format<string>;
790
792
 
793
+ /**
794
+ * Font family format
795
+ *
796
+ * Delta: { insert: "text", attributes: { font: "Times New Roman" } }
797
+ */
798
+ declare const fontFormat: Format<string>;
799
+
791
800
  /**
792
801
  * Italic format
793
802
  *
@@ -825,6 +834,15 @@ declare const linkFormat: Format<string>;
825
834
  */
826
835
  declare const markFormat: Format<boolean>;
827
836
 
837
+ /**
838
+ * Font size format
839
+ *
840
+ * Delta: { insert: "text", attributes: { size: "14pt" } }
841
+ *
842
+ * Value is a string with CSS unit (e.g. "14pt", "16px", "1.2em").
843
+ */
844
+ declare const sizeFormat: Format<string>;
845
+
828
846
  /**
829
847
  * Strikethrough format
830
848
  *
@@ -1655,4 +1673,4 @@ declare function markdownToDelta(markdown: string, options?: MarkdownToDeltaOpti
1655
1673
  */
1656
1674
  declare function markdownToDeltaSync(markdown: string, options?: MarkdownToDeltaOptions): Delta;
1657
1675
 
1658
- 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 ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type SanitizeOptions, type TableBlockData, type TableColAlignType, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTextNode, isValidColor, isValidHexColor, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, sanitizeDelta, slugify, slugifyWithDedup, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
1676
+ 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 ColumnsBlockData, type DOMAdapter, type DOMDocument, type DOMDocumentFragment, type DOMElement, type DOMNode, type DOMNodeList, type DeltaToHtmlOptions, type DeltaToMarkdownOptions, type FootnotesBlockData, type Format, type FormatDefinition, type FormatMatchResult, type FormatScope, type HtmlToDeltaOptions, type ListType, type MarkdownToDeltaOptions, NODE_TYPE, NodeDOMAdapter, Registry, type SanitizeOptions, type TableBlockData, type TableColAlignType, alertBlockHandler, alignFormat, backgroundFormat, blockFormat, blockquoteFormat, boldFormat, boxBlockHandler, browserAdapter, cloneDelta, codeBlockFormat, codeFormat, colorFormat, columnsBlockHandler, createDefaultBlockHandlers, createDefaultRegistry, defaultBlockFormats, defaultEmbedFormats, defaultFormats, defaultInlineFormats, deltaToHtml, deltaToMarkdown, dividerFormat, escapeHtml, extractBoxOpAttributes, fontFormat, footnoteRefFormat, footnotesBlockHandler, formulaFormat, getAdapter, getNamedColors, headerFormat, headerIdFormat, htmlToDelta, imageFormat, indentFormat, isAdapterAvailable, isElement, isRemarkAvailable, isTextNode, isValidColor, isValidHexColor, italicFormat, kbdFormat, linkFormat, listFormat, markFormat, markdownToDelta, markdownToDeltaSync, nodeAdapter, normalizeDelta, sanitizeDelta, sizeFormat, slugify, slugifyWithDedup, strikeFormat, subscriptFormat, superscriptFormat, tableBlockHandler, tableColAlignFormat, tableColFormat, tableHeaderFormat, tableRowFormat, toHexColor, underlineFormat, unescapeHtml, validateDelta, videoFormat };
package/dist/index.js CHANGED
@@ -1563,6 +1563,15 @@ var colorFormat = {
1563
1563
  }
1564
1564
  };
1565
1565
 
1566
+ // src/schema/formats/inline/font.ts
1567
+ var fontFormat = {
1568
+ name: "font",
1569
+ scope: "inline",
1570
+ validate(value) {
1571
+ return typeof value === "string" && value.length > 0;
1572
+ }
1573
+ };
1574
+
1566
1575
  // src/schema/formats/inline/italic.ts
1567
1576
  var italicFormat = {
1568
1577
  name: "italic",
@@ -1620,6 +1629,15 @@ var markFormat = {
1620
1629
  }
1621
1630
  };
1622
1631
 
1632
+ // src/schema/formats/inline/size.ts
1633
+ var sizeFormat = {
1634
+ name: "size",
1635
+ scope: "inline",
1636
+ validate(value) {
1637
+ return typeof value === "string" && value.length > 0;
1638
+ }
1639
+ };
1640
+
1623
1641
  // src/schema/formats/inline/strike.ts
1624
1642
  var strikeFormat = {
1625
1643
  name: "strike",
@@ -1827,7 +1845,9 @@ var INLINE_FORMAT_ORDER = [
1827
1845
  ];
1828
1846
  var INLINE_STYLE_FORMATS = {
1829
1847
  color: "color",
1830
- background: "background-color"
1848
+ background: "background-color",
1849
+ font: "font-family",
1850
+ size: "font-size"
1831
1851
  };
1832
1852
  var BLOCK_FORMAT_TAGS = {
1833
1853
  header: (value) => `h${String(value)}`,
@@ -2212,6 +2232,8 @@ var defaultInlineFormats = [
2212
2232
  linkFormat,
2213
2233
  colorFormat,
2214
2234
  backgroundFormat,
2235
+ fontFormat,
2236
+ sizeFormat,
2215
2237
  markFormat,
2216
2238
  kbdFormat
2217
2239
  ];
@@ -3242,6 +3264,14 @@ function htmlToDelta(html, options = {}) {
3242
3264
  if (bg) {
3243
3265
  currentAttributes.background = bg;
3244
3266
  }
3267
+ const fontFamily = element.style?.fontFamily || element.style?.getPropertyValue?.("font-family");
3268
+ if (fontFamily) {
3269
+ currentAttributes.font = fontFamily.replace(/^["']|["']$/g, "");
3270
+ }
3271
+ const fontSize = element.style?.fontSize || element.style?.getPropertyValue?.("font-size");
3272
+ if (fontSize) {
3273
+ currentAttributes.size = fontSize;
3274
+ }
3245
3275
  processChildren(element);
3246
3276
  flushText();
3247
3277
  currentAttributes = prevAttrs;
@@ -3943,11 +3973,14 @@ function renderInlineText2(text, attributes) {
3943
3973
  if (link) {
3944
3974
  result = renderLink(result, link);
3945
3975
  }
3946
- if (typeof attributes.color === "string") {
3947
- result = `<span style="color: ${attributes.color}">${result}</span>`;
3948
- }
3949
- if (typeof attributes.background === "string") {
3950
- result = `<span style="background-color: ${attributes.background}">${result}</span>`;
3976
+ const styleProps = [];
3977
+ if (typeof attributes.color === "string") styleProps.push(`color: ${attributes.color}`);
3978
+ if (typeof attributes.background === "string")
3979
+ styleProps.push(`background-color: ${attributes.background}`);
3980
+ if (typeof attributes.font === "string") styleProps.push(`font-family: ${attributes.font}`);
3981
+ if (typeof attributes.size === "string") styleProps.push(`font-size: ${attributes.size}`);
3982
+ if (styleProps.length > 0) {
3983
+ result = `<span style="${styleProps.join("; ")}">${result}</span>`;
3951
3984
  }
3952
3985
  return result;
3953
3986
  }
@@ -4689,6 +4722,19 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
4689
4722
  currentInlineAttrs = { ...currentInlineAttrs, background: bgMatch[1].trim() };
4690
4723
  addedKeys.push("background");
4691
4724
  }
4725
+ const fontMatch = style.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i);
4726
+ if (fontMatch) {
4727
+ currentInlineAttrs = {
4728
+ ...currentInlineAttrs,
4729
+ font: fontMatch[1].trim().replace(/^["']|["']$/g, "")
4730
+ };
4731
+ addedKeys.push("font");
4732
+ }
4733
+ const sizeMatch = style.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i);
4734
+ if (sizeMatch) {
4735
+ currentInlineAttrs = { ...currentInlineAttrs, size: sizeMatch[1].trim() };
4736
+ addedKeys.push("size");
4737
+ }
4692
4738
  spanAttrStack.push(addedKeys);
4693
4739
  return;
4694
4740
  }
@@ -4799,6 +4845,7 @@ export {
4799
4845
  dividerFormat,
4800
4846
  escapeHtml,
4801
4847
  extractBoxOpAttributes,
4848
+ fontFormat,
4802
4849
  footnoteRefFormat,
4803
4850
  footnotesBlockHandler,
4804
4851
  formulaFormat,
@@ -4825,6 +4872,7 @@ export {
4825
4872
  nodeAdapter,
4826
4873
  normalizeDelta,
4827
4874
  sanitizeDelta,
4875
+ sizeFormat,
4828
4876
  slugify,
4829
4877
  slugifyWithDedup,
4830
4878
  strikeFormat,