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

andrewmacpherson’s picture

StatusFileSize
new1.76 KB

Here'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:


<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>

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.

andrewmacpherson’s picture

Status: Active » Needs review

Nuts. I keep forgetting to update the status when I submit a patch :-)

andrewmacpherson’s picture

Tested it out, and it validates with the W3C now. Forgot to mention that crucial bit.

Jeff Burnz’s picture

This looks good Andrew, I'll test it out today, but looks RTBC from my reading of the code, certainly solves the issue.

Jeff Burnz’s picture

Status: Needs review » Fixed

OK, 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.

andrewmacpherson’s picture

Thanks 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.

Jeff Burnz’s picture

Looks 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.

Jeff Burnz’s picture

Status: Fixed » Needs work
Jeff Burnz’s picture

OK, 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.

andrewmacpherson’s picture

Just read the latest HEAD...

$heading_level = $vars['page'] ? 'h2' : 'h3';

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.

andrewmacpherson’s picture

Status: Closed (fixed) » Fixed

This is in the new 6.x-1.6 release of adaptivetheme, so fixed.

Thanks Jeff!

Status: Needs work » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

andrewmacpherson’s picture

Status: Fixed » Needs review
StatusFileSize
new2.15 KB

Hi 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.,

<div class="node-terms">
  <ul class="taxonomy" role="navigation">
    <li class="vocab-term"> 
      <a>Automobile</a>   <!-- vehicle terms form vocab 1 -->
      ,                  <!-- this comma is valid xhtml -->
    </li>
    <li class="vocab-term">
      <a>Bicycle</a>
    </li>
    ,                            <!-- this comma is invalid xhtml -->
    <li class="vocab-term">   <!-- animal terms form vocab 2 -->
      <a>Cat</a>
      ,
    </li>
    <li class="vocab-term"> 
     <a>Dog</a>
    </li>
  </ul>
</div>

I've fixed this in a new patch (against current HEAD). Let me know what you think.

Jeff Burnz’s picture

OK, good spotting, I'll apply this patch in a day or two, cheers!

Jeff Burnz’s picture

Status: Needs review » Fixed

Committed to head.

andrewmacpherson’s picture

Status: Fixed » Active

I 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_delimiter would 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.

andrewmacpherson’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new4.14 KB
new4.18 KB

Okay, 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.

Jeff Burnz’s picture

I 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,

if ($output != '') {
  $output = '<ul class="taxonomy">'. $output .'</ul>';
}

Which is what the original method did as well.

andrewmacpherson’s picture

Ah, $output was empty when there were no terms applied to a node. Thanks Jeff!

Jeff Burnz’s picture

Status: Needs review » Fixed

comitted, fixed, thanks Andrew - great work!

andrewmacpherson’s picture

Version: 6.x-2.x-dev » 6.x-2.0-rc1
Status: Fixed » Active
StatusFileSize
new994 bytes

template.preprocess-node.inc rev 1.1.2.9 introduced a new bug :-(

The if ($output != '') check is nested at the wrong level, inside foreach ($vocabularies)...

case "vocab":
  ...
  foreach ($vocabularies as $vocabulary) {
    ... 
    if ($terms) {
      ...
    } // end: if ($terms)
    if ($output != '') {
      $output = '<ul class="taxonomy">'. $output .'</ul>';
    }
  } // end: foreach ($vocabularies as $vocabulary)
  break;

The <ul class="taxonomy"> wrapper is applied per-vocabulary, leading to invalid output like this...

<ul class="taxonomy">
  <ul class="taxonomy">
    <ul class="taxonomy">
      <li class="vocab"/>
    </ul>
    <li class="vocab"/>
  </ul>
  <li class="vocab"/>
</ul>

So the if ($output != '') needs to move outside foreach ($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...

Jeff Burnz’s picture

Great 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!

Jeff Burnz’s picture

Status: Active » Fixed

Marking as fixed, I think we done enough on this one ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.