@scrider/formatter 1.3.4 → 1.3.6

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