From 52903b7778d05113c54704f796fbefb3f7c0882d Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Thu, 29 Dec 2022 18:36:53 +0300 Subject: [PATCH] Simplify midword break regex to avoid unsupported features --- _static/js/custom.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/_static/js/custom.js b/_static/js/custom.js index 9fe65df2e..ac0d267a1 100644 --- a/_static/js/custom.js +++ b/_static/js/custom.js @@ -250,7 +250,16 @@ $(document).ready(() => { registerOnScrollEvent(mediaQuery); }); - // Add line-break suggestions to class refernece navigation items. + // Add line-break suggestions to the sidebar navigation items in the class reference section. + // + // Some class reference pages have very long PascalCase names, such as + // VisualShaderNodeCurveXYZTexture + // Those create issues for our layout, as we can neither make them wrap with CSS without + // breaking normal article titles, nor is it good to have them overflow their containers. + // So we use a tag to insert mid-word suggestions for appropriate splits, so the browser + // knows that it's okay to split it like + // Visual Shader Node Curve XYZTexture + // and add a new line at an opportune moment. const classReferenceLinks = document.querySelectorAll('.wy-menu-vertical > ul:last-of-type .reference.internal'); for (const linkItem of classReferenceLinks) { let textNode = null; @@ -266,8 +275,10 @@ $(document).ready(() => { if (textNode != null) { let text = textNode.textContent; - // Adds suggested line-breaks, if needed, and replace the original text. - text = text.replace(/((?:(?<=[a-z])[A-Z0-9](?!$))|(?$1'); + // Add suggested line-breaks and replace the original text. + // The regex looks for a lowercase letter followed by a number or an uppercase + // letter. We avoid splitting at the last character in the name, though. + text = text.replace(/([a-z])([A-Z0-9](?!$))/gm, '$1$2'); linkItem.removeChild(textNode); linkItem.insertAdjacentHTML('beforeend', text);