diff --git a/pastebin/apps/dpaste/forms.py b/pastebin/apps/dpaste/forms.py
index 7a9af97..97fb00c 100644
--- a/pastebin/apps/dpaste/forms.py
+++ b/pastebin/apps/dpaste/forms.py
@@ -112,6 +112,12 @@ class UserSettingsForm(forms.Form):
widget=forms.CheckboxInput,
help_text=_(u'This also enables the super secret \'guess lexer\' function.'),
)
+ wordwrap = forms.BooleanField(
+ label=_('Always enable wordwrap'),
+ required=False,
+ widget=forms.CheckboxInput,
+ help_text=_(u'Wordwrap is always enabled for text lexers such as \'text\' or \'reStructuredText\'.'),
+ )
font_family = forms.ChoiceField(label=_(u'Font Family'), required=False, choices=USERPREFS_FONT_CHOICES)
font_size = forms.ChoiceField(label=_(u'Font Size'), required=False, choices=USERPREFS_SIZES)
line_height = forms.ChoiceField(label=_(u'Line Height'), required=False, choices=USERPREFS_SIZES)
diff --git a/pastebin/apps/dpaste/highlight.py b/pastebin/apps/dpaste/highlight.py
index 02245d3..1f528b3 100644
--- a/pastebin/apps/dpaste/highlight.py
+++ b/pastebin/apps/dpaste/highlight.py
@@ -28,7 +28,7 @@ LEXER_LIST = (
('text', 'Text only'),
)
LEXER_DEFAULT = 'python'
-
+LEXER_WORDWRAP = ('text', 'rst')
class NakedHtmlFormatter(HtmlFormatter):
def wrap(self, source, outfile):
@@ -48,7 +48,7 @@ def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
lexer = guess_lexer(code_string)
except:
lexer = PythonLexer()
-
+
try:
return highlight(code_string, lexer, NakedHtmlFormatter())
except:
diff --git a/pastebin/apps/dpaste/templates/dpaste/snippet_details.html b/pastebin/apps/dpaste/templates/dpaste/snippet_details.html
index 81c332d..1916dfc 100644
--- a/pastebin/apps/dpaste/templates/dpaste/snippet_details.html
+++ b/pastebin/apps/dpaste/templates/dpaste/snippet_details.html
@@ -37,7 +37,7 @@
Delete now!
—
{% endif %}
- {% trans "Wordwrap" %}
+ {% trans "Wordwrap" %}
{% if snippet.title %}{{ snippet.title }}{% else %} {% trans "Snippet" %} #{{ snippet.id}}{% endif %}
@@ -131,15 +131,22 @@ jQuery(document).ready(function(){
*/
$('#toggleWordwrap').toggle(
function(){
+ $('input', this).attr('checked', 'checked');
$('div.snippet pre.code').css('white-space', 'pre-wrap');
return false;
},
function(){
+ $('input', this).attr('checked', '');
$('div.snippet pre.code').css('white-space', 'pre');
return false;
}
);
+ // Activate wordwrap for text heavy lexers or if enabled in the settings
+ if('{{ wordwrap }}' === 'True' || '{{ request.session.userprefs.wordwrap }}' === 'True') {
+ $('#toggleWordwrap').trigger('click');
+ }
+
/**
* Line Highlighting
*/
diff --git a/pastebin/apps/dpaste/views.py b/pastebin/apps/dpaste/views.py
index 6bb75aa..d57f03f 100644
--- a/pastebin/apps/dpaste/views.py
+++ b/pastebin/apps/dpaste/views.py
@@ -5,11 +5,14 @@ from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, \
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.utils.translation import ugettext_lazy as _
-from pastebin.apps.dpaste.forms import SnippetForm, UserSettingsForm
-from pastebin.apps.dpaste.models import Snippet
-from pastebin.apps.dpaste.highlight import pygmentize, guess_code_lexer
from django.core.urlresolvers import reverse
from django.utils import simplejson
+
+from pastebin.apps.dpaste.forms import SnippetForm, UserSettingsForm
+from pastebin.apps.dpaste.models import Snippet
+from pastebin.apps.dpaste.highlight import pygmentize, guess_code_lexer, \
+ LEXER_WORDWRAP
+
import difflib
def snippet_new(request, template_name='dpaste/snippet_new.html'):
@@ -44,7 +47,7 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
except ObjectDoesNotExist:
raise Http404('This snippet does not exist anymore. Its likely that its '
'lifetime is expired.')
-
+
tree = snippet.get_root()
tree = tree.get_descendants(include_self=True)
@@ -66,6 +69,7 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
'snippet': snippet,
'lines': range(snippet.get_linecount()),
'tree': tree,
+ 'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
}
response = render_to_response(
diff --git a/pastebin/static/theme.css b/pastebin/static/theme.css
index 2d08663..99484d0 100644
--- a/pastebin/static/theme.css
+++ b/pastebin/static/theme.css
@@ -171,7 +171,7 @@ form.snippetform ol li{
form.snippetform label{
width: 125px;
- float: left;
+ display: inline-block;
}
form.snippetform #id_content{