diff --git a/fluffy/static/js/paste-inline.js b/fluffy/static/js/paste-inline.js index 3cc389b..73e55d0 100644 --- a/fluffy/static/js/paste-inline.js +++ b/fluffy/static/js/paste-inline.js @@ -91,7 +91,23 @@ function updateSelectedHash(selected) { } $(document).ready(function() { - var numbers = $('.line-numbers > a'); + + $("#do_word_wrap").click(function () { + let text_to_wrap = $(".highlight").find('pre'); + if (text_to_wrap.css('white-space')==="pre") { + text_to_wrap.css('white-space', 'break-spaces'); + } else { + text_to_wrap.css('white-space', ''); + } + }); + + var numbers = $('.highlight > pre > span'); + numbers.each(function (i) { + var data = $("").text($(this).text()); + var line_num = $("").text(i); + $(this).html(""); + $(this).append(line_num, data); + }); var setState = -1; $(document).mouseup(function() { setState = -1; @@ -121,12 +137,13 @@ $(document).ready(function() { } var selected = selectedLines(); - var line = parseInt(el.text()); + var line = parseInt(el.get(0).id.replace("line-", "")); var idx = selected.indexOf(line); if (idx === -1 && setState === 1) { updateLineClasses(line, true); selected.push(line); + console.log("##"+ selected); updateSelectedHash(selected); } else if (idx !== -1 && setState === 0) { selected.splice(idx, 1); @@ -138,7 +155,7 @@ $(document).ready(function() { numbers.on('mousedown', function(e) { var selected = selectedLines(); - var line = parseInt($(this).text()); + var line = parseInt(this.id.replace("line-", "")); setState = selected.indexOf(line) === -1 ? 1 : 0; return maybeChangeState($(this)); }); diff --git a/fluffy/static/scss/app.scss b/fluffy/static/scss/app.scss index 4bd3153..30c05d7 100644 --- a/fluffy/static/scss/app.scss +++ b/fluffy/static/scss/app.scss @@ -99,3 +99,7 @@ a.report { .footer a:hover { color: #89C2C7; } + +.page-paste #paste .text .highlight > pre > span::before { + content: attr(line-number); +} diff --git a/fluffy/templates/home.html b/fluffy/templates/home.html index 83a072d..a8db29e 100644 --- a/fluffy/templates/home.html +++ b/fluffy/templates/home.html @@ -38,6 +38,11 @@

+ +

+ + +

diff --git a/fluffy/templates/paste.html b/fluffy/templates/paste.html index a8437a0..90c207e 100644 --- a/fluffy/templates/paste.html +++ b/fluffy/templates/paste.html @@ -31,11 +31,11 @@ {% endblock %} {% block text %} -

- {% for i in range(1, num_lines(text) + 1) %} - {{i}} - {% endfor %} -
+{#
#} +{# {% for i in range(1, num_lines(text) + 1) %}#} +{# {{i}}#} +{# {% endfor %}#} +{#
#}
{{highlighter.highlight(text)|safe}}
diff --git a/fluffy/utils.py b/fluffy/utils.py index e703996..87488f9 100644 --- a/fluffy/utils.py +++ b/fluffy/utils.py @@ -1,5 +1,7 @@ import os import random +from json import dumps +from json import loads from fluffy.app import app @@ -98,3 +100,14 @@ def get_result(): return result return get_result() + + +def iff_json_then_pretty_json(text): + try: + text_no_whitespace = text.strip() + if text_no_whitespace[0] in ['[', '{'] and text_no_whitespace[-1] in [']', '}']: + text = dumps(loads(text), separators=(',', ':'), indent=4) + return text + except ValueError: + pass + return None diff --git a/fluffy/views.py b/fluffy/views.py index 5b73c0b..ce8b040 100644 --- a/fluffy/views.py +++ b/fluffy/views.py @@ -19,6 +19,7 @@ from fluffy.models import UploadedFile from fluffy.utils import human_size from fluffy.utils import ICON_EXTENSIONS +from fluffy.utils import iff_json_then_pretty_json from fluffy.utils import ONE_MB @@ -153,8 +154,12 @@ def paste(): ), 413 objects.append(uf) + if request.form.get('format_text'): + if iff_json_then_pretty_json(text): + text = iff_json_then_pretty_json(text) + lang = 'json' # HTML view (Markdown or paste) - lang = request.form['language'] + lang = lang or request.form['language'] if lang != 'rendered-markdown': highlighter = get_highlighter(text, lang, None) lang_title = highlighter.name