Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2025-04-15 12:36:50

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,875
Website GitHub

Re: remove trailing slashes

phiw13 wrote #339536:

PS – If memory serves there used to be a plugin to remove the slashes and generate valid HTML4 markup. That was along time ago in the early life of Textpattern. Lights a candle anyone?

Well, if I’ve identified all instances, it’ll only affect the tags I mentioned above. One could try adding trim="#<br\s?\/>#" replace="<br>" (or something along those lines) to those tags, or wrap them in txp:evaluate with those attributes.


TXP Builders – finely-crafted code, design and txp

Offline

#14 2025-04-15 12:59:16

etc
Developer
Registered: 2010-11-11
Posts: 5,366
Website GitHub

Re: remove trailing slashes

Unfortunately, this also affects any tag generated (by core or plugin) via tag() and tag_void() functions. And how browsers will react to a void <customtag>, dunno. On the other hand, <customtag /> allows no ambiguity.

The closing slash is optional, but not invalid in html5, whatever ‘validators’ claim.

Offline

#15 2025-04-15 13:03:29

etc
Developer
Registered: 2010-11-11
Posts: 5,366
Website GitHub

Re: remove trailing slashes

jakob wrote #339530:

For 1, might the parsers catch up at some point?

I’m waiting for this more than 10 years already, but libxml2 used in php does not seem to support html5, even in ‘html’ mode. I might be wrong, though, haven’t checked it recently.

Offline

#16 2025-04-16 14:54:14

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,875
Website GitHub

Re: remove trailing slashes

etc wrote #339539:

I’m waiting for this more than 10 years already, but libxml2 used in php does not seem to support html5, even in ‘html’ mode. I might be wrong, though, haven’t checked it recently.

Just throwing this out: might the new HTML5 compliant parser in PHP 8.4 offer a way forward? https://stitcher.io/blog/html-5-in-php-84. I’m not knowledgeable enough to say whether this fits the bill. It’s PHP 8.4+ only, but that is now commonly available on many hosts.


TXP Builders – finely-crafted code, design and txp

Offline

#17 2025-04-17 21:09:43

etc
Developer
Registered: 2010-11-11
Posts: 5,366
Website GitHub

Re: remove trailing slashes

Thank you for the link, there is some hope then. But anyway, unconditionally (in html5 mode) removing slashes in tag() and tag_void() functions is potentially problematic. For example, tag_void('txp:site_name') would produce the invalid <txp:site_name> (I know it’s an edge case). We should check first whether $tag matches one of the ‘official’ html5 void tags.

Offline

#18 2025-04-18 00:38:59

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,368
Website

Re: remove trailing slashes

etc wrote #339538:

Unfortunately, this also affects any tag generated (by core or plugin) via tag() and tag_void() functions.

Can a distinction be made between HTML elements and TXP elements(<txp:xxx />? As far as I understand, the latter have a set of grammar rules set by Textpattern. (Perhaps a naive question annex suggestion)

And how browsers will react to a void <customtag>, dunno. On the other hand, <customtag /> allows no ambiguity.

There is no ambiguity, <custom_element /> is invalid per HTML 5. You would get an error:

Self-closing syntax (/>) used on a non-void HTML element. Ignoring the slash and treating as a start tag.

The browsers will ignore the trailing slash (as they do on void elements) and attempt to “heal” the construct by closing the tag at the first opportunity. Same would happen if you accidentally forgot to insert a closing </custom_element> in your HTML. Tested with an edited basic example for custom elements from MDN, edited test here: “https://dev.l-c-n.com/web_compo1/test3.html”.

The closing slash is optional, but not invalid in html5, whatever ‘validators’ claim.

The validator does not claim “invalid”. Here is the (current) warning message:

Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.

This validator wiki entry gives you an amusing (but kind sad in my eyes) read.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#19 2025-04-18 03:54:46

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,163
Website GitHub Mastodon Twitter

Re: remove trailing slashes

etc wrote #339551:

Thank you for the link, there is some hope then. But anyway, unconditionally (in html5 mode) removing slashes in tag() and tag_void() functions is potentially problematic. For example, tag_void('txp:site_name') would produce the invalid <txp:site_name> (I know it’s an edge case). We should check first whether $tag matches one of the ‘official’ html5 void tags.

By no means do I think that the trailing slashes from txp:tags should be removed. Admittedly, I like trailing slashes as they make the code clearer. The initial request referred purely to the html5 output and not to the tags.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#20 2025-04-18 07:23:15

etc
Developer
Registered: 2010-11-11
Posts: 5,366
Website GitHub

Re: remove trailing slashes

You mostly seem to speak of html5 void elements, on which I can agree (modulo php html5 parser unavailability). The problem is, tag_void() is a generic txp function (concerned here) that can be used by core or plugins to generate all kind of tags, e.g. MathML or SVG. But these include self-closed tags like <circle cx="50" cy="50" r="50" />. If generated via tag_void() in html5 mode, it will lose its slash and probably become invalid.

Offline

#21 2025-04-18 08:58:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,875
Website GitHub

Re: remove trailing slashes

etc wrote #339551:

We should check first whether $tag matches one of the ‘official’ html5 void tags.

That sounds like a possible way forward. MDN list these void tags (and mention the XML, XHTML, SVG cases you cite).

I checked all the instances the doctype check in the core code and all the other cases of non-trailing slashes are explicitly html(5) tags. tag_void is used in numerous places in the core, and – currently – only for link, img and input tags, but plugins may use it differently and it could serve other non-html tag purposes.

So the two cases to address (as far as HTML5 compliance is concerned) would be:

  • tag_void. Proposal: add a constant (in /lib/constants.php?) with an array of the permitted HTML5 tags and check in tag_void whether $tag is in that list.
  • the br constant. What do we do here?

That doesn’t resolve the parser conflict problem, but would mean txp 4.9 produces html5-compliant output.


TXP Builders – finely-crafted code, design and txp

Offline

#22 Yesterday 15:17:10

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,875
Website GitHub

Re: remove trailing slashes

I’ve made two PRs for these aspects:

  • PR #1989 – tag_void should act only on named HTML5 void tags
  • PR #1990 – Pragmatic solution for the remaining inconsistent handling of HTML5-compliant br break tags in public-side tags. The br constant is unchanged, only the public-side output has been changed.

The conflict/problem with (current) xhtml parsers not handling slashless void tags remains nevertheless, but these PRs would make the current public-side output in HTML5 mode consistent.


TXP Builders – finely-crafted code, design and txp

Offline

#23 Yesterday 17:39:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,721
Website GitHub

Re: remove trailing slashes

jakob wrote #339568:

I’ve made two PRs for these aspects

That’s brilliant thank you. Merged. Please everyone test if you can.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB