mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
Fix midword link wrapping issues
Adds <wbr> which is suggested linebreaks to each class reference link in the sidebar once the page is ready.
This commit is contained in:
@@ -250,6 +250,30 @@ $(document).ready(() => {
|
||||
registerOnScrollEvent(mediaQuery);
|
||||
});
|
||||
|
||||
// Add line-break suggestions to class refernece navigation items.
|
||||
const classReferenceLinks = document.querySelectorAll('.wy-menu-vertical > ul:last-of-type .reference.internal');
|
||||
for (const linkItem of classReferenceLinks) {
|
||||
let textNode = null;
|
||||
linkItem.childNodes.forEach(it => {
|
||||
if (it.nodeType === Node.TEXT_NODE) {
|
||||
// If this is a text node and if it needs to be updated, store a reference.
|
||||
let text = it.textContent;
|
||||
if (!(text.includes(" ") || text.length < 10)) {
|
||||
textNode = it;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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](?!$))|(?<!^)[A-Z](?=[a-z]))/gm, '<wbr>$1');
|
||||
|
||||
linkItem.removeChild(textNode);
|
||||
linkItem.insertAdjacentHTML('beforeend', text);
|
||||
}
|
||||
}
|
||||
|
||||
if (inDev) {
|
||||
// Add a compatibility notice using JavaScript so it doesn't end up in the
|
||||
// automatically generated `meta description` tag.
|
||||
|
||||
2
conf.py
2
conf.py
@@ -196,7 +196,7 @@ if not on_rtd:
|
||||
html_css_files.append("css/dev.css")
|
||||
|
||||
html_js_files = [
|
||||
"js/custom.js?2", # Increment the number at the end when the file changes to bust the cache.
|
||||
"js/custom.js?3", # Increment the number at the end when the file changes to bust the cache.
|
||||
('https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js', {'defer': 'defer'}),
|
||||
('js/algolia.js', {'defer': 'defer'})
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user