Wordwrap support.

This commit is contained in:
Martin Mahner 2014-01-21 21:08:59 +01:00
parent 973a7b825e
commit c61f134bb3
5 changed files with 116 additions and 90 deletions

View file

@ -142,11 +142,12 @@ h1, h2, h3, h4 {
}
.snippet-rendered {
color: #555;
color: #666;
font-size: 16px;
line-height: 1.5em;
max-width: 700px;
font-family: Georgia, Palatino, "Palatino Linotype", FreeSerif, serif;
line-height: 24px;
max-width: 620px;
font-family: Helvetica, FreeSerif, serif;
font-weight: 300;
}
div.tree{
@ -195,27 +196,114 @@ div.tree div.submit input{
}
/* ----------------------------------------------------------------------------
Pre
.code
---------------------------------------------------------------------------- */
.code {
background: #232829;
color: #f8f8f2;
padding: 20px 30px !important;
border-radius: 0;
padding: 20px 30px;
font-family: Monaco,Menlo,Consolas,"Courier New",monospace;
}
ol.linenums {
.code.wordwrap {
overflow: auto;
white-space: nowrap;
}
.code ol {
margin: 0 0 0 45px;
}
ol.linenums li {
.code ol li {
color: #aaa;
font-size: 12px;
line-height: 20px;
line-height: 21px;
cursor: pointer;
padding-left: 5px;
}
ol.linenums li.marked {
.code ol li.marked {
color: #f4e009;
background-color: #4f4800;
margin-right: -30px;
padding-right: 30px;
}
/* ----------------------------------------------------------------------------
Pygments
---------------------------------------------------------------------------- */
.code .gd { background-color: rgba(226, 12, 19, .3); color: #fff; display: block; }
.code .gi { background-color: rgba(23, 189, 10, .2); color: #fff; display: block; }
.code .hll { background-color: #49483e }
.code .c { color: #75715e } /* Comment */
.code .err { color: #960050; background-color: #1e0010 } /* Error */
.code .k { color: #66d9ef } /* Keyword */
.code .l { color: #ae81ff } /* Literal */
.code .n { color: #f8f8f2 } /* Name */
.code .o { color: #f92672 } /* Operator */
.code .p { color: #f8f8f2 } /* Punctuation */
.code .cm { color: #75715e } /* Comment.Multiline */
.code .cp { color: #75715e } /* Comment..codeproc */
.code .c1 { color: #75715e } /* Comment.Single */
.code .cs { color: #75715e } /* Comment.Special */
.code .ge { font-style: italic } /* Generic.Emph */
.code .gs { font-weight: bold } /* Generic.Strong */
.code .kc { color: #66d9ef } /* Keyword.Constant */
.code .kd { color: #66d9ef } /* Keyword.Declaration */
.code .kn { color: #f92672 } /* Keyword.Namespace */
.code .kp { color: #66d9ef } /* Keyword.Pseudo */
.code .kr { color: #66d9ef } /* Keyword.Reserved */
.code .kt { color: #66d9ef } /* Keyword.Type */
.code .ld { color: #e6db74 } /* Literal.Date */
.code .m { color: #ae81ff } /* Literal.Number */
.code .s { color: #e6db74 } /* Literal.String */
.code .na { color: #a6e22e } /* Name.Attribute */
.code .nb { color: #f8f8f2 } /* Name.Builtin */
.code .nc { color: #a6e22e } /* Name.Class */
.code .no { color: #66d9ef } /* Name.Constant */
.code .nd { color: #a6e22e } /* Name.Decorator */
.code .ni { color: #f8f8f2 } /* Name.Entity */
.code .ne { color: #a6e22e } /* Name.Exception */
.code .nf { color: #a6e22e } /* Name.Function */
.code .nl { color: #f8f8f2 } /* Name.Label */
.code .nn { color: #f8f8f2 } /* Name.Namespace */
.code .nx { color: #a6e22e } /* Name.Other */
.code .py { color: #f8f8f2 } /* Name.Property */
.code .nt { color: #f92672 } /* Name.Tag */
.code .nv { color: #f8f8f2 } /* Name.Variable */
.code .ow { color: #f92672 } /* Operator.Word */
.code .w { color: #f8f8f2 } /* Text.Whitespace */
.code .mf { color: #ae81ff } /* Literal.Number.Float */
.code .mh { color: #ae81ff } /* Literal.Number.Hex */
.code .mi { color: #ae81ff } /* Literal.Number.Integer */
.code .mo { color: #ae81ff } /* Literal.Number.Oct */
.code .sb { color: #e6db74 } /* Literal.String.Backtick */
.code .sc { color: #e6db74 } /* Literal.String.Char */
.code .sd { color: #e6db74 } /* Literal.String.Doc */
.code .s2 { color: #e6db74 } /* Literal.String.Double */
.code .se { color: #ae81ff } /* Literal.String.Escape */
.code .sh { color: #e6db74 } /* Literal.String.Heredoc */
.code .si { color: #e6db74 } /* Literal.String.Interpol */
.code .sx { color: #e6db74 } /* Literal.String.Other */
.code .sr { color: #e6db74 } /* Literal.String.Regex */
.code .s1 { color: #e6db74 } /* Literal.String.Single */
.code .ss { color: #e6db74 } /* Literal.String.Symbol */
.code .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.code .vc { color: #f8f8f2 } /* Name.Variable.Class */
.code .vg { color: #f8f8f2 } /* Name.Variable.Global */
.code .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.code .il { color: #ae81ff } /* Literal.Number.Integer.Long */
/* ----------------------------------------------------------------------------
Mobile
---------------------------------------------------------------------------- */
@media (max-width: 580px) {
.form-options-expire {
float: left;
@ -223,78 +311,3 @@ ol.linenums li.marked {
margin-top: 10px;
}
}
/* ----------------------------------------------------------------------------
Pygments
---------------------------------------------------------------------------- */
pre {
background: #232829;
color: #f8f8f2;
padding: 10px 15px 10px 0;
border-radius: 0;
padding: 20px 30px;
}
pre .gd { background-color: rgba(226, 12, 19, .3); color: #fff; display: block; }
pre .gi { background-color: rgba(23, 189, 10, .2); color: #fff; display: block; }
pre .hll { background-color: #49483e }
pre .c { color: #75715e } /* Comment */
pre .err { color: #960050; background-color: #1e0010 } /* Error */
pre .k { color: #66d9ef } /* Keyword */
pre .l { color: #ae81ff } /* Literal */
pre .n { color: #f8f8f2 } /* Name */
pre .o { color: #f92672 } /* Operator */
pre .p { color: #f8f8f2 } /* Punctuation */
pre .cm { color: #75715e } /* Comment.Multiline */
pre .cp { color: #75715e } /* Comment.Preproc */
pre .c1 { color: #75715e } /* Comment.Single */
pre .cs { color: #75715e } /* Comment.Special */
pre .ge { font-style: italic } /* Generic.Emph */
pre .gs { font-weight: bold } /* Generic.Strong */
pre .kc { color: #66d9ef } /* Keyword.Constant */
pre .kd { color: #66d9ef } /* Keyword.Declaration */
pre .kn { color: #f92672 } /* Keyword.Namespace */
pre .kp { color: #66d9ef } /* Keyword.Pseudo */
pre .kr { color: #66d9ef } /* Keyword.Reserved */
pre .kt { color: #66d9ef } /* Keyword.Type */
pre .ld { color: #e6db74 } /* Literal.Date */
pre .m { color: #ae81ff } /* Literal.Number */
pre .s { color: #e6db74 } /* Literal.String */
pre .na { color: #a6e22e } /* Name.Attribute */
pre .nb { color: #f8f8f2 } /* Name.Builtin */
pre .nc { color: #a6e22e } /* Name.Class */
pre .no { color: #66d9ef } /* Name.Constant */
pre .nd { color: #a6e22e } /* Name.Decorator */
pre .ni { color: #f8f8f2 } /* Name.Entity */
pre .ne { color: #a6e22e } /* Name.Exception */
pre .nf { color: #a6e22e } /* Name.Function */
pre .nl { color: #f8f8f2 } /* Name.Label */
pre .nn { color: #f8f8f2 } /* Name.Namespace */
pre .nx { color: #a6e22e } /* Name.Other */
pre .py { color: #f8f8f2 } /* Name.Property */
pre .nt { color: #f92672 } /* Name.Tag */
pre .nv { color: #f8f8f2 } /* Name.Variable */
pre .ow { color: #f92672 } /* Operator.Word */
pre .w { color: #f8f8f2 } /* Text.Whitespace */
pre .mf { color: #ae81ff } /* Literal.Number.Float */
pre .mh { color: #ae81ff } /* Literal.Number.Hex */
pre .mi { color: #ae81ff } /* Literal.Number.Integer */
pre .mo { color: #ae81ff } /* Literal.Number.Oct */
pre .sb { color: #e6db74 } /* Literal.String.Backtick */
pre .sc { color: #e6db74 } /* Literal.String.Char */
pre .sd { color: #e6db74 } /* Literal.String.Doc */
pre .s2 { color: #e6db74 } /* Literal.String.Double */
pre .se { color: #ae81ff } /* Literal.String.Escape */
pre .sh { color: #e6db74 } /* Literal.String.Heredoc */
pre .si { color: #e6db74 } /* Literal.String.Interpol */
pre .sx { color: #e6db74 } /* Literal.String.Other */
pre .sr { color: #e6db74 } /* Literal.String.Regex */
pre .s1 { color: #e6db74 } /* Literal.String.Single */
pre .ss { color: #e6db74 } /* Literal.String.Symbol */
pre .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
pre .vc { color: #f8f8f2 } /* Name.Variable.Class */
pre .vg { color: #f8f8f2 } /* Name.Variable.Global */
pre .vi { color: #f8f8f2 } /* Name.Variable.Instance */
pre .il { color: #ae81ff } /* Literal.Number.Integer.Long */

View file

@ -19,8 +19,9 @@
<h3>API</h3>
{# Just put the script in dpaste and copy the source node #}
<pre class="prettyprint linenums"><ol class="linenums"><li id="1"><span class="c">#!/usr/bin/env python</span></li><li id="2">&nbsp;</li><li id="3"><span class="kn">import</span> <span class="nn">urllib</span></li><li id="4"><span class="kn">import</span> <span class="nn">urllib2</span></li><li id="5"><span class="kn">import</span> <span class="nn">sys</span></li><li id="6">&nbsp;</li><li id="7"><span class="k">def</span> <span class="nf">paste_code</span><span class="p">():</span></li><li id="8"> <span class="n">request</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">Request</span><span class="p">(</span></li><li id="9"> <span class="s">'https://dpaste.de/api/'</span><span class="p">,</span></li><li id="10"> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">([(</span><span class="s">'content'</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">read</span><span class="p">())]),</span></li><li id="11"> <span class="p">)</span></li><li id="12"> <span class="n">response</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></li><li id="13"> <span class="c"># Strip surrounding quotes (NB: response has no trailing newline)</span></li><li id="14"> <span class="k">print</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span></li><li id="15">&nbsp;</li><li id="16"><span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span></li><li id="17"> <span class="n">paste_code</span><span class="p">()</span></li></ol></pre>
<div class="code"><ol class="linenums"><li id="1"><span class="c">#!/usr/bin/env python</span></li><li id="2">&nbsp;</li><li id="3"><span class="kn">import</span> <span class="nn">urllib</span></li><li id="4"><span class="kn">import</span> <span class="nn">urllib2</span></li><li id="5"><span class="kn">import</span> <span class="nn">sys</span></li><li id="6">&nbsp;</li><li id="7"><span class="k">def</span> <span class="nf">paste_code</span><span class="p">():</span></li><li id="8"> <span class="n">request</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">Request</span><span class="p">(</span></li><li id="9"> <span class="s">'https://dpaste.de/api/'</span><span class="p">,</span></li><li id="10"> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">([(</span><span class="s">'content'</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">read</span><span class="p">())]),</span></li><li id="11"> <span class="p">)</span></li><li id="12"> <span class="n">response</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></li><li id="13"> <span class="c"># Strip surrounding quotes (NB: response has no trailing newline)</span></li><li id="14"> <span class="k">print</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span></li><li id="15">&nbsp;</li><li id="16"><span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span></li><li id="17"> <span class="n">paste_code</span><span class="p">()</span></li></ol></div>
<br/>
<p>Save this script in <code>/usr/local/bin/dpaste</code> and <code>chmod +x ..filepath</code>.</p>
<p>Usage: <code>cat foo.txt | dpaste</code></p>

View file

@ -68,6 +68,9 @@
<a class="btn" href="{% url "snippet_details_raw" snippet.secret_id %}"><i class="icon-align-left"></i> {% trans "View Raw" %}</a>
<a class="btn" href="{% url "snippet_gist" snippet.secret_id %}"
rel="nofollow" title="Create a secret Gist"><i class="icon-share"></i> {% trans "Gist" %}</a>
{% if snippet.lexer != 'text' %}
<a class="btn" href="#" id="toggleWordwrap">Wordwrap</a>
{% endif %}
</div>
{% if snippet.expire_type == 3 %}
@ -88,7 +91,7 @@
======================================================================= -->
{% if snippet.lexer == 'text' %}
<div class="snippet-rendered">
{{ snippet.content|linebreaks }}
{{ snippet.content|linebreaksbr }}
</div>
{% else %}
{% include "dpaste/snippet_pre.html" %}
@ -168,24 +171,32 @@ jQuery(function($) {
hashlist = curLine.substring(2).split(',');
if (hashlist.length > 0 && hashlist[0] !== '') {
$.each(hashlist, function(index, elem){
$('.linenums li#' + elem).addClass('marked');
$('.code li#' + elem).addClass('marked');
});
}
}
$('.linenums li').click(function(e) {
$('.code li').click(function(e) {
var line = $(this),
hash = 'L';
line.toggleClass('marked');
$('.linenums li.marked').each(function (index, elem) {
$('.code li.marked').each(function (index, elem) {
if (hash !== 'L') hash += ',';
hash += $(elem).attr('id');
});
window.location.hash = hash;
});
/* ------------------------------------------------------------------------
Line Highlighting
------------------------------------------------------------------------ */
$('#toggleWordwrap').click(function(e){
e.preventDefault();
$('.code').toggleClass('wordwrap');
});
});
</script>
{% endblock %}

View file

@ -1 +1 @@
{% load dpaste_tags %}<pre><ol class="linenums">{% for line in snippet|highlight %}<li id="{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></pre>
{% load dpaste_tags %}<div class="code"><ol>{% for line in snippet|highlight %}<li id="{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></div>

View file

@ -10,4 +10,5 @@ def in_list(value, arg):
@register.filter
def highlight(snippet):
h = pygmentize(snippet.content, snippet.lexer)
h = h.replace(u' ', u' &nbsp;')
return h.splitlines()