@scrider/formatter 1.8.7 → 1.9.1

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
@@ -73,6 +73,7 @@ __export(index_exports, {
73
73
  deltaToHtml: () => deltaToHtml,
74
74
  deltaToMarkdown: () => deltaToMarkdown,
75
75
  dividerFormat: () => dividerFormat,
76
+ documentMetadataToPresentation: () => documentMetadataToPresentation,
76
77
  documentPresentationStyleParts: () => documentPresentationStyleParts,
77
78
  escapeHtml: () => escapeHtml,
78
79
  extractBoxOpAttributes: () => extractBoxOpAttributes,
@@ -998,10 +999,12 @@ function renderTableHostWrapperOpen(data, pretty) {
998
999
  attrs.push(`data-block-align="${escapeHtml(data.blockAlign)}"`);
999
1000
  }
1000
1001
  const styleParts = [];
1001
- if (data.width != null && data.width > 0) {
1002
+ if (data.blockAlign === "justify" && !data.float) {
1003
+ styleParts.push("width: 100%");
1004
+ } else if (data.width != null && data.width > 0) {
1002
1005
  styleParts.push(`width: ${Math.round(data.width)}px`);
1003
1006
  styleParts.push("max-width: 100%");
1004
- } else if (data.blockAlign === "justify" && !data.float) {
1007
+ } else if (data.blockAlign && !data.float) {
1005
1008
  styleParts.push("width: 100%");
1006
1009
  }
1007
1010
  if (styleParts.length > 0) attrs.push(`style="${styleParts.join("; ")}"`);
@@ -2622,6 +2625,7 @@ var codeWidgetFormat = {
2622
2625
  var dividerFormat = {
2623
2626
  name: "divider",
2624
2627
  scope: "embed",
2628
+ blockLevel: true,
2625
2629
  normalize(value) {
2626
2630
  return !!value;
2627
2631
  },
@@ -3243,6 +3247,26 @@ function resolveDocumentPresentation(presentation) {
3243
3247
  listBlockIndentCm
3244
3248
  };
3245
3249
  }
3250
+ function documentMetadataToPresentation(metadata) {
3251
+ if (!metadata) return void 0;
3252
+ const presentation = {};
3253
+ if (typeof metadata.lineSpacing === "number") {
3254
+ presentation.lineSpacing = metadata.lineSpacing;
3255
+ }
3256
+ if (typeof metadata.paragraphSpacingBeforeEm === "number") {
3257
+ presentation.paragraphSpacingBeforeEm = metadata.paragraphSpacingBeforeEm;
3258
+ }
3259
+ if (typeof metadata.paragraphSpacingAfterEm === "number") {
3260
+ presentation.paragraphSpacingAfterEm = metadata.paragraphSpacingAfterEm;
3261
+ }
3262
+ if (typeof metadata.textIndentCm === "number") {
3263
+ presentation.textIndentCm = metadata.textIndentCm;
3264
+ }
3265
+ if (typeof metadata.listBlockIndentCm === "number") {
3266
+ presentation.listBlockIndentCm = metadata.listBlockIndentCm;
3267
+ }
3268
+ return Object.keys(presentation).length > 0 ? presentation : void 0;
3269
+ }
3246
3270
  var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
3247
3271
  function documentPresentationListWrapperStyleParts(resolved) {
3248
3272
  if (!resolved?.listBlockIndentCm) return [];
@@ -3428,7 +3452,9 @@ function deltaToHtml(delta, options = {}) {
3428
3452
  const hierarchicalNumbers = options.hierarchicalNumbers ?? false;
3429
3453
  const blockHandlers = options.blockHandlers;
3430
3454
  const anchorLinks = options.anchorLinks ?? false;
3431
- const resolvedDocumentPresentation = resolveDocumentPresentation(options.documentPresentation);
3455
+ const resolvedDocumentPresentation = resolveDocumentPresentation(
3456
+ options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
3457
+ );
3432
3458
  let html = "";
3433
3459
  let listStack = [];
3434
3460
  let counters = [];
@@ -4066,7 +4092,13 @@ function htmlToDelta(html, options = {}) {
4066
4092
  if (format.match) {
4067
4093
  const result = format.match(node);
4068
4094
  if (result != null) {
4095
+ if (format.blockLevel && !atLineStart) {
4096
+ context.pushNewline();
4097
+ }
4069
4098
  context.pushEmbed({ [format.name]: result.value }, result.attributes);
4099
+ if (format.blockLevel) {
4100
+ context.pushNewline();
4101
+ }
4070
4102
  return;
4071
4103
  }
4072
4104
  }
@@ -4081,6 +4113,9 @@ function htmlToDelta(html, options = {}) {
4081
4113
  return;
4082
4114
  }
4083
4115
  if (tagName === "hr") {
4116
+ if (!atLineStart) {
4117
+ context.pushNewline();
4118
+ }
4084
4119
  context.pushEmbed({ divider: true });
4085
4120
  context.pushNewline();
4086
4121
  return;
@@ -6200,6 +6235,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
6200
6235
  deltaToHtml,
6201
6236
  deltaToMarkdown,
6202
6237
  dividerFormat,
6238
+ documentMetadataToPresentation,
6203
6239
  documentPresentationStyleParts,
6204
6240
  escapeHtml,
6205
6241
  extractBoxOpAttributes,