mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Enabled wordwrap by default for text lexer, display a checkbox inside the label and added a user pref to enable wordwrap by default.
This commit is contained in:
parent
9efe17b5d7
commit
e79cb69530
5 changed files with 25 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<a onclick="return confirm('{% trans "Really delete this snippet?" %}')" href="{% url snippet_delete snippet.secret_id %}">Delete now!</a>
|
||||
—
|
||||
{% endif %}
|
||||
<a id="toggleWordwrap" href="#">{% trans "Wordwrap" %}</a>
|
||||
<a id="toggleWordwrap" href="#"><input type="checkbox"/> {% trans "Wordwrap" %}</a>
|
||||
</div>
|
||||
<h2>
|
||||
{% 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
|
||||
*/
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -171,7 +171,7 @@ form.snippetform ol li{
|
|||
|
||||
form.snippetform label{
|
||||
width: 125px;
|
||||
float: left;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
form.snippetform #id_content{
|
||||
|
|
Loading…
Reference in a new issue