@scrider/formatter 1.0.1 → 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.cjs CHANGED
@@ -63,6 +63,7 @@ __export(index_exports, {
63
63
  dividerFormat: () => dividerFormat,
64
64
  escapeHtml: () => escapeHtml,
65
65
  extractBoxOpAttributes: () => extractBoxOpAttributes,
66
+ fontFormat: () => fontFormat,
66
67
  footnoteRefFormat: () => footnoteRefFormat,
67
68
  footnotesBlockHandler: () => footnotesBlockHandler,
68
69
  formulaFormat: () => formulaFormat,
@@ -89,6 +90,7 @@ __export(index_exports, {
89
90
  nodeAdapter: () => nodeAdapter,
90
91
  normalizeDelta: () => normalizeDelta,
91
92
  sanitizeDelta: () => sanitizeDelta,
93
+ sizeFormat: () => sizeFormat,
92
94
  slugify: () => slugify,
93
95
  slugifyWithDedup: () => slugifyWithDedup,
94
96
  strikeFormat: () => strikeFormat,
@@ -1663,6 +1665,15 @@ var colorFormat = {
1663
1665
  }
1664
1666
  };
1665
1667
 
1668
+ // src/schema/formats/inline/font.ts
1669
+ var fontFormat = {
1670
+ name: "font",
1671
+ scope: "inline",
1672
+ validate(value) {
1673
+ return typeof value === "string" && value.length > 0;
1674
+ }
1675
+ };
1676
+
1666
1677
  // src/schema/formats/inline/italic.ts
1667
1678
  var italicFormat = {
1668
1679
  name: "italic",
@@ -1720,6 +1731,15 @@ var markFormat = {
1720
1731
  }
1721
1732
  };
1722
1733
 
1734
+ // src/schema/formats/inline/size.ts
1735
+ var sizeFormat = {
1736
+ name: "size",
1737
+ scope: "inline",
1738
+ validate(value) {
1739
+ return typeof value === "string" && value.length > 0;
1740
+ }
1741
+ };
1742
+
1723
1743
  // src/schema/formats/inline/strike.ts
1724
1744
  var strikeFormat = {
1725
1745
  name: "strike",
@@ -1927,7 +1947,9 @@ var INLINE_FORMAT_ORDER = [
1927
1947
  ];
1928
1948
  var INLINE_STYLE_FORMATS = {
1929
1949
  color: "color",
1930
- background: "background-color"
1950
+ background: "background-color",
1951
+ font: "font-family",
1952
+ size: "font-size"
1931
1953
  };
1932
1954
  var BLOCK_FORMAT_TAGS = {
1933
1955
  header: (value) => `h${String(value)}`,
@@ -2312,6 +2334,8 @@ var defaultInlineFormats = [
2312
2334
  linkFormat,
2313
2335
  colorFormat,
2314
2336
  backgroundFormat,
2337
+ fontFormat,
2338
+ sizeFormat,
2315
2339
  markFormat,
2316
2340
  kbdFormat
2317
2341
  ];
@@ -3342,6 +3366,14 @@ function htmlToDelta(html, options = {}) {
3342
3366
  if (bg) {
3343
3367
  currentAttributes.background = bg;
3344
3368
  }
3369
+ const fontFamily = element.style?.fontFamily || element.style?.getPropertyValue?.("font-family");
3370
+ if (fontFamily) {
3371
+ currentAttributes.font = fontFamily.replace(/^["']|["']$/g, "");
3372
+ }
3373
+ const fontSize = element.style?.fontSize || element.style?.getPropertyValue?.("font-size");
3374
+ if (fontSize) {
3375
+ currentAttributes.size = fontSize;
3376
+ }
3345
3377
  processChildren(element);
3346
3378
  flushText();
3347
3379
  currentAttributes = prevAttrs;
@@ -4043,11 +4075,14 @@ function renderInlineText2(text, attributes) {
4043
4075
  if (link) {
4044
4076
  result = renderLink(result, link);
4045
4077
  }
4046
- if (typeof attributes.color === "string") {
4047
- result = `<span style="color: ${attributes.color}">${result}</span>`;
4048
- }
4049
- if (typeof attributes.background === "string") {
4050
- result = `<span style="background-color: ${attributes.background}">${result}</span>`;
4078
+ const styleProps = [];
4079
+ if (typeof attributes.color === "string") styleProps.push(`color: ${attributes.color}`);
4080
+ if (typeof attributes.background === "string")
4081
+ styleProps.push(`background-color: ${attributes.background}`);
4082
+ if (typeof attributes.font === "string") styleProps.push(`font-family: ${attributes.font}`);
4083
+ if (typeof attributes.size === "string") styleProps.push(`font-size: ${attributes.size}`);
4084
+ if (styleProps.length > 0) {
4085
+ result = `<span style="${styleProps.join("; ")}">${result}</span>`;
4051
4086
  }
4052
4087
  return result;
4053
4088
  }
@@ -4789,6 +4824,19 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
4789
4824
  currentInlineAttrs = { ...currentInlineAttrs, background: bgMatch[1].trim() };
4790
4825
  addedKeys.push("background");
4791
4826
  }
4827
+ const fontMatch = style.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i);
4828
+ if (fontMatch) {
4829
+ currentInlineAttrs = {
4830
+ ...currentInlineAttrs,
4831
+ font: fontMatch[1].trim().replace(/^["']|["']$/g, "")
4832
+ };
4833
+ addedKeys.push("font");
4834
+ }
4835
+ const sizeMatch = style.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i);
4836
+ if (sizeMatch) {
4837
+ currentInlineAttrs = { ...currentInlineAttrs, size: sizeMatch[1].trim() };
4838
+ addedKeys.push("size");
4839
+ }
4792
4840
  spanAttrStack.push(addedKeys);
4793
4841
  return;
4794
4842
  }
@@ -4900,6 +4948,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
4900
4948
  dividerFormat,
4901
4949
  escapeHtml,
4902
4950
  extractBoxOpAttributes,
4951
+ fontFormat,
4903
4952
  footnoteRefFormat,
4904
4953
  footnotesBlockHandler,
4905
4954
  formulaFormat,
@@ -4926,6 +4975,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
4926
4975
  nodeAdapter,
4927
4976
  normalizeDelta,
4928
4977
  sanitizeDelta,
4978
+ sizeFormat,
4929
4979
  slugify,
4930
4980
  slugifyWithDedup,
4931
4981
  strikeFormat,