diff options
author | W. Trevor King <wking@tremily.us> | 2014-02-13 08:47:17 -0800 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-02-13 21:45:40 -0400 |
commit | 711d04c8214f487e57c4bbc26b4433c5e6f099ce (patch) | |
tree | cb8ac0aa149a054793539f0483565fa27534181c /devel | |
parent | e485b5bd1de1d514a35ab92d726240d2b46f99ab (diff) |
nmbug-status: Slug the title when using it as an id
Also allow manual id overrides from the JSON config. Sluggin avoids
errors like:
Bad value '#Possible bugs' for attribute href on element a:
Whitespace in fragment component. Use %20 in place of spaces.
from http://validator.w3.org.
I tried just quoting the titles (e.g. 'Possible%20bugs'), but that
didn't work (at least with Firefox 24.2.0). Slugging avoids any
ambiguity over when the quotes are expanded in the client. The specs
are unclear about quoting, saying only [1]:
Value: Any string, with the following restrictions:
must be at least one character long
must not contain any space characters
[1]: http://dev.w3.org/html5/markup/global-attributes.html#common.attrs.id
Diffstat (limited to 'devel')
-rwxr-xr-x | devel/nmbug/nmbug-status | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status index 40e68962..9fde20ec 100755 --- a/devel/nmbug/nmbug-status +++ b/devel/nmbug/nmbug-status @@ -21,6 +21,7 @@ except ImportError: # Python 2 import json import argparse import os +import re import sys import subprocess @@ -168,16 +169,20 @@ class Page (object): class HtmlPage (Page): + _slug_regexp = re.compile('\W+') + def _write_header(self, views, stream): super(HtmlPage, self)._write_header(views=views, stream=stream) stream.write('<ul>\n') for view in views: + if 'id' not in view: + view['id'] = self._slug(view['title']) stream.write( - '<li><a href="#{title}">{title}</a></li>\n'.format(**view)) + '<li><a href="#{id}">{title}</a></li>\n'.format(**view)) stream.write('</ul>\n') def _write_view_header(self, view, stream): - stream.write('<h3 id="{title}">{title}</h3>\n'.format(**view)) + stream.write('<h3 id="{id}">{title}</h3>\n'.format(**view)) if 'comment' in view: stream.write(view['comment']) stream.write('\n') @@ -224,6 +229,9 @@ class HtmlPage (Page): ).format(**d) return (running_data, display_data) + def _slug(self, string): + return self._slug_regexp.sub('-', string) + _PAGES['text'] = Page() _PAGES['html'] = HtmlPage( |