+ 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);
+ }
+ }
+ }
+ }