-
-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code blocks from doxygen are not highlighted correctly #123
Comments
Hey, Thanks for raising this. Maybe Doxygen always assumes that code blocks are in the same code domain as the source files themselves. Maybe we can assume the same thing? I'm not sure how to set up syntax highlighted blocks in Sphinx/RST but we can give it a go. Cheers, |
Hi,
exactly.
The problem is, that Doxygen embeds semantical syntax highlighting into the But maybe we could just map the highlight information from doxygen to .highlight .hll { background-color: #ffffcc }
.highlight { background: #eeffcc; }
.highlight .c { color: #408090; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #007020 } /* Comment.Preproc */
.highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408090; background-color: #fff0f0 } /*
Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #303030 } /* Generic.Output */
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #902000 } /* Keyword.Type */
.highlight .m { color: #208050 } /* Literal.Number */
.highlight .s { color: #4070a0 } /* Literal.String */
.highlight .na { color: #4070a0 } /* Name.Attribute */
.highlight .nb { color: #007020 } /* Name.Builtin */
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.highlight .no { color: #60add5 } /* Name.Constant */
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #007020 } /* Name.Exception */
.highlight .nf { color: #06287e } /* Name.Function */
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #bb60d5 } /* Name.Variable */
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #208050 } /* Literal.Number.Float */
.highlight .mh { color: #208050 } /* Literal.Number.Hex */
.highlight .mi { color: #208050 } /* Literal.Number.Integer */
.highlight .mo { color: #208050 } /* Literal.Number.Oct */
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
.highlight .si { color: #70a0d0; font-style: italic } /*
Literal.String.Interpol */
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
.highlight .sr { color: #235388 } /* Literal.String.Regex */
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
.highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ Doxygen uses much less classes. I found this list in \definecolor{comment}{rgb}{0.5,0.0,0.0}
\definecolor{keyword}{rgb}{0.0,0.5,0.0}
\definecolor{keywordtype}{rgb}{0.38,0.25,0.125}
\definecolor{keywordflow}{rgb}{0.88,0.5,0.0}
\definecolor{preprocessor}{rgb}{0.5,0.38,0.125}
\definecolor{stringliteral}{rgb}{0.0,0.125,0.25}
\definecolor{charliteral}{rgb}{0.0,0.5,0.5}
\definecolor{vhdldigit}{rgb}{1.0,0.0,1.0}
\definecolor{vhdlkeyword}{rgb}{0.43,0.0,0.43}
\definecolor{vhdllogic}{rgb}{1.0,0.0,0.0}
\definecolor{vhdlchar}{rgb}{0.0,0.0,0.0}
Colors are irrelevant. |
I'm still looking for a solution, but it may take while because my |
Hey, Thanks for the bump. I guess we're all busy :) I think it is an interesting idea and your proposal of converting from doxygen to sphinx styles might well work. I'm afraid I've not rushed into it as I don't know where to begin so I need a little more time or prompting. Messages like yours do help. I'll try to find time to think about it some more and start investigations. Though if you find time yourself, I'll welcome any additional discoveries :) All the best, |
I figured out docutils' raw node and hacked up something based on the above style map. But it's only a hack and there are many things that I do not understand. Commit: rweickelt/breathe@ae2a87e |
Thank you for sharing. It is interesting to see an approach that works and maybe we can figure out a way to use something like this. Unfortunately we can't have raw html in the main code as I'm sure you're aware due to other output formats (though the latex is currently broken!) Good to see though. I can't promise much movement on this soon but I'll try to find some time to think about it. |
Yes. LaTeX should be considered. Perhaps this would work very similar. Well, we could also just implement it for html and fall back for other formats. |
Hi all, hope it's okay that I revived this old issue :) I just submited a patch to Doxygen that propagates language information to all In my own Doxygen theme I'm just removing all Doxygen-made highlighting in those blocks and passing the raw code + language info through Pygments to get proper highlighting. For anyone who's interested, here's a screenshot and link to live snapshot: https://twitter.com/czmosra/status/932068062693642242 |
@mosra thanks for the update. I think that it is especially important when documenting things such as language bindings etc... I don't know how much time it will take for doxygen to be released with your patch. Although there might be some hope:
We use conda-forge + breathe for the documentation of e.g. xtensor. So I can probably make a new build of the doxygen conda-package including your patch, and we could use it with breathe. |
I think it is safe to say that @mosra 's patch is in current Doxygen releases. Based upon reading the above is it safe to say that Breathe still needs to implement reading the additional XML and use it for rendering? |
+1 to this. It would be very helpful to feed the code-block's domain into sphinx. For example, I have a project that documents the C++ implementation, but it is littered with relative python wrapper "gotcha" example code-blocks to note slight differences in buffer object usages. Currently, I get a warning (related to this issue) for every python snippet in the C++ docs. |
@2bndy5, would it be possible for you (or someone else) to make a small example project to start discussion from? so we are aligned on what this feature request is about. |
After posting that comment, I tried to reproduce the warnings in a simple example project, but I was unable to do so. It seems that pygments is raising warnings for highly terse code-blocks. I also looked at the XML output for a few |
With a bit of poking around in Breathe and Sphinx I think what is needed is:
|
I would be happier if doxygen would output the domain of a code-block as the My use case wouldn't be solved by your proposed step 1 & 2 because I'm putting python code-blocks in a document created from a C++ header file. |
For me it does that. E.g., with ///
/// Something
/// \code{blah}
/// int main() {}
/// \endcode
/// something else
void f(); I get the Doxygen XML <detaileddescription>
<para>Something <programlisting filename=".blah"><codeline><highlight class="normal">int<sp/>main()<sp/>{}</highlight></codeline>
</programlisting> something else </para>
</detaileddescription> It seems that whatever is in {...} after the
All the line number stuff for
Hmm, it seems to me that individual |
exactly correct. I never noticed the |
I see that the Same is applied to MD-fenced code-blocks. |
I found an archive of the dead link in this comment: |
What I've tried so far:
Unfortunately, these changes don't seem to render any differently. All code-blocks still respect whatever the |
🤣fixing this typo solved it
Ironlically, language is spelled wrong 🤣 |
@jakobandersen I'm ready to submit your proposed implementation as a PR. Should I make any other considerations? Would breathe's Looking at the pygment lexers aliases, it seems that option may not be needed. |
I've added a bit that passes the |
Just FYI, it also gets specified when you use Doxygen's |
@mosra Interesting advice! I re-read the PR you submitted to doxygen, with my newly enlightened understanding, and I took your advice about using pygments to guess the lexer name from the full filename. Thanks for submitting that PR! |
Code blocks in doxygen are rendered as literal blocks without syntax highlighting. The reason is, that the doxygen XML output does not contain information about the used code domain.
The example code
produces the following XML output
The problem could be probably solved by using embedded rst but at the price of not having links to documented items.
The text was updated successfully, but these errors were encountered: