Option to preserve HTML when specifying instrument/part name

• Jun 3, 2021 - 01:08

MuseScore already supports instrument/part names with HTML formatting, but in its infinite wisdom escapes all HTML tags them when you try to specify them on the Staff Properties dialog.
Ideally there needs to be an option to leave them in, accepting that some amount of sanitisation or verification would be required to ensure the resultant msxc/xml isn't invalid when saved (any sort of basic XML syntax validation should do). The major score I've tried typesetting uses sub- and superscript in instrument names, and this is not uncommon by any means.

In principle this could apply to any text in the score, but this was the first place I needed it.


Comments

FWIW, there is I think some limited form of HTML parsing in the instrument name dialog (e.g., the "b" tag works, just tried it). Probably just a matter of adding support for the "sup" tag too.

In reply to by Marc Sabatella

Actually "sub" and "sup" should work, not sure why they don't in this case? See:

QString TextBase::tagEscape(QString s)
      {
      QStringList tags = { "sym", "b", "i", "u", "sub", "sup" };
      for (const QString &tag : tags) {
            QString openTag = "<" + tag + ">";
            QString openProxy = "!!" + tag + "!!";
            QString closeTag = "</" + tag + ">";
            QString closeProxy = "!!/" + tag + "!!";
            s.replace(openTag, openProxy);
            s.replace(closeTag, closeProxy);
            }
      s = XmlWriter::xmlString(s);
      for (const QString &tag : tags) {
            QString openTag = "<" + tag + ">";
            QString openProxy = "!!" + tag + "!!";
            QString closeTag = "</" + tag + ">";
            QString closeProxy = "!!/" + tag + "!!";
            s.replace(openProxy, openTag);
            s.replace(closeProxy, closeTag);
            }
      return s;
      }

In reply to by Jojo-Schmitz

Wow, that's a...curious way to do it - but it should mean you can use !!sub!! and !!/sub!! - and that doesn't work either.
FWIW Visual Studio is telling me that that function is never called anywhere (and a simple find-in-files seems to verify that). Yet to try debugging any of the UI stuff (dialogs etc.) so I'll see what I can dig up...
So EditStaff::apply( ) calls

      QString sn = shortName-&gt;toPlainText();
      QString ln = longName-&gt;toPlainText();
      if (!Text::validateText(sn) || !Text::validateText(ln)) {

And it's Text::validateText that does the escaping, there's no checking for sub etc.

But even after changing that it still doesn't work as expected because StaffName::StaffName escapes it again!

Text::validateText(_name); // enforce HTML encoding

In reply to by Dylan Nicholson1

Ok I've worked out how to fix, but my thinking it might be better to have a flag to pass to Text::validateText to indicate whether limited HTML tags are permitted.
For now I've just changed to use Text::tagEscape (without removing the calls to validateText in EditStaff::apply(), as they obviously do something useful, but the resulting string is ignored).
Not sure if worth putting up a PR, MU4 is in a pretty weird state...

Do you still have an unanswered question? Please log in first to post your question.