diff options
author | Vladimír Vondruš <mosra@centrum.cz> | 2017-11-19 12:36:12 (GMT) |
---|---|---|
committer | Vladimír Vondruš <mosra@centrum.cz> | 2017-11-19 13:15:14 (GMT) |
commit | eaf8edbac7e6a1873aa5c4ff0df063cd367351d6 (patch) | |
tree | 4999e26ac9d19d631e120b73d64c949d3ba39538 /testing/014 | |
parent | ebf75c1fe8a0ff2cc9235155b6d63367944d6342 (diff) | |
download | Doxygen-eaf8edbac7e6a1873aa5c4ff0df063cd367351d6.zip Doxygen-eaf8edbac7e6a1873aa5c4ff0df063cd367351d6.tar.gz Doxygen-eaf8edbac7e6a1873aa5c4ff0df063cd367351d6.tar.bz2 |
Propagate language information to all <programlisting> XML elements.
This is based on work done in 141dbfd5a4f79c98da14a1b414c6db4e1b34618b
through ed9acb6e1bb81a2eec334180f7b8c1bf0598b444 and makes a few
behavioral changes to it.
There's a new attribute called `filename` and the `language` was removed,
because it could provide misleading information. This allows for more
flexibility on the user side. In particular:
* For historical reasons, `*.txt` files are marked by Doxygen as C++
(see https://bugzilla.gnome.org/show_bug.cgi?id=760836 for details).
In particular, code snippet included from a CMakeLists.txt file would
be marked and highlighted as C++. So in this case, the language
attribute would be very misleading.
* Doxygen is aware only of a very small subset of languages and thus a
lot of information can be lost when relying on its
extension-to-language-name conversion -- in particular, all
extensions that are not recognized are assumed to be C++. On the other
hand, putting more effort into its language detection algorithms is
not worth the time, as there will always be new languages that fail to
detect. So let's leave that on the user of the XML output instead.
* Using just file extension is not enough, it has to be a full filename.
For example, `*.txt` can be either a plain text file or a
`CMakeLists.txt`.
* The path is not stripped from the filename, as it also may contain
additional information that helps to detect the language better.
In addition to that, filenames of code snippets included via the \include
command and related are propagated to the <programlisting> element as
well.
With this change, (1) code snippets using simply
\code
some code
\endcode
will not produce any `filename` attribute and it's up to the user what to
do -- assume C++, detect language from contents or not highlight
anything.
<programlisting>
some code
</programlisting>
(2) Code snippets using
\code{.cmake}
some code
\endcode
will produce the following:
<programlisting filename=".cmake">
some code
</programlisting>
(3) And finally, \include, \dontinclude and related \skip, \skipline etc.
commands
\include path/to/some-file.py
will produce
<programlisting filename="path/to/some-file.py">
some code
</programlisting>
The tests were updated to check all three cases.
On the user side, when using Pygments for example, it's then just a
matter of calling pygments.lexers.find_lexer_class_for_filename() with
value of the `filename` attribute value and optionally also the code
snippet for additional language analysis.
Diffstat (limited to 'testing/014')
-rw-r--r-- | testing/014/indexpage.xml | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/testing/014/indexpage.xml b/testing/014/indexpage.xml index ad35261..e677e24 100644 --- a/testing/014/indexpage.xml +++ b/testing/014/indexpage.xml @@ -5,7 +5,7 @@ <title>My Project</title> <detaileddescription> <para> - <programlisting language="Python"> + <programlisting filename=".py"> <codeline> <highlight class="comment">#<sp/>comment<sp/>in<sp/>Python</highlight> <highlight class="normal"/> @@ -25,7 +25,7 @@ </programlisting> </para> <para> - <programlisting language="C++"> + <programlisting filename=".cpp"> <codeline> <highlight class="comment">//<sp/>comment<sp/>in<sp/>a<sp/>code<sp/>block</highlight> <highlight class="normal"/> @@ -37,6 +37,13 @@ </codeline> </programlisting> </para> + <para> + <programlisting> + <codeline> + <highlight class="normal">//<sp />implicit<sp />code<sp />language</highlight> + </codeline> + </programlisting> + </para> </detaileddescription> </compounddef> </doxygen> |