Pre-processing of the $terms variable produces invalid XHTML, as illustrated in the following output sample:
<div class="node-terms">
<ul class="taxonomy" role="navigation">
<li class="vocab-term">
<a title="Posts about Costumes" rel="tag" href="/category/costumes">Costumes</a>
</li>
,
<li class="vocab-term"> ... </li>
</ul>
</div>
The culprits turn out to be the commas which separate the terms, for which the W3C validator reports an error as:
"character data is not allowed here"
i.e. there should only be whitespace between the end of one <li> element and the next.
Comments
Comment #1
andrewmacpherson commentedHere's my patch for this. Please take a look and tell me what you think.
I've re-jigged things so that commas are produced inside the
<li>elements rather than between them, like this:I'm not sure how good my approach is - I tried looking for other themes which delimit terms with commas, but couldn't find any code to steal :-(
Hope you like it.
Comment #2
andrewmacpherson commentedNuts. I keep forgetting to update the status when I submit a patch :-)
Comment #3
andrewmacpherson commentedTested it out, and it validates with the W3C now. Forgot to mention that crucial bit.
Comment #4
Jeff Burnz commentedThis looks good Andrew, I'll test it out today, but looks RTBC from my reading of the code, certainly solves the issue.
Comment #5
Jeff Burnz commentedOK, was good, I committed to head with a few minor additions:
1) added h2 to the vocab headers when the vocabs are displayed separately (they were span tags but they really should be headings).
2) added a new theme settings so you can change the delimiter.
Thanks for the patch, and you made me focus on this neglected area as well, great stuff.
Comment #6
andrewmacpherson commentedThanks Jeff! I'll check out the new HEAD soon.
About those additions you mention...
1) May I suggest using h3 for the vocab headers, or even h4? My reason is that node.tlp.php uses h2 for the node title when the node isn't a standalone page. If taxonomy terms are set to always display, then the vocab headers will be on the same level as the node title, which would be confusing in the typical river-of-news front-page scenario. It probably wouldn't be good for accessibility either. The vocab-headers should be at a level beneath the node title, since the vocabulary terms are a property of the node.
2) A delimiter setting is something I was going to suggest doing (you read my mind there), but I'm still getting my head around theme settings api, so I thought it best to fix the markup straight away.
Comment #7
Jeff Burnz commentedLooks like we'll have to do some hacky contextual checking for the header level, in teaser view it needs to be h3, but really in full node view it should probably be h2, so the nesting is correct - we just went through this whole concept for D7 for theme_links, I'll think about, if I cant get a decent resolution lets move back down to h3, that seems like the best compromise for now.
Comment #8
Jeff Burnz commentedComment #9
Jeff Burnz commentedOK, that turned out to be pretty simple, not sure what i was worrying about (long day man...), committed to head, h3 for teaser view, h2 for full node view.
Added .node-terms .vocab-name {font-size: 1em;} to starter.css for some basic styling also.
Comment #10
andrewmacpherson commentedJust read the latest HEAD...
Looks good. I'm really starting to like the ternary operator after today. (Used to avoid it, thought it was hard to read...)
This issue is turning out well. The h2/h3 scenario is a good example of what the XHTML2 effort was trying to support with the
<h>element.Comment #11
andrewmacpherson commentedThis is in the new 6.x-1.6 release of adaptivetheme, so fixed.
Thanks Jeff!
Comment #13
andrewmacpherson commentedHi Jeff,
I'd like to re-open this issue, 'cos I've realized the problem is only half-fixed.
Case
$taxonomy_format == 'vocab'works fine; however when$taxonomy_format == 'list'there is still a problem. The delimiter is properly nested inside the <li> when it is within a taxonomy, but lies outside the <li> when it is between two vocabularies - invalid XHTML.i.e.,
I've fixed this in a new patch (against current HEAD). Let me know what you think.
Comment #14
Jeff Burnz commentedOK, good spotting, I'll apply this patch in a day or two, cheers!
Comment #15
Jeff Burnz commentedCommitted to head.
Comment #16
andrewmacpherson commentedI inadvertently introduced a new bug with my last patch; the logic for deciding when to show the delimiter is flawed.
It leads to a hanging delimiter being displayed after the last term, when there are no terms assigned from the final vocabulary in the
foreach ($vocabularies as $vocabulary)loop.$use_delimiterwould only be false when the final vocabulary was set to display and had terms assigned to the node.Sorry for messing this up! I'll have a go at fixing it asap.
Comment #17
andrewmacpherson commentedOkay, looks like I've fixed it, fingers crossed.
I tried a few different ways to get it to work, but the code was starting to get really messy. In the end I refactored it into two separate routines for handling one-list and per-vocab display settings. There's a little bit of repeated code, but it's much more readable to me, and more importantly, it works.
I'm going to keep testing this over the next few days, with lots of different taxonomy settings (core and theme) to check there isn't any more unexpected behaviour. I'll let you know how that goes.
Updated patches for 1.x and 2.x follow. I'm mainly working with 2.x now.
Comment #18
Jeff Burnz commentedI found it generating an empty
<ul class="taxonomy"></ul>, but I am not sure under what conditions or if its all the time, I need to test some.OK, this was pretty easily fixed but wrapping up the output,
Which is what the original method did as well.
Comment #19
andrewmacpherson commentedAh, $output was empty when there were no terms applied to a node. Thanks Jeff!
Comment #20
Jeff Burnz commentedcomitted, fixed, thanks Andrew - great work!
Comment #21
andrewmacpherson commentedtemplate.preprocess-node.inc rev 1.1.2.9 introduced a new bug :-(
The
if ($output != '')check is nested at the wrong level, insideforeach ($vocabularies)...The
<ul class="taxonomy">wrapper is applied per-vocabulary, leading to invalid output like this...So the
if ($output != '')needs to move outsideforeach ($vocabularies).I didn't notice this until I started playing with the margins on li.vocab, but it's quite obvious on the base theme. Patch enclosed...
Comment #22
Jeff Burnz commentedGreat spotting, you know I have looked at this a thousands time but I don't understand why my validator did not pick this up, I have tested your change and its working fine so I have committed to head.
Thanks once again Andrew, you have been an invaluable set of eyes!
Comment #23
Jeff Burnz commentedMarking as fixed, I think we done enough on this one ;)