Skip to content

Commit 3b889d8

Browse files
committed
Callout margin reference improvement
1 parent 659d8a7 commit 3b889d8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

news/changelog-1.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Improve the performance of extremely large documents with margin elements by improving the efficiency of positioning the elements.
66

7+
## HTML Format
8+
9+
- Improved handling of margin references that appear within a callout. (#3003)
10+
711
## Dates
812

913
- Properly fall back to language only locale when a supported language-region locale isn't available. (#3059)

src/format/html/format-html-bootstrap.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,28 @@ const marginContainerForEl = (el: Element, doc: Document) => {
936936
}
937937
}
938938

939+
// Find the callout parent and create a container for the callout there
940+
// Walks up the parent stack until a callout element is found
941+
const findCalloutEl = (el: Element): Element | undefined => {
942+
console.log(el.parentElement?.classList);
943+
if (el.parentElement?.classList.contains("callout")) {
944+
return el.parentElement;
945+
} else if (el.parentElement) {
946+
return findCalloutEl(el.parentElement);
947+
} else {
948+
return undefined;
949+
}
950+
};
951+
const calloutEl = findCalloutEl(el);
952+
if (calloutEl) {
953+
const container = createMarginContainer(doc);
954+
calloutEl.parentNode?.insertBefore(
955+
container,
956+
calloutEl.nextElementSibling,
957+
);
958+
return container;
959+
}
960+
939961
// Deal with a paragraph
940962
const parentEl = el.parentElement;
941963
const cantContainBlockTags = ["P"];

0 commit comments

Comments
 (0)