[PATCH 2 of 3 V3 [NOW_WITH_DOCS!]] hgweb: apply the websub filter to revision descriptions

Angel Ezquerra angel.ezquerra at gmail.com
Sat Feb 9 09:55:01 CST 2013


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1360424901 -3600
# Node ID 3d1290c7131e8e1df991f1753ab5e76d3e3cd21e
# Parent  04299b2afc200171eeca472c5d5644e84048a3b5
hgweb: apply the websub filter to revision descriptions

In order to use this, add a [websub] section to your configuration and add
websub expressions such as:

italic = s/\b_(\S+)_\b/<i>\1<\/i>/
bold = s/\*\b(\S+)\b\*/<b>\1<\/b>/
issues = s|issue(\d+)|<a href="http://bts.example.org/issue\1">issue\1</a>|i
bugzilla = s!((?:bug|b=|(?=#?\d{4,}))(?:\s*#?)(\d+))!<a href="http://bz.selenic.com/\2">\1</a>!i

This also adds documentation (proofed by Kevin!) to the config help section.

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1463,3 +1463,36 @@
 
 ``templates``
     Where to find the HTML templates. Default is install path.
+
+``websub``
+-------
+
+Web substitution filter definition. You can use this section to
+define a set of regular expression substitution patterns which
+let you automatically modify the hgweb server output.
+
+The default hgweb templates only apply these substitution patterns
+on the revision description fields. You can apply them anywhere
+you want when you create your own templates by adding calls to the
+"websub" filter (usually after calling the "escape" filter).
+
+This can be used, for example, to convert issue references to links
+to your issue tracker, or to convert "markdown-like" syntax into
+HTML (see the examples below).
+
+Each entry in this section names a substitution filter.
+The value of each entry defines the substitution expression itself.
+The websub expressions follow the old interhg extension syntax,
+which in turn imitates the Unix sed replacement syntax::
+
+    pattername = s/SEARCH_REGEX/REPLACE_EXPRESSION/[i]
+
+You can use any separator other than "/". The final "i" is optional
+and indicates that the search must be case insensitive.
+
+Examples::
+
+    [websub]
+    issues = s|issue(\d+)|<a href="http://bts.example.org/issue\1">issue\1</a>|i
+    italic = s/\b_(\S+)_\b/<i>\1<\/i>/
+    bold = s/\*\b(\S+)\b\*/<b>\1<\/b>/
diff --git a/mercurial/templates/gitweb/changelogentry.tmpl b/mercurial/templates/gitweb/changelogentry.tmpl
--- a/mercurial/templates/gitweb/changelogentry.tmpl
+++ b/mercurial/templates/gitweb/changelogentry.tmpl
@@ -8,7 +8,7 @@
 <i>{author|obfuscate} [{date|rfc822date}] rev {rev}</i><br/>
 </div>
 <div class="log_body">
-{desc|strip|escape|addbreaks|nonempty}
+{desc|strip|escape|websub|addbreaks|nonempty}
 <br/>
 <br/>
 </div>
diff --git a/mercurial/templates/gitweb/changeset.tmpl b/mercurial/templates/gitweb/changeset.tmpl
--- a/mercurial/templates/gitweb/changeset.tmpl
+++ b/mercurial/templates/gitweb/changeset.tmpl
@@ -41,7 +41,7 @@
 </table></div>
 
 <div class="page_body">
-{desc|strip|escape|addbreaks|nonempty}
+{desc|strip|escape|websub|addbreaks|nonempty}
 </div>
 <div class="list_head"></div>
 <div class="title_text">
diff --git a/mercurial/templates/gitweb/fileannotate.tmpl b/mercurial/templates/gitweb/fileannotate.tmpl
--- a/mercurial/templates/gitweb/fileannotate.tmpl
+++ b/mercurial/templates/gitweb/fileannotate.tmpl
@@ -56,7 +56,7 @@
 </div>
 
 <div class="page_path">
-{desc|strip|escape|addbreaks|nonempty}
+{desc|strip|escape|websub|addbreaks|nonempty}
 </div>
 <div class="page_body">
 <table>
diff --git a/mercurial/templates/gitweb/filerevision.tmpl b/mercurial/templates/gitweb/filerevision.tmpl
--- a/mercurial/templates/gitweb/filerevision.tmpl
+++ b/mercurial/templates/gitweb/filerevision.tmpl
@@ -56,7 +56,7 @@
 </div>
 
 <div class="page_path">
-{desc|strip|escape|addbreaks|nonempty}
+{desc|strip|escape|websub|addbreaks|nonempty}
 </div>
 
 <div class="page_body">
diff --git a/mercurial/templates/monoblue/changelogentry.tmpl b/mercurial/templates/monoblue/changelogentry.tmpl
--- a/mercurial/templates/monoblue/changelogentry.tmpl
+++ b/mercurial/templates/monoblue/changelogentry.tmpl
@@ -2,5 +2,5 @@
 <ul class="changelog-entry">
     <li class="age">{date|rfc822date}</li>
     <li>by <span class="name">{author|obfuscate}</span> <span class="revdate">[{date|rfc822date}] rev {rev}</span></li>
-    <li class="description">{desc|strip|escape|addbreaks|nonempty}</li>
+    <li class="description">{desc|strip|escape|websub|addbreaks|nonempty}</li>
 </ul>
diff --git a/mercurial/templates/monoblue/changeset.tmpl b/mercurial/templates/monoblue/changeset.tmpl
--- a/mercurial/templates/monoblue/changeset.tmpl
+++ b/mercurial/templates/monoblue/changeset.tmpl
@@ -52,7 +52,7 @@
         {child%changesetchild}
     </dl>
 
-    <p class="description">{desc|strip|escape|addbreaks|nonempty}</p>
+    <p class="description">{desc|strip|escape|websub|addbreaks|nonempty}</p>
 
     <table>
     {files}
diff --git a/mercurial/templates/monoblue/fileannotate.tmpl b/mercurial/templates/monoblue/fileannotate.tmpl
--- a/mercurial/templates/monoblue/fileannotate.tmpl
+++ b/mercurial/templates/monoblue/fileannotate.tmpl
@@ -57,7 +57,7 @@
         <dd>{permissions|permissions}</dd>
     </dl>
 
-    <p class="description">{desc|strip|escape|addbreaks|nonempty}</p>
+    <p class="description">{desc|strip|escape|websub|addbreaks|nonempty}</p>
 
     <table class="annotated">
     {annotate%annotateline}
diff --git a/mercurial/templates/monoblue/filerevision.tmpl b/mercurial/templates/monoblue/filerevision.tmpl
--- a/mercurial/templates/monoblue/filerevision.tmpl
+++ b/mercurial/templates/monoblue/filerevision.tmpl
@@ -57,7 +57,7 @@
         <dd>{permissions|permissions}</dd>
     </dl>
 
-    <p class="description">{desc|strip|escape|addbreaks|nonempty}</p>
+    <p class="description">{desc|strip|escape|websub|addbreaks|nonempty}</p>
 
     <div class="source">
     {text%fileline}
diff --git a/mercurial/templates/paper/changeset.tmpl b/mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl
+++ b/mercurial/templates/paper/changeset.tmpl
@@ -40,7 +40,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="description">{desc|strip|escape|nonempty}</div>
+<div class="description">{desc|strip|escape|websub|nonempty}</div>
 
 <table id="changesetEntry">
 <tr>
diff --git a/mercurial/templates/paper/fileannotate.tmpl b/mercurial/templates/paper/fileannotate.tmpl
--- a/mercurial/templates/paper/fileannotate.tmpl
+++ b/mercurial/templates/paper/fileannotate.tmpl
@@ -46,7 +46,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="description">{desc|strip|escape|nonempty}</div>
+<div class="description">{desc|strip|escape|websub|nonempty}</div>
 
 <table id="changesetEntry">
 <tr>
diff --git a/mercurial/templates/paper/filecomparison.tmpl b/mercurial/templates/paper/filecomparison.tmpl
--- a/mercurial/templates/paper/filecomparison.tmpl
+++ b/mercurial/templates/paper/filecomparison.tmpl
@@ -45,7 +45,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="description">{desc|strip|escape|nonempty}</div>
+<div class="description">{desc|strip|escape|websub|nonempty}</div>
 
 <table id="changesetEntry">
 <tr>
diff --git a/mercurial/templates/paper/filediff.tmpl b/mercurial/templates/paper/filediff.tmpl
--- a/mercurial/templates/paper/filediff.tmpl
+++ b/mercurial/templates/paper/filediff.tmpl
@@ -45,7 +45,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="description">{desc|strip|escape|nonempty}</div>
+<div class="description">{desc|strip|escape|websub|nonempty}</div>
 
 <table id="changesetEntry">
 <tr>
diff --git a/mercurial/templates/paper/filerevision.tmpl b/mercurial/templates/paper/filerevision.tmpl
--- a/mercurial/templates/paper/filerevision.tmpl
+++ b/mercurial/templates/paper/filerevision.tmpl
@@ -44,7 +44,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="description">{desc|strip|escape|nonempty}</div>
+<div class="description">{desc|strip|escape|websub|nonempty}</div>
 
 <table id="changesetEntry">
 <tr>
diff --git a/mercurial/templates/spartan/changeset.tmpl b/mercurial/templates/spartan/changeset.tmpl
--- a/mercurial/templates/spartan/changeset.tmpl
+++ b/mercurial/templates/spartan/changeset.tmpl
@@ -39,7 +39,7 @@
 </tr>
 <tr>
  <th class="description">description:</th>
- <td class="description">{desc|strip|escape|addbreaks|nonempty}</td>
+ <td class="description">{desc|strip|escape|websub|addbreaks|nonempty}</td>
 </tr>
 </table>
 
diff --git a/mercurial/templates/spartan/fileannotate.tmpl b/mercurial/templates/spartan/fileannotate.tmpl
--- a/mercurial/templates/spartan/fileannotate.tmpl
+++ b/mercurial/templates/spartan/fileannotate.tmpl
@@ -38,7 +38,7 @@
 </tr>
 <tr>
   <td class="metatag">description:</td>
-  <td>{desc|strip|escape|addbreaks|nonempty}</td>
+  <td>{desc|strip|escape|websub|addbreaks|nonempty}</td>
 </tr>
 </table>
 
diff --git a/mercurial/templates/spartan/filerevision.tmpl b/mercurial/templates/spartan/filerevision.tmpl
--- a/mercurial/templates/spartan/filerevision.tmpl
+++ b/mercurial/templates/spartan/filerevision.tmpl
@@ -36,7 +36,7 @@
  <td>{permissions|permissions}</td></tr>
 <tr>
   <td class="metatag">description:</td>
-  <td>{desc|strip|escape|addbreaks|nonempty}</td>
+  <td>{desc|strip|escape|websub|addbreaks|nonempty}</td>
 </tr>
 </table>
 


More information about the Mercurial-devel mailing list