From c61f134bb38ddce00a5bd4ba837d14546a2ffea6 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 21 Jan 2014 21:08:59 +0100 Subject: [PATCH] Wordwrap support. --- dpaste/static/dpaste/theme.css | 181 ++++++++++--------- dpaste/templates/dpaste/about.html | 3 +- dpaste/templates/dpaste/snippet_details.html | 19 +- dpaste/templates/dpaste/snippet_pre.html | 2 +- dpaste/templatetags/dpaste_tags.py | 1 + 5 files changed, 116 insertions(+), 90 deletions(-) diff --git a/dpaste/static/dpaste/theme.css b/dpaste/static/dpaste/theme.css index af8f01c..42aed6c 100644 --- a/dpaste/static/dpaste/theme.css +++ b/dpaste/static/dpaste/theme.css @@ -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 */ diff --git a/dpaste/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index 9201b3f..aa7d730 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -19,8 +19,9 @@

API

{# Just put the script in dpaste and copy the source node #} -
  1. #!/usr/bin/env python
  2.  
  3. import urllib
  4. import urllib2
  5. import sys
  6.  
  7. def paste_code():
  8. request = urllib2.Request(
  9. 'https://dpaste.de/api/',
  10. urllib.urlencode([('content', sys.stdin.read())]),
  11. )
  12. response = urllib2.urlopen(request)
  13. # Strip surrounding quotes (NB: response has no trailing newline)
  14. print response.read()[1:-1]
  15.  
  16. if __name__ == '__main__':
  17. paste_code()
+
  1. #!/usr/bin/env python
  2.  
  3. import urllib
  4. import urllib2
  5. import sys
  6.  
  7. def paste_code():
  8. request = urllib2.Request(
  9. 'https://dpaste.de/api/',
  10. urllib.urlencode([('content', sys.stdin.read())]),
  11. )
  12. response = urllib2.urlopen(request)
  13. # Strip surrounding quotes (NB: response has no trailing newline)
  14. print response.read()[1:-1]
  15.  
  16. if __name__ == '__main__':
  17. paste_code()
+

Save this script in /usr/local/bin/dpaste and chmod +x ..filepath.

Usage: cat foo.txt | dpaste

diff --git a/dpaste/templates/dpaste/snippet_details.html b/dpaste/templates/dpaste/snippet_details.html index 52926ce..83aa85e 100644 --- a/dpaste/templates/dpaste/snippet_details.html +++ b/dpaste/templates/dpaste/snippet_details.html @@ -68,6 +68,9 @@ {% trans "View Raw" %} {% trans "Gist" %} + {% if snippet.lexer != 'text' %} + Wordwrap + {% endif %} {% if snippet.expire_type == 3 %} @@ -88,7 +91,7 @@ ======================================================================= --> {% if snippet.lexer == 'text' %}
- {{ snippet.content|linebreaks }} + {{ snippet.content|linebreaksbr }}
{% 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'); + }); }); {% endblock %} diff --git a/dpaste/templates/dpaste/snippet_pre.html b/dpaste/templates/dpaste/snippet_pre.html index b2247ff..791a47d 100644 --- a/dpaste/templates/dpaste/snippet_pre.html +++ b/dpaste/templates/dpaste/snippet_pre.html @@ -1 +1 @@ -{% load dpaste_tags %}
    {% for line in snippet|highlight %}
  1. {{ line|safe|default:" " }}
  2. {% endfor %}
+{% load dpaste_tags %}
    {% for line in snippet|highlight %}
  1. {{ line|safe|default:" " }}
  2. {% endfor %}
diff --git a/dpaste/templatetags/dpaste_tags.py b/dpaste/templatetags/dpaste_tags.py index 487311b..c6b59e4 100644 --- a/dpaste/templatetags/dpaste_tags.py +++ b/dpaste/templatetags/dpaste_tags.py @@ -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'  ') return h.splitlines()