@json-to-office/core-docx 4.4.0 → 4.4.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.js CHANGED
@@ -3293,6 +3293,7 @@ import {
3293
3293
  Header,
3294
3294
  ImageRun,
3295
3295
  Packer,
3296
+ LineRuleType as LineRuleType2,
3296
3297
  Paragraph as Paragraph2
3297
3298
  } from "docx";
3298
3299
  function createDocxJsRenderer() {
@@ -3546,21 +3547,33 @@ function sectionChildren(section2, resources) {
3546
3547
  const blocks = section2.children.map((block2) => emitBlock(block2, resources));
3547
3548
  const bookmark = section2.bookmark;
3548
3549
  if (!bookmark) return blocks;
3549
- const out = [];
3550
+ const out = [...blocks];
3550
3551
  if (bookmark.opens) {
3551
- out.push(
3552
- new Paragraph2({
3553
- children: [new BookmarkStart2(bookmark.name, bookmark.id)],
3554
- spacing: { before: 0, after: 0, line: 0 }
3555
- })
3556
- );
3552
+ const start = new BookmarkStart2(bookmark.name, bookmark.id);
3553
+ const first = out[0];
3554
+ if (first instanceof Paragraph2) {
3555
+ first.addRunToFront(start);
3556
+ } else {
3557
+ out.unshift(anchorParagraph(start));
3558
+ }
3557
3559
  }
3558
- out.push(...blocks);
3559
3560
  if (bookmark.closes) {
3560
- out.push(new Paragraph2({ children: [new BookmarkEnd2(bookmark.id)] }));
3561
+ const end = new BookmarkEnd2(bookmark.id);
3562
+ const last = out[out.length - 1];
3563
+ if (last instanceof Paragraph2) {
3564
+ last.addChildElement(end);
3565
+ } else {
3566
+ out.push(anchorParagraph(end));
3567
+ }
3561
3568
  }
3562
3569
  return out;
3563
3570
  }
3571
+ function anchorParagraph(anchor) {
3572
+ return new Paragraph2({
3573
+ children: [anchor],
3574
+ spacing: { before: 0, after: 0, line: 20, lineRule: LineRuleType2.EXACT }
3575
+ });
3576
+ }
3564
3577
  function coreProperties(ir) {
3565
3578
  const { metadata } = ir;
3566
3579
  return {