# Html//1 from html\_write: quoting of html tag attributes

**URL:** <https://swi-prolog.discourse.group/t/html-1-from-html-write-quoting-of-html-tag-attributes/1407>\
**Category:** General\
**Created:** [October 19, 2019, 9:51pm UTC](https://swi-prolog.discourse.group/t/html-1-from-html-write-quoting-of-html-tag-attributes/1407 "2019-10-19T21:51:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgondan](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgondan](https://swi-prolog.discourse.group/u/mgondan)\
**Post date:** [October 19, 2019, 9:51pm UTC](https://swi-prolog.discourse.group/t/html-1-from-html-write-quoting-of-html-tag-attributes/1407/1 "2019-10-19T21:51:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 20, 2019, 2:02am UTC](https://swi-prolog.discourse.group/t/html-1-from-html-write-quoting-of-html-tag-attributes/1407/2 "2019-10-20T02:02:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mgondan](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@mgondan](https://swi-prolog.discourse.group/u/mgondan)\
**Post date:** [October 20, 2019, 8:13am UTC](https://swi-prolog.discourse.group/t/html-1-from-html-write-quoting-of-html-tag-attributes/1407/3 "2019-10-20T08:13:40Z")

</div>

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
