godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Inline code hightlighting

Open Qubus0 opened this issue 3 months ago • 6 comments

while working on #11217 i was curious if it was possible to add inline code highlighting like we have it for the mod loader docs, and it turns out that it is possible by adding this to the files

.. role:: gd(code)
   :language: gdscript

The following is the list of supported operators and their precedence. All binary operators are `left-associative <https://en.wikipedia.org/wiki/Operator_associativity>`_,
including the :gd:`**` operator. This means that :gd:`2 ** 2 ** 3` is equal to :gd:`(2 ** 2) ** 3`. Use parentheses to explicitly specify precedence you need, for
example :gd:`2 ** (2 ** 3)`. The ternary :gd:`if/else` operator is right-associative.

which does result in all the proper code highlights.

Before After
Image Image

note that :language: gd results in the old lexer being used, i think, so not everything is properly highlighted, but :language: gdscript works just fine.

now the question - do we want this? it's neat, but also quite some effort to pull through everywhere, especially when tables break. also new contributions should probably use this too, which adds a bit more contribution friction

regex replace with

``(.*?)``
:gd:`$1`

does work alright, but of course not everything is gdscript

Qubus0 avatar Aug 31 '25 13:08 Qubus0