From 68bb7a65787d9dba821c329b3b7037d1e0e164eb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 14 Feb 2014 08:47:17 +1600 Subject: [PATCH] [PATCH v3 2/8] nmbug-status: Slug the title when using it as an id --- c0/f42f084bd14c239de154ecdeb84c37909bc7d7 | 141 ++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 c0/f42f084bd14c239de154ecdeb84c37909bc7d7 diff --git a/c0/f42f084bd14c239de154ecdeb84c37909bc7d7 b/c0/f42f084bd14c239de154ecdeb84c37909bc7d7 new file mode 100644 index 000000000..619a27682 --- /dev/null +++ b/c0/f42f084bd14c239de154ecdeb84c37909bc7d7 @@ -0,0 +1,141 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 56615431FC3 + for ; Thu, 13 Feb 2014 08:50:51 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id IDLMxb92iHMn for ; + Thu, 13 Feb 2014 08:50:45 -0800 (PST) +Received: from qmta02.westchester.pa.mail.comcast.net + (qmta02.westchester.pa.mail.comcast.net [76.96.62.24]) + by olra.theworths.org (Postfix) with ESMTP id 553A9431FB6 + for ; Thu, 13 Feb 2014 08:50:45 -0800 (PST) +Received: from omta22.westchester.pa.mail.comcast.net ([76.96.62.73]) + by qmta02.westchester.pa.mail.comcast.net with comcast + id Rrur1n0081ap0As51sqlvu; Thu, 13 Feb 2014 16:50:45 +0000 +Received: from odin.tremily.us ([24.18.63.50]) + by omta22.westchester.pa.mail.comcast.net with comcast + id Rsok1n005152l3L3isoljD; Thu, 13 Feb 2014 16:48:45 +0000 +Received: from mjolnir.tremily.us (unknown [192.168.0.140]) + by odin.tremily.us (Postfix) with ESMTPS id 1BC1F102DA02; + Thu, 13 Feb 2014 08:48:43 -0800 (PST) +Received: (nullmailer pid 17985 invoked by uid 1000); + Thu, 13 Feb 2014 16:47:29 -0000 +From: "W. Trevor King" +To: notmuch@notmuchmail.org +Subject: [PATCH v3 2/8] nmbug-status: Slug the title when using it as an id +Date: Thu, 13 Feb 2014 08:47:17 -0800 +Message-Id: + <4755c683a14500c996683ef5cf271be3c7f4f9f3.1392309570.git.wking@tremily.us> +X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1 +In-Reply-To: +References: +In-Reply-To: +References: +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; + s=q20121106; t=1392310245; + bh=U4aJhZgQIh74J6bF214XjQxBHvdfqkJPm6GPKWzusQc=; + h=Received:Received:Received:Received:From:To:Subject:Date: + Message-Id; + b=fpTKngdzz2RzRIbH1opy9CLlM+YrWTB/8BtLvZA8UG55+Ovj1NITj2K5oCrKt5iJ0 + 25BxmIppmmonfwr048MT1/sMNFczyJL5xdO2ybCKrNo0GlFIXKQhL/uXB4llsjgrVw + dIxuNNmg68Dtd9GG3u0s1g2Y5IzbPPOeo4x1aAjPOaWxYlgm5Jjpu2tLHPsKvphFGo + IAs8s6JIEqBSGwCn7mpjB0Gc1IDbE22YQL8C+v13hNbdkQU1T6sA+cmqQE7i4xCt6b + k+L4O8ZrGdZlPNomd0h3Q8JDDHZNW/76n/kAbUZhIUqkSPIr2OmwStnE9eGaT1qXiD + dc/LHROC+aOhA== +Cc: Tomi Ollila +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 13 Feb 2014 16:50:51 -0000 + +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 +--- + devel/nmbug/nmbug-status | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status +index 40e6896..9fde20e 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('
    \n') + for view in views: ++ if 'id' not in view: ++ view['id'] = self._slug(view['title']) + stream.write( +- '
  • {title}
  • \n'.format(**view)) ++ '
  • {title}
  • \n'.format(**view)) + stream.write('
\n') + + def _write_view_header(self, view, stream): +- stream.write('

{title}

\n'.format(**view)) ++ stream.write('

{title}

\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( +-- +1.8.5.2.8.g0f6c0d1 + -- 2.26.2