Automatically convert spaces to tabs in codeblocks

• Adds codeblock css rule for tab-size
• Only applies to GDScript/C++
• Fix some inconsistent cpp codeblock filters
This commit is contained in:
Thaddeus Crews
2023-10-03 22:18:53 -05:00
parent adbab1482c
commit acf09b8551
4 changed files with 28 additions and 14 deletions

View File

@@ -846,6 +846,7 @@ code,
.highlight {
background-color: var(--highlight-background-color);
tab-size: 4;
}
/* Emphasized lines */

View File

@@ -291,6 +291,19 @@ $(document).ready(() => {
}
}
// Change indentation from spaces to tabs for codeblocks.
const codeBlocks = document.querySelectorAll('.rst-content div[class^="highlight"] pre');
for (const codeBlock of codeBlocks) {
const classList = codeBlock.parentNode.parentNode.classList;
if (!classList.contains('highlight-gdscript') && !classList.contains('highlight-cpp')) {
// Only change indentation for GDScript and C++.
continue;
}
let html = codeBlock.innerHTML;
html = html.replace(/(?<=^(<span class="w">)?( {4})*)( {4})/gm, '\t');
codeBlock.innerHTML = html;
}
// See `godot_is_latest` in conf.py
const isLatest = document.querySelector('meta[name=doc_is_latest]').content.toLowerCase() === 'true';
if (isLatest) {