mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +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,
|
widget=forms.CheckboxInput,
|
||||||
help_text=_(u'This also enables the super secret \'guess lexer\' function.'),
|
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_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)
|
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)
|
line_height = forms.ChoiceField(label=_(u'Line Height'), required=False, choices=USERPREFS_SIZES)
|
||||||
|
|
|
@ -28,7 +28,7 @@ LEXER_LIST = (
|
||||||
('text', 'Text only'),
|
('text', 'Text only'),
|
||||||
)
|
)
|
||||||
LEXER_DEFAULT = 'python'
|
LEXER_DEFAULT = 'python'
|
||||||
|
LEXER_WORDWRAP = ('text', 'rst')
|
||||||
|
|
||||||
class NakedHtmlFormatter(HtmlFormatter):
|
class NakedHtmlFormatter(HtmlFormatter):
|
||||||
def wrap(self, source, outfile):
|
def wrap(self, source, outfile):
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<a onclick="return confirm('{% trans "Really delete this snippet?" %}')" href="{% url snippet_delete snippet.secret_id %}">Delete now!</a>
|
<a onclick="return confirm('{% trans "Really delete this snippet?" %}')" href="{% url snippet_delete snippet.secret_id %}">Delete now!</a>
|
||||||
—
|
—
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a id="toggleWordwrap" href="#">{% trans "Wordwrap" %}</a>
|
<a id="toggleWordwrap" href="#"><input type="checkbox"/> {% trans "Wordwrap" %}</a>
|
||||||
</div>
|
</div>
|
||||||
<h2>
|
<h2>
|
||||||
{% if snippet.title %}{{ snippet.title }}{% else %} {% trans "Snippet" %} #{{ snippet.id}}{% endif %}
|
{% if snippet.title %}{{ snippet.title }}{% else %} {% trans "Snippet" %} #{{ snippet.id}}{% endif %}
|
||||||
|
@ -131,15 +131,22 @@ jQuery(document).ready(function(){
|
||||||
*/
|
*/
|
||||||
$('#toggleWordwrap').toggle(
|
$('#toggleWordwrap').toggle(
|
||||||
function(){
|
function(){
|
||||||
|
$('input', this).attr('checked', 'checked');
|
||||||
$('div.snippet pre.code').css('white-space', 'pre-wrap');
|
$('div.snippet pre.code').css('white-space', 'pre-wrap');
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
function(){
|
function(){
|
||||||
|
$('input', this).attr('checked', '');
|
||||||
$('div.snippet pre.code').css('white-space', 'pre');
|
$('div.snippet pre.code').css('white-space', 'pre');
|
||||||
return false;
|
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
|
* Line Highlighting
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,11 +5,14 @@ from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, \
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.core.urlresolvers import reverse
|
||||||
from django.utils import simplejson
|
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
|
import difflib
|
||||||
|
|
||||||
def snippet_new(request, template_name='dpaste/snippet_new.html'):
|
def snippet_new(request, template_name='dpaste/snippet_new.html'):
|
||||||
|
@ -66,6 +69,7 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
|
||||||
'snippet': snippet,
|
'snippet': snippet,
|
||||||
'lines': range(snippet.get_linecount()),
|
'lines': range(snippet.get_linecount()),
|
||||||
'tree': tree,
|
'tree': tree,
|
||||||
|
'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = render_to_response(
|
response = render_to_response(
|
||||||
|
|
|
@ -171,7 +171,7 @@ form.snippetform ol li{
|
||||||
|
|
||||||
form.snippetform label{
|
form.snippetform label{
|
||||||
width: 125px;
|
width: 125px;
|
||||||
float: left;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
form.snippetform #id_content{
|
form.snippetform #id_content{
|
||||||
|
|
Loading…
Reference in a new issue