Skip to content

Commit 95869e4

Browse files
authored
Merge pull request #8153 from Repiteo/space-to-tab-v2
Automatically convert spaces to tabs in CodeBlocks
2 parents 17f0da6 + acf09b8 commit 95869e4

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

_static/css/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ code,
846846

847847
.highlight {
848848
background-color: var(--highlight-background-color);
849+
tab-size: 4;
849850
}
850851

851852
/* Emphasized lines */

_static/js/custom.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ $(document).ready(() => {
291291
}
292292
}
293293

294+
// Change indentation from spaces to tabs for codeblocks.
295+
const codeBlocks = document.querySelectorAll('.rst-content div[class^="highlight"] pre');
296+
for (const codeBlock of codeBlocks) {
297+
const classList = codeBlock.parentNode.parentNode.classList;
298+
if (!classList.contains('highlight-gdscript') && !classList.contains('highlight-cpp')) {
299+
// Only change indentation for GDScript and C++.
300+
continue;
301+
}
302+
let html = codeBlock.innerHTML;
303+
html = html.replace(/(?<=^(<span class="w">)?( {4})*)( {4})/gm, '\t');
304+
codeBlock.innerHTML = html;
305+
}
306+
294307
// See `godot_is_latest` in conf.py
295308
const isLatest = document.querySelector('meta[name=doc_is_latest]').content.toLowerCase() === 'true';
296309
if (isLatest) {

tutorials/migrating/upgrading_to_godot_4.1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ This means that GDExtensions made for Godot 4.0 will need to be recompiled for G
253253

254254
In Godot 4.0, your "entry_symbol" function looks something like this:
255255

256-
.. code-block:: C++
256+
.. code-block:: cpp
257257
258258
GDExtensionBool GDE_EXPORT example_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
259259
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
@@ -267,7 +267,7 @@ In Godot 4.0, your "entry_symbol" function looks something like this:
267267
268268
However, for Godot 4.1, it should look like:
269269

270-
.. code-block:: C++
270+
.. code-block:: cpp
271271
272272
GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
273273
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

tutorials/scripting/gdextension/gdextension_cpp_example.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Your folder structure should now look like this:
158158
In the ``src`` folder, we'll start with creating our header file for the
159159
GDExtension node we'll be creating. We will name it ``gdexample.h``:
160160

161-
.. code-block:: C++
161+
.. code-block:: cpp
162162
163163
#ifndef GDEXAMPLE_H
164164
#define GDEXAMPLE_H
@@ -211,7 +211,7 @@ as the ``_process`` function you're used to in GDScript.
211211

212212
Let's implement our functions by creating our ``gdexample.cpp`` file:
213213

214-
.. code-block:: C++
214+
.. code-block:: cpp
215215
216216
#include "gdexample.h"
217217
#include <godot_cpp/core/class_db.hpp>
@@ -250,7 +250,7 @@ and source file like we've implemented ``GDExample`` up above. What we need now
250250
is a small bit of code that tells Godot about all the classes in our
251251
GDExtension plugin.
252252

253-
.. code-block:: C++
253+
.. code-block:: cpp
254254
255255
#include "register_types.h"
256256
@@ -303,7 +303,7 @@ Furthermore, it sets the level of initialization (core, servers, scene, editor,
303303
At last, we need the header file for the ``register_types.cpp`` named
304304
``register_types.h``.
305305

306-
.. code-block:: C++
306+
.. code-block:: cpp
307307
308308
#ifndef GDEXAMPLE_REGISTER_TYPES_H
309309
#define GDEXAMPLE_REGISTER_TYPES_H
@@ -466,7 +466,7 @@ Lets add a property that allows us to control the amplitude of our wave.
466466
In our ``gdexample.h`` file we need to add a member variable and getter and setter
467467
functions:
468468

469-
.. code-block:: C++
469+
.. code-block:: cpp
470470
471471
...
472472
private:
@@ -481,7 +481,7 @@ functions:
481481
In our ``gdexample.cpp`` file we need to make a number of changes, we will only
482482
show the methods we end up changing, don't remove the lines we're omitting:
483483

484-
.. code-block:: C++
484+
.. code-block:: cpp
485485
486486
void GDExample::_bind_methods() {
487487
ClassDB::bind_method(D_METHOD("get_amplitude"), &GDExample::get_amplitude);
@@ -523,7 +523,7 @@ Let's do the same but for the speed of our animation and use a setter and getter
523523
function. Our ``gdexample.h`` header file again only needs a few more lines of
524524
code:
525525

526-
.. code-block:: C++
526+
.. code-block:: cpp
527527
528528
...
529529
double amplitude;
@@ -537,7 +537,7 @@ code:
537537
This requires a few more changes to our ``gdexample.cpp`` file, again we're only
538538
showing the methods that have changed so don't remove anything we're omitting:
539539

540-
.. code-block:: C++
540+
.. code-block:: cpp
541541
542542
void GDExample::_bind_methods() {
543543
...
@@ -594,7 +594,7 @@ would need to showcase a far more complete example.
594594

595595
This is the required syntax:
596596

597-
.. code-block:: C++
597+
.. code-block:: cpp
598598
599599
some_other_node->connect("the_signal", this, "my_method");
600600
@@ -607,7 +607,7 @@ emit a signal every time a second has passed and pass the new location along.
607607

608608
In our ``gdexample.h`` header file, we need to define a new member ``time_emit``:
609609

610-
.. code-block:: C++
610+
.. code-block:: cpp
611611
612612
...
613613
double time_passed;
@@ -622,7 +622,7 @@ constructor. We'll look at the other 2 needed changes one by one.
622622
In our ``_bind_methods`` method, we need to declare our signal. This is done
623623
as follows:
624624

625-
.. code-block:: C++
625+
.. code-block:: cpp
626626
627627
void GDExample::_bind_methods() {
628628
...
@@ -643,7 +643,7 @@ of type ``Vector2``, respectively named "node" and "new_pos".
643643

644644
Next, we'll need to change our ``_process`` method:
645645

646-
.. code-block:: C++
646+
.. code-block:: cpp
647647
648648
void GDExample::_process(double delta) {
649649
time_passed += speed * delta;

0 commit comments

Comments
 (0)