10000 issue #11245 Add class attribute to the `@qualifier` command in the HTML output by albert-github · Pull Request #11250 · doxygen/doxygen · GitHub
[go: up one dir, main page]

Skip to content

issue #11245 Add class attribute to the @qualifier command in the HTML output #11250

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

albert-github
Copy link
Collaborator

Adding the possibility to have (HTML) class attribute values as options with the @qualifier command.

…n the HTML output

Adding the possibility to have (HTML) class attribute values as options with the `@qualifier` command.
…n the HTML output

Removing pedantic warning
@doxygen
Copy link
Owner
doxygen commented Dec 5, 2024

@albert-github I think there is a more local change possible, that doesn't require the user to specify any extra options, and also provides the possibility to style existing labels.

My idea is to derive the class from the label automatically, like so:

void HtmlGenerator::writeLabel(const QCString &label,bool /*isLast*/)
{
  DBG_HTML(m_t << "<!-- writeLabel(" << label << ") -->\n";)

  auto convertLabelToClass = [](const std::string &lab) -> QCString {
    QCString input = convertUTF8ToLower(lab);
    QCString result;
    size_t l=input.length()+1;
    result.reserve(l);
    result+=' ';
    for (size_t i=0; i<l; i++)
    {
      char c = input.at(i);
      if (isId(c) || c<0) result+=c;
      else if (c==' ' || c=='-') result+='-';
    }
    return result;
  };

  m_t << "<span class=\"mlabel" << convertLabelToClass(label.stripWhiteSpace().str()) << "\">" << label << "</span>";
}

This way

    /** \qualifier Thread-Safe
     *  \qualifier "Some other qualifier"
     *  More docs
     */
    inline void nvs_init() {}

will make Doxygen generate the labels like this:

<span class="mlabels">
  <span class="mlabel inline">inline</span>
  <span class="mlabel thread-safe">Thread-Safe</span>
  <span class="mlabel some-other-qualifier">Some other qualifier</span>
</span>

Let me know what you think.

Note that turning specific spans into links can be done with a bit of JavaScript.

@albert-github
Copy link
Collaborator Author

In principle it doesn't look bad, but it will mean that with each qualifier an extra part will be added to the class attribute (argument with PR 11243).
I think my solution is more flexible (maybe to flexible) as a user can style all qualifiers individually (e.g. when having a qualifier X with C++ it can be made green and with C# it can be made red) also one can use multiple classes added to do some other differentiating.

From the given example I understand that the "default" labels also get automatically a class attribute, that is good (was enlarging my proposed code change a bit).

The isId also allows the $ but as far as I can tell this character is not allowed in a HTML class name (and maybe there are more).

The remark:

Note that turning specific spans into links can be done with a bit of JavaScript.

what do you mean here I don't get it, the "class" are steered through the css are does the JS give some other / extra flexibility?

Furthermore there is the enhancement request #11247 ([Feature Request] Add support for @ref command inside @qualifier command) will this interfere with your proposal?

@doxygen
Copy link
Owner
doxygen commented Dec 6, 2024

In principle it doesn't look bad, but it will mean that with each qualifier an extra part will be added to the class attribute (argument with PR 11243).

In this case it is justified, as all qualifiers have the same span and cannot be distinguished.

I think my solution is more flexible (maybe to flexible) as a user can style all qualifiers individually (e.g. when having a qualifier X with C++ it can be made green and with C# it can be made red) also one can use multiple classes added to do some other differentiating.

I think it is indeed more flexibility, but at the cost of the user having to specify things explicitly, so a bit overly flexible in my opinion. It is always a trade-off of course.

From the given example I understand that the "default" labels also get automatically a class attribute, that is good (was enlarging my proposed code change a bit).

The isId also allows the $ but as far as I can tell this character is not allowed in a HTML class name (and maybe there are more).

Indeed. I found the spec, and can change it to

void HtmlGenerator::writeLabel(const QCString &label,bool /*isLast*/)
{
  DBG_HTML(m_t << "<!-- writeLabel(" << label << ") -->\n";)

  auto convertLabelToClass = [](const std::string &lab) {
    QCString input = convertUTF8ToLower(lab);
    QCString result;
    size_t l=input.length();
    result.reserve(l);

    // Create valid class selector, see 10.2 here https://www.w3.org/TR/selectors-3/#w3cselgrammar
    // ident     [-]?{nmstart}{nmchar}*
    // nmstart   [_a-z]|{nonascii}
    // nonascii  [^\0-\177]
    // nmchar    [_a-z0-9-]|{nonascii}

    bool nmstart=false;
    for (size_t i=0; i<l; i++)
    {
      char c = input.at(i);
      if (c<0 || (c>='a' && c<='z') || c=='_') // nmstart pattern
      {
        nmstart=true;
        result+=c;
      }
      else if (nmstart && (c<0 || (c>='a' && c<='z') || (c>='0' && c<='9') || c=='_')) // nmchar pattern
      {
        result+=c;
      }
      else if (nmstart && (c==' ' || c=='-')) // show whitespace as -
      {
        result+='-';
      }
    }
    return result;
  };

  m_t << "<span class=\"mlabel " << convertLabelToClass(label.stripWhiteSpace().str()) << "\">" << label << "</span>";
}

The remark:

Note that turning specific spans into links can be done with a bit of JavaScript.

what do you mean here I don't get it, the "class" are steered through the css are does the JS give some other / extra flexibility?

Furthermore there is the enhancement request #11247 ([Feature Request] Add support for @ref command inside @qualifier command) will this interfere with your proposal?

I was indeed referring to the enhancement request. You can do this also by embedding a piece of JavaScript in the header, e.g.

$(document).ready(function() {
    $('span.thread-safe').each(function() {
        var spanContent = $(this).text();
        $(this).replaceWith('<span class="mlabel thread-safe"><a href="https://en.wikipedia.org/wiki/Thread_safety">' + spanContent + '</a></span>');
    });
});

@albert-github
Copy link
Collaborator Author
  • Definition of the class identifier.
    The lexical grammar in https://www.w3.org/TR/selectors-3/#w3cselgrammar specifies that it is case insensitive anf this is respected by the call to QCString input = convertUTF8ToLower(lab);. A bit strange is that the example in https://www.w3schools.com/html/tryit.asp?filename=tryhtml_classes_capitals is case sensitive (I fiddled a bit with the class names) but I think this is might be a bug here. (I'll try to post in the forum there but awaiting approval)
  • C++ / C# different layout of e.g. "inline" label
    Would there any possibility to distinguish these?
  • \ref support
    The given JavaScript code will work for a fixed address, but I don't see show this will work when the \ref points to an internal doxygen page. Think here about e.g. the difference whether CREATE_SUBDIRS is set or not, SHORT_NAMES or slightly reorganizing the code or did I oversee some possible flexibility in the JS code?

@doxygen
Copy link
Owner
doxygen commented Dec 7, 2024

Ok, interesting.

  • C++ / C# different layout of e.g. "inline" label
    Would there any possibility to distinguish these?

No, but is that really something someone wants to do? Sounds a bit farfetched to me. This particular example could also be handled in an automated way by adding a language identifier as a class specifier.

  • \ref support
    The given JavaScript code will work for a fixed address, but I don't see show this will work when the \ref points to an internal doxygen page. Think here about e.g. the difference whether CREATE_SUBDIRS is set or not, SHORT_NAMES or slightly reorganizing the code or did I oversee some possible flexibility in the JS code?

Good point. This would indeed require it be processed by Doxygen. But if \ref can be supported, why not other things like markup commands, images, formulas, or something crazy like a table? Then it is maybe easier/clearer to have a dedicated command like \qualifierlink item_to_link_to "text". But I'm not convinced this is worth the effort.

@albert-github
Copy link
Collaborator Author
  • Definition of the class identifier.
    login has been approved and I created: https://w3schools.invisionzone.com/topic/64106-case-insensitive-of-class-attribute-values/
  • C++ / C# different layout of e.g. "inline" label
    Might sound far fetched but I think that giving more general possibilities would give the users more possibilities. We don't know what they "invent" / would like to show which special concepts (not to confuse with C++ concepts) they use.
    For a language it might, probably, be reasonably easy to create, but I used the language as an example as this is easy to understand / visualize in one's mind.
  • \ref support
    I can imagine that in the text of the label there can be things like a small formula, this could / should be limited to the possibilities (ore even further) as possible with the section headers.
    This possibility not only applies for the \ref possibility with the \qualifier but is actually a broader request to have the text part of the \ref command be extended with layout possibilities as with section headers.
    Actually this also accounts for the \name command, the title of a \defgroup, the title of a \page.
    In the recent past I already had a look at the `\name command (Formulas in member groups ignored (Origin: bugzilla #682258), Formulas in member groups ignored (Origin: bugzilla #682258) #4854). It is not easy, but well feasible. Hopefully I can work on it in the near future and I will keep for the request [Feature Request] Add support for @ref command inside @qualifier command #11247 also in mind and hopefully this can automatically be part of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to enhance doxygen, not a bug HTML HTML / XHTML output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0