Open jwmcgettigan opened 1 year ago
We use a shell syntax highlighter there, but it's not designed for Windows-style path, hence the issue. If there is a cmd syntax highlighter as an alternative, we could use that. Or we could properly escape paths with double slashes.
And the first example will always be invalid, because it shows both the commands and a shell context (i.e. the current system path), which is not a part of the syntax.
We use a shell syntax highlighter there, but it's not designed for Windows-style path, hence the issue. If there is a cmd syntax highlighter as an alternative, we could use that. Or we could properly escape paths with double slashes.
And the first example will always be invalid, because it shows both the commands and a shell context (i.e. the current system path), which is not a part of the syntax.
Sorry, I'm not sure I understand what you mean. Can you elaborate?
- Are you configuring it to be a 'shell' syntax highlighter somewhere is that simply the default?
It's set as a page default using the .. highlight:: shell
line at the top, yes. And yes, Pygments is responsible for highlighting.
- I've tried using double slashes without success.
Then I guess we can't do that.
Sorry, I'm not sure I understand what you mean. Can you elaborate?
Some command line examples in the docs, including the one in your first image, include not only the command itself, but also the part that you see in the terminal, such as the name of the shell or the path in the local system. In this case it's C:\godot>
. This is done as a reference for the reader, I guess, but it's not a part of the valid syntax for bash shells or any other standard. So because of that it will always cause errors in the highlighter.
Pygments has Windows related lexers such as batch
and powershell
.
But they each have their own drawbacks compared to shell
.
I'm looking into creating a custom lexer like the GDScriptLexer
to handle:
That would be an overkill for this minor issue. Maintaining our own lexers as a workaround of shell syntax highlighting is out of scope for the project.
We can remove the context part, as it can be confusing anyway. And for slashes we can probably use forward slashes on all platforms. Most tools should be fine with that.
I've become much more familiar with Sphinx since I created this issue and so I have a better idea how to approach the problem.
I think that this issue is actually two issues:
.highlight
styles appear to be applying styles for a specific lexer/language (presumably shell
) to all code-blocks regardless of their language. Instead, language specific styles should be set in their language specific highlight class (e.g. .highlight-shell
and .highlight-powershell
).
batch
and powershell
lexers also had drawbacks. They both are having unwanted styles applied to them from the blanket .highlight
class... code-block:: none
which will prevent any styling from being applied to a code-block.Given the points above, I've opted to rename this issue to "Unwanted styles are being applied to code blocks by the .highlight
class" to address the first issue from above. I've updated the contents of the original post as well.
For the second issue above, I've created https://github.com/godotengine/godot-docs/issues/7016.
The way the highlighter works is it tokenizes the code, breaks it up into general-concept tokens, such as "identifier", "number", or "comment". Plus a few permutations of the concept to handle more complex cases. That's why all c
, c1
, cm
, and cs
are using the comment color. These CSS classes mean the same thing in any language, so they can be styled the same way, and we don't need to define some specific rules like .highlight-powershell .c1
.
Again, the lines starting with C:\godot>
break highlighting because they are not valid lines of any code.
Thank you for clarifying that for me. 🙏
If that is the case, then it sounds like the solution to this issue is to be aware and mindful of these rules that dictate how code-blocks tokenize the code and what styles are applied. This leads me to believe that https://github.com/godotengine/godot-docs/issues/7016 is likely sufficient enough to address what lead me to create this issue.
What do you think? While takeaway two may very well be overkill depending on the amount of effort required to implement it, I'm curious as to whether you think it is viable in the first place?
Is there a way to validate whether the content of a code-block is supported by its lexer?
It depends on the lexer. When the pages are built, it will err if it cannot parse the content at all (and I think the build itself will fail then). But the lexer can also be implemented in a recoverable way, and keep parsing through invalid syntax. The only recourse there is to disable highlighting for the block all together (with none
), and perhaps leave a note for the future.
Overall, yes, contributors should validate the look of the page they edit. But we are also lenient with documentation contributions and don't require anyone to build the docs locally to test. Many contributions are done through the GitHub's web editor tools, and that's fine.
Your Godot version:
Latest (4.0)
Issue description:
The current
.highlight
styles appear to be applying styles for a specific lexer/language (presumablyshell
) to all code-blocks regardless of their language. Instead, language specific styles should be set in their language specific highlight class (e.g..highlight-shell
and.highlight-powershell
).batch
andpowershell
lexers also have drawbacks. They both are having unwanted styles applied to them from the blanket.highlight
class... code-block:: none
which will prevent any styling from being applied to a code-block.Example:
.. code-block:: batch
command treated as comment.The highlight class and child classes
https://github.com/godotengine/godot-docs/blob/361bdfc6d000172df5d46913cce4fbcaaba0f0e5/_static/css/custom.css#L820-L924
URL to the documentation page (if already existing):
This section is shown in the above example.