Html//1 from html_write: quoting of html tag attributes

Dear developers,

I noted that html//1 always wants to quote the tag attributes:

Example (with & replaced by $):

html(math(mfenced(separators(‘$nbsp;’), [mtext(a), mtext(b)])), M, ), print_html(M).

Result is (with spaces inserted into the tags to make them visible, and & replaced by $)

< math>
< mfenced separators=“$amp;nbsp;”>
< mtext>a< /mtext>
< mtext>b< /mtext>
< /mfenced>
< /math>

This is because the html attributes always undergo quoting in html//1. I would like to
suppress it using the backslash (as in the content of html tags), but this does not work for the attributes,

html(math(mfenced(separators(\‘$nbsp;’), [mtext(a), mtext(a)])))

raises an error that an atom is expected. I could fix the problem by inserting the following line into library/http/html_write.pl (around line 830)

html_quoted_attribute(\Text) → !, [ Text ]. % inserted

html_quoted_attribute(Text) →
{ xml_quote_attribute(Text, Quoted, utf8) },
[ Quoted ].

I don’t think this breaks existing code, or will it? You might wish to integrate this into the code. Thank you for your consideration.

Best wishes,

Matthias

The intend is to use &(nbsp) and have html//1 emit the right term. Why doesn’t that work?

Dear Jan,

I was referring to the tag attributes, not to its “content”. Indeed, as you write, quoting can be suppressed for the content, so this works:

html(math(mfenced(separators(‘’), [mtext(a), \[‘&nbsp;’], mtext(b)])), M, ), print_html(M).

and I think your suggestion refers to this:

html(math(mfenced(separators(‘’), [mtext(a), ‘&(nbsp)’, mtext(b)])), M, ), print_html(M).

I was actually referring to the “separator” (i.e., the tag attribute). But this one does not work, because the ampersand is quoted:

html(math(mfenced(separators(‘&nbsp;’), [mtext(a), mtext(b)])), M, ), print_html(M).
html(math(mfenced(separators(‘&(nbsp)’), [mtext(a), mtext(b)])), M, ), print_html(M).

Both result in html output like

<math><mfenced separators=“&amp;nbsp;”><mtext>a</mtext><mtext>b</mtext></mfenced></math>

And in the attribute it seems not possible to suppress the quote, so this does not work:

html(math(mfenced(separators(\[‘&nbsp;’]), [mtext(a), mtext(b)])), M, ), print_html(M). error message html(math(mfenced(separators(\\'\&nbsp;'), [mtext(a), mtext(b)])), M, []), print_html(M). error message

I see that my use case is somewhat special. But I was wondering if quoting of tag attributes is a desirable feature at all.

Thank you for your consideration.

Best wishes,

Matthias