};
const applyTransforms = function (node) {
+ const document = node.ownerDocument;
+ const LMN = Lemon.bind(document);
if (
node.localName == "pre" && node.childNodes.length == 1 &&
node.firstChild.localName == "code"
}
if (node.nodeType == 1) {
// This is an element; process its children.
+ if (node.localName == "code") {
+ // This is a `<code>` element; wrap it in a `Word-Wrap: Pre` with
+ // any previous/next characters to prevent line‐breaking due to
+ // it being rendered as an inline block.
+ const prev = node.previousSibling;
+ const prevText = prev?.nodeType == 3 ? prev.textContent : "";
+ const prevWrap = prevText.match(/\S*$/u)[0];
+ const next = node.nextSibling;
+ const nextText = next?.nodeType == 3 ? next.textContent : "";
+ const nextWrap = nextText.match(/^\S*/u)[0];
+ if (prevWrap || nextWrap) {
+ const span = LMN.span.style("White-Space: Pre")``;
+ node.parentNode.replaceChild(span, node);
+ if (prevWrap) {
+ prev.parentNode.replaceChild(
+ document.createTextNode(
+ prevText.substring(0, prevText.length - prevWrap.length),
+ ),
+ prev,
+ );
+ span.appendChild(
+ document.createTextNode(
+ prevText.substring(prevText.length - prevWrap.length),
+ ),
+ );
+ }
+ span.appendChild(node);
+ if (nextWrap) {
+ const nexts = [
+ document.createTextNode(
+ nextText.substring(0, nextWrap.length),
+ ),
+ document.createTextNode(
+ nextText.substring(nextWrap.length),
+ ),
+ ];
+ span.appendChild(nexts[0]);
+ next.parentNode.replaceChild(nexts[1], next);
+ for (const nextNode of nexts) {
+ applyTransforms.call(this, nextNode);
+ }
+ }
+ }
+ }
Array.from(node.childNodes).forEach(applyTransforms.bind(this));
} else if (node.nodeType == 3) {
// This is a text node; apply replacements.
};
await import(
- "https://git.ladys.computer/Beorn/blob_plain/0.2.3:/build.js"
+ "https://git.ladys.computer/Beorn/blob_plain/0.2.4:/build.js"
);