@scrider/formatter 1.3.4 → 1.3.5

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
@@ -61,6 +61,7 @@ __export(index_exports, {
61
61
  deltaToHtml: () => deltaToHtml,
62
62
  deltaToMarkdown: () => deltaToMarkdown,
63
63
  dividerFormat: () => dividerFormat,
64
+ documentPresentationStyleParts: () => documentPresentationStyleParts,
64
65
  escapeHtml: () => escapeHtml,
65
66
  extractBoxOpAttributes: () => extractBoxOpAttributes,
66
67
  extractTableRegion: () => extractTableRegion,
@@ -93,6 +94,7 @@ __export(index_exports, {
93
94
  nodeAdapter: () => nodeAdapter,
94
95
  normalizeDelta: () => normalizeDelta,
95
96
  preloadRemark: () => preloadRemark,
97
+ resolveDocumentPresentation: () => resolveDocumentPresentation,
96
98
  resolveTablePresentation: () => resolveTablePresentation,
97
99
  sanitizeDelta: () => sanitizeDelta,
98
100
  sizeFormat: () => sizeFormat,
@@ -2601,6 +2603,32 @@ function slugifyWithDedup(text, usedSlugs) {
2601
2603
  return `${base}-${count}`;
2602
2604
  }
2603
2605
 
2606
+ // src/conversion/html/document-presentation.ts
2607
+ function resolveDocumentPresentation(presentation) {
2608
+ if (!presentation) return void 0;
2609
+ const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
2610
+ const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
2611
+ if (lineSpacing === void 0 && textIndentCm === void 0) return void 0;
2612
+ return { lineSpacing, textIndentCm };
2613
+ }
2614
+ var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
2615
+ function documentPresentationStyleParts(tag, resolved) {
2616
+ if (!resolved) return [];
2617
+ const parts = [];
2618
+ if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
2619
+ const pct = Math.round(resolved.lineSpacing * 100);
2620
+ parts.push(`line-height:${resolved.lineSpacing}`);
2621
+ parts.push(`mso-line-height-alt:${pct}%`);
2622
+ }
2623
+ if (resolved.textIndentCm !== void 0 && tag === "p") {
2624
+ parts.push(`text-indent:${resolved.textIndentCm}cm`);
2625
+ }
2626
+ return parts;
2627
+ }
2628
+ function joinStyleParts(parts) {
2629
+ return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
2630
+ }
2631
+
2604
2632
  // src/conversion/html/table-presentation.ts
2605
2633
  var DEFAULT_BORDER_COLOR = "#e7e7e7";
2606
2634
  var DEFAULT_HEADER_BG = "#f5f5f5";
@@ -2671,6 +2699,7 @@ function deltaToHtml(delta, options = {}) {
2671
2699
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
2672
2700
  const blockHandlers = options.blockHandlers;
2673
2701
  const anchorLinks = options.anchorLinks ?? false;
2702
+ const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
2674
2703
  let html = "";
2675
2704
  let listStack = [];
2676
2705
  let counters = [];
@@ -2733,7 +2762,14 @@ function deltaToHtml(delta, options = {}) {
2733
2762
  if (hierarchicalNumbers && listType === "ordered") {
2734
2763
  hierarchicalNumber = counters.slice(0, indent + 1).join(".");
2735
2764
  }
2736
- html += renderListItem(content, listItemAttrs, pretty, indentLevel, hierarchicalNumber);
2765
+ html += renderListItem(
2766
+ content,
2767
+ listItemAttrs,
2768
+ pretty,
2769
+ indentLevel,
2770
+ hierarchicalNumber,
2771
+ resolvedDocumentPresentation
2772
+ );
2737
2773
  } else {
2738
2774
  let headingId;
2739
2775
  if (line.attributes?.header) {
@@ -2745,7 +2781,14 @@ function deltaToHtml(delta, options = {}) {
2745
2781
  headingId = slugifyWithDedup(plainText, slugUsageMap);
2746
2782
  }
2747
2783
  }
2748
- html += renderBlock(content, tag, line.attributes, pretty, headingId);
2784
+ html += renderBlock(
2785
+ content,
2786
+ tag,
2787
+ line.attributes,
2788
+ pretty,
2789
+ headingId,
2790
+ resolvedDocumentPresentation
2791
+ );
2749
2792
  }
2750
2793
  }
2751
2794
  html += closeAllLists(listStack, pretty);
@@ -3037,36 +3080,41 @@ function getListItemAttributes(attributes) {
3037
3080
  }
3038
3081
  return "";
3039
3082
  }
3040
- function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber) {
3083
+ function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
3041
3084
  const indent = pretty ? getIndent(indentLevel) : "";
3042
3085
  const innerContent = content || "<br>";
3043
3086
  let fullAttrs = attrs;
3044
3087
  if (hierarchicalNumber) {
3045
3088
  fullAttrs += ` data-number="${hierarchicalNumber}"`;
3046
3089
  }
3090
+ const styleAttr = joinStyleParts(
3091
+ documentPresentationStyleParts("li", resolvedDocumentPresentation)
3092
+ );
3093
+ fullAttrs += styleAttr;
3047
3094
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
3048
3095
  return pretty ? html + "\n" : html;
3049
3096
  }
3050
- function renderBlock(content, tag, attributes, pretty, id) {
3097
+ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
3051
3098
  const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
3052
- const styleAttr = getBlockStyleAttribute(attributes);
3099
+ const styleAttr = getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation);
3053
3100
  const innerContent = content || "<br>";
3054
3101
  const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
3055
3102
  return pretty ? html + "\n" : html;
3056
3103
  }
3057
- function getBlockStyleAttribute(attributes) {
3058
- if (!attributes) return "";
3059
- const styles = [];
3060
- const alignVal = attributes.align;
3061
- if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
3062
- styles.push(`text-align: ${alignVal}`);
3063
- }
3064
- if (attributes.indent && typeof attributes.indent === "number") {
3065
- if (!attributes.list) {
3066
- styles.push(`margin-left: ${attributes.indent * 2}em`);
3104
+ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3105
+ const styles = documentPresentationStyleParts(tag, resolvedDocumentPresentation);
3106
+ if (attributes) {
3107
+ const alignVal = attributes.align;
3108
+ if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
3109
+ styles.push(`text-align: ${alignVal}`);
3110
+ }
3111
+ if (attributes.indent && typeof attributes.indent === "number") {
3112
+ if (!attributes.list) {
3113
+ styles.push(`margin-left: ${attributes.indent * 2}em`);
3114
+ }
3067
3115
  }
3068
3116
  }
3069
- return styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
3117
+ return joinStyleParts(styles);
3070
3118
  }
3071
3119
  function extractPlainText(ops) {
3072
3120
  let text = "";
@@ -5219,6 +5267,7 @@ function extractTableRegion(ops, hintOpIdx) {
5219
5267
  deltaToHtml,
5220
5268
  deltaToMarkdown,
5221
5269
  dividerFormat,
5270
+ documentPresentationStyleParts,
5222
5271
  escapeHtml,
5223
5272
  extractBoxOpAttributes,
5224
5273
  extractTableRegion,
@@ -5251,6 +5300,7 @@ function extractTableRegion(ops, hintOpIdx) {
5251
5300
  nodeAdapter,
5252
5301
  normalizeDelta,
5253
5302
  preloadRemark,
5303
+ resolveDocumentPresentation,
5254
5304
  resolveTablePresentation,
5255
5305
  sanitizeDelta,
5256
5306
  sizeFormat,