Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-11-21 17:38:23

stg
New Member
Registered: 2012-11-21
Posts: 3

Improve doTags behaviour

Hi,

I’m using one template for all pages, this includes the error_page, and I noticed a broken behaviour of the <txp:breadcrumb> tag if I try to access a non-existing section. However, it’s not the breadcrumb function itself, as far as I can tell it’s doTag (taghandlers.php) that may (or IMHO rather should) be improved. doTag should in general not return self-closing empty tags (e.g. <a href="something" />, which is what happens with non-existing sections and the breadcrumbs). Only a few tags may be empty in XHTML, and as far as I know the same applies to HTML5. It should be reasonable to handle these tags appropriately in doTag and return for example <a...></a> if the content is empty.

Edit:

Something like below. Note that I haven’t checked if these are really all valid empty tags in the list, I did only a quick search. Also, if $tag is guaranteed to not contain spaces and/or to be lowercase, strtolower and/or trim should be removed. The patch doesn’t seem to break anything on my test system.

--- taghandlers.orig	2012-08-10 08:00:49.000000000 +0200
+++ taghandlers.php	2012-11-21 21:30:06.000000000 +0100
@@ -3405,7 +3405,14 @@
 			return $content;
 		}

-		return ($content) ? tag($content, $tag, $atts) : "<$tag $atts />";
+		if ($content)
+		{
+			return tag($content, $tag, $atts);
+		}
+
+		$empty = array('area', 'base', 'br', 'col', 'hr', 'img', 'input', 'link', 'meta', 'param');
+
+		return (in_array(strtolower(trim ($tag)), $empty)) ? "<$tag $atts />" : "<$tag $atts></$tag>";
 	}

// -------------------------------------------------------------

(Is there really no way to put that in one code block?)

Edited to improve code formatting —wet

Last edited by wet (2012-11-22 09:10:14)

Offline

#2 2012-11-22 09:10:19

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Improve doTags behaviour

It is: Use bc..

Offline

#3 2012-11-22 09:44:58

stg
New Member
Registered: 2012-11-21
Posts: 3

Re: Improve doTags behaviour

Ok, it’s actually mentioned at the bottom of http://textile.thresholdstate.com/, must have missed that. Thanks.

Offline

#4 2012-11-22 13:58:38

stg
New Member
Registered: 2012-11-21
Posts: 3

Re: Improve doTags behaviour

The full list of empty elements in XHTML 1.0:

br param hr input col img area meta link base

Additionally, in XHTML 1.1:

frame

And marked deprecated in XHTML:

basefont isindex

Empty elements in the (current) W3C HTML5 spec are all listed above for XHTML 1.0 (not 1.1, not deprecated) plus:

wbr embed source track keygen command

Offline

Board footer

Powered by FluxBB