Patchwork [RFC] hgweb: code selection without line numbers in file diff and changesets views

login
register
mail settings
Submitter Alexander Plavin
Date July 6, 2013, 11:52 a.m.
Message ID <3c184b9273fddb711944.1373111524@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1800/
State RFC, archived
Headers show

Comments

Alexander Plavin - July 6, 2013, 11:52 a.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1373107475 -14400
#      Sat Jul 06 14:44:35 2013 +0400
# Node ID 3c184b9273fddb711944dc1f48e838c143786e43
# Parent  4a38d70d86dabc7b7976a0e599471ffadb4299ed
hgweb: code selection without line numbers in file diff and changesets views

All the source lines are put in a <pre> tag, as with file source view in
previous patches.

This is a request for commets, as I'm not sure that this exact implementation
way of e.g. nested CSS counters is best and looking for your advice.
Later I'm going to split this into several commits, and now waiting for
overall comments.

Patch

diff -r 4a38d70d86da -r 3c184b9273fd mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl	Thu Jul 04 14:19:43 2013 +0400
+++ b/mercurial/templates/paper/changeset.tmpl	Sat Jul 06 14:44:35 2013 +0400
@@ -77,10 +77,11 @@ 
 </table>
 
 <div class="overflow">
-<div class="sourcefirst">   line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 reset-lineno">
 {diff}
 </div>
+</div>
 
 </div>
 </div>
diff -r 4a38d70d86da -r 3c184b9273fd mercurial/templates/paper/filediff.tmpl
--- a/mercurial/templates/paper/filediff.tmpl	Thu Jul 04 14:19:43 2013 +0400
+++ b/mercurial/templates/paper/filediff.tmpl	Sat Jul 06 14:44:35 2013 +0400
@@ -68,11 +68,12 @@ 
 </table>
 
 <div class="overflow">
-<div class="sourcefirst">   line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 reset-lineno">
 {diff}
 </div>
 </div>
 </div>
+</div>
 
 {footer}
diff -r 4a38d70d86da -r 3c184b9273fd mercurial/templates/paper/filerevision.tmpl
--- a/mercurial/templates/paper/filerevision.tmpl	Thu Jul 04 14:19:43 2013 +0400
+++ b/mercurial/templates/paper/filerevision.tmpl	Sat Jul 06 14:44:35 2013 +0400
@@ -68,7 +68,7 @@ 
 
 <div class="overflow">
 <div class="sourcefirst"> line source</div>
-<pre class="sourcelines">{text%fileline}</pre>
+<pre class="sourcelines stripes4">{text%fileline}</pre>
 <div class="sourcelast"></div>
 </div>
 </div>
diff -r 4a38d70d86da -r 3c184b9273fd mercurial/templates/paper/map
--- a/mercurial/templates/paper/map	Thu Jul 04 14:19:43 2013 +0400
+++ b/mercurial/templates/paper/map	Sat Jul 06 14:44:35 2013 +0400
@@ -84,11 +84,15 @@ 
     <td class="source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</td>
   </tr>'
 
-diffblock = '<div class="source bottomline parity{parity}"><pre>{lines}</pre></div>'
-difflineplus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="plusline">{line|escape}</span>'
-difflineminus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="minusline">{line|escape}</span>'
-difflineat = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="atline">{line|escape}</span>'
-diffline = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}'
+diffblock = '<div class="bottomline inc-lineno"><pre class="sourcelines">{lines}</pre></div>'
+difflineplus = '
+  <span id="{lineid}" class="plusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineminus = '
+  <span id="{lineid}" class="minusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineat = '
+  <span id="{lineid}" class="atline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+diffline = '
+  <span id="{lineid}">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
 
 comparisonblock ='
   <tbody class="block">
diff -r 4a38d70d86da -r 3c184b9273fd mercurial/templates/static/style-paper.css
--- a/mercurial/templates/static/style-paper.css	Thu Jul 04 14:19:43 2013 +0400
+++ b/mercurial/templates/static/style-paper.css	Sat Jul 06 14:44:35 2013 +0400
@@ -212,8 +212,12 @@ 
 .sourcelines {
   font-size: 90%;
   position: relative;
+  counter-reset: lineno;
 }
 
+.reset-lineno { counter-reset: lineno; }
+.inc-lineno { counter-increment: lineno; }
+
 .sourcelines > span {
   display: inline-block;
   width: 100%;
@@ -234,11 +238,13 @@ 
   font-size: smaller;
   color: #999;
   text-align: right;
-  content: counter(lineno);
+  content: counters(lineno, ".");
 }
 
-.sourcelines > span:nth-child(4n+1) { background-color: #f0f0f0; }
-.sourcelines > span:nth-child(4n+3) { background-color: white; }
+.stripes4 > :nth-child(4n+1) { background-color: #f0f0f0; }
+.stripes4 > :nth-child(4n+3) { background-color: white; }
+.stripes2 > :nth-child(odd) { background-color: #f0f0f0; }
+.stripes2 > :nth-child(even) { background-color: white; }
 
 .sourcelines > span:target {
   background-color: #ffff99;