0

The Problem

I have the following snippet in one of my headers:

/**
 * @brief Simple function.
 * 
 * @verbatim 
 *     don't want the following to be rendered as &lt: > or \> !
 * @endverbatim
 * 
 * This function skips all \<li\> elements.
 */
void simple(void) {}

I'm running Doxygen and on the XML output I'm getting:

<memberdef kind="function" id="simple8hpp_1a6624a5381d71ba485b6c59bc71214607" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
    <detaileddescription>
<para><verbatim>*     don&apos;t want the following to be rendered as &amp;lt: &gt; or \&gt; !
* </verbatim></para>
<para>This function skips all &lt;li&gt; elements. </para>
    </detaileddescription>
</memberdef>

In the <detaileddescription>, my original > got replaced by &gt. I do not want that. How can I configure Doxygen so that replacement doesn't happen?

I've tried using Doxygen 1.8.17 and 1.9.6 (c144c104ca2c0453cc5b19ce4c1b302cc2e4d929*), the result is the same.

According to this answer, the \verbatim block should not replace those. Also escaping with \< should also work.

Full Context

Doxygen is actually being called by Breathe. I'm trying to create a ReTxT reference like so:

/**
 * @brief Simple function.
 * 
 * @verbatim 
 *     don't want the following to be rendered as &lt: > or \> !
 * @endverbatim
 * 
 * @rstref2{my-reference-label, not the title here}
 * 
 * This function skips all \<li\> elements. This function skips all \verb{li} elements. This function skips all @verb{li} elements.
 * 
 */
void simple(void) {}

Breathe's help shows how to create a Doxygen alias:

breathe_doxygen_aliases = {
    'rstref{1}': r'\verbatim embed:rst:inline :ref:`\1` \endverbatim'
}

The example above creates a ReTxT cross-reference in the form:

It refers to the section itself, see :ref:`my-reference-label`.

I want to have a reference in the form:

It refers to the section itself, see :ref:`not the title here<my-reference-label>`.

So that not the title here is the link text.

I've tried to configure Breathe like so:

breathe_doxygen_aliases = {
    'rstref{1}': r'\verbatim embed:rst:inline :ref:`\1` \endverbatim',
    'rstref2{2}': r'\verbatim embed:rst:inline :ref:`\2<\1>` \endverbatim',
    'verb{1}' : r'\<\1\>'
}

Which yields the (apparently correct) following Doxygen config:

ALIASES += rstref{1}="\verbatim embed:rst:inline :ref:`\1` \endverbatim"
ALIASES += rstref2{2}="\verbatim embed:rst:inline :ref:`\2<\1>` \endverbatim"
ALIASES += verb{1}="\<\1\>"

But in the XML output the < and > are being replaced by &lt and &gt:

    <detaileddescription>
<para><verbatim>*     don&apos;t want the following to be rendered as &amp;lt: &gt; or \&gt; !
* </verbatim></para>
<para><verbatim>embed:rst:inline :ref:` not the title here&lt;my-reference-label&gt;` </verbatim></para>
<para>This function skips all &lt;li&gt; elements. This function skips all &lt;li&gt; elements. This function skips all &lt;li&gt; elements. </para>
    </detaileddescription>

Which breaks the subsequent ReTxT processing and I don't get a link. The rstref{1} alias works perfectly though:

<verbatim>embed:rst:inline :ref:`custom0_pe_convert` </verbatim>

I've tried escaping the <> symbols in the alias definition:

'rstref2{2}': r'\verbatim embed:rst:inline :ref:`\2\<\1\>` \endverbatim'

Which gives me:

ALIASES += rstref2{2}="\verbatim embed:rst:inline :ref:`\2\<\1\>` \endverbatim"

But the XML is still wrong:

<verbatim>embed:rst:inline :ref:` not the title here\&lt;my-reference-label\&gt;` </verbatim>

Update

I've tried using CDATA from the Doxygen example and this answer:

/// <summary>
/// A search engine.
/// </summary>
class Engine
{
  /// <summary>
  /// The Search method takes a series of parameters to specify the search criterion
  /// and returns a dataset containing the result set.
  // <![CDATA[ test > 17; ]]>
  /// </summary>
  /// <param name="connectionString">the connection string to connect to the
  /// database holding the content to search</param>
  /// <param name="maxRows">The maximum number of rows to
  /// return in the result set</param>
  /// <param name="searchString">The text that we are searching for</param>
  /// <returns>A DataSet instance containing the matching rows. It contains a maximum
  /// number of rows specified by the maxRows parameter</returns>
  public DataSet Search(string connectionString, int maxRows, int searchString)
  {
    DataSet ds = new DataSet();
    return ds;
  }
}

Unfortunately the Doxygen docs don't show an example on how to use CDATA

And I still get escaped XML:

<codeline lineno="34"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&lt;![CDATA[<sp/>test<sp/>&gt;<sp/>17;<sp/>]]&gt;</highlight></codeline>

Any help us much appreciatted.

Cheers!

Leonardo
  • 1,533
  • 17
  • 28
  • The first question you have "In the ``, my original `>` got replaced by `&gt`. I do not want that. How can I configure Doxygen so that replacement doesn't happen?" This is logical, simply said, as in XML some characters (provided they are not in a `CDATA` section) cannot be used directly in text parts (among these are `<>&`) and they have to be "escaped" (in this case like `<`, `>`, `&` ). so the resulting doxygen XML code is correct. This should be read correctly by each program that reads XML. – albert Mar 25 '23 at 09:26
  • The remark about the `\verbatim` means that the input is not interpreted by doxygen but his has no influence on the output that is generated, the output has to obey the rules of that output language. – albert Mar 25 '23 at 09:27
  • I've tried using CDATA and I can't get that to work, I've updated my question accordingly. Could you link some resource that explains how CDATA can be used to Doxygen doesn't escapes those symbols? Thanks/ – Leonardo Mar 27 '23 at 16:06
  • The `CDATA` as you mention is in the input, doxygen translates this to local strings for usage in the documentation (that don't know anything anymore of `cdata` or `xml` ).The place where you see `>` etc is the xml output and here you see the `>` instead of the `>` as this is requiered as doxygen does not use the `CDATA` tag here. – albert Mar 27 '23 at 17:34
  • I'm trying to follow the [example here](https://stackoverflow.com/a/2784294/6271889) as well. From that answer, `CDATA` is allowed inside any XML element that's valid under the schema. In the context of Doxygen, I'm assuming this means any [XML command](https://www.doxygen.nl/manual/xmlcmds.html). In a nutshell, if I do `<![CDATA[ > ]]>`, that's valid XML, no? I'd expect that Doxygen generated ` <![CDATA[>]]> ` and not ` > ` – Leonardo Mar 27 '23 at 19:41
  • The <![CDATA[ > ]]>` is valid XML. In the doxygen manual about the `CDATA` it is written`: "`The text inside this tag (on the ...) is handled as normal doxygen comment except for the XML special characters `<`, `>` and `&` that are used as if they were escaped.". In doxygen terms for `<![CDATA[ > ]]>` sees doxygen sees `\brief >` and in the XML output this is shown as ` > ` which is also correct XML and an XML interpreter should read the `>` as `>`. – albert Mar 28 '23 at 08:03

0 Answers0