From 0b094a72291e071a2e9736420f1fce71de0f1092 Mon Sep 17 00:00:00 2001 From: TheAMM Date: Fri, 10 Nov 2017 02:12:08 +0200 Subject: [PATCH] Decode HTML entities in comments, make blockquotes smaller Flask escapes < > etc, and the markdown parser does not consider > as > aka blockquote. Fixed by decoding HTML source before rendering markdown. --- nyaa/forms.py | 2 +- nyaa/static/css/main.css | 6 ++++++ nyaa/static/js/main.js | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nyaa/forms.py b/nyaa/forms.py index 18a45ee..db575b0 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -182,7 +182,7 @@ class DisabledSelectField(SelectField): class CommentForm(FlaskForm): comment = TextAreaField('Make a comment', [ - Length(min=3, max=1024, message='Comment must be at least %(min)d characters ' + Length(min=3, max=2048, message='Comment must be at least %(min)d characters ' 'long and %(max)d at most.'), DataRequired(message='Comment must not be empty.') ]) diff --git a/nyaa/static/css/main.css b/nyaa/static/css/main.css index 9d4eefc..525e0a1 100644 --- a/nyaa/static/css/main.css +++ b/nyaa/static/css/main.css @@ -565,3 +565,9 @@ td.report-action-column { width: 400px; } } + + +/* Override
font size (assume main.css comes after bootstrap) */ +blockquote { + font-size: inherit; +} \ No newline at end of file diff --git a/nyaa/static/js/main.js b/nyaa/static/js/main.js index 90db9b7..2796a0e 100644 --- a/nyaa/static/js/main.js +++ b/nyaa/static/js/main.js @@ -67,7 +67,7 @@ $(document).ready(function() { $('#torrent_file')[0].files = files; $(this).css({ 'visibility': 'hidden', 'opacity': 0 }); }); - + // Collapsible file lists $('.torrent-file-list a.folder').click(function(e) { e.preventDefault(); @@ -75,6 +75,7 @@ $(document).ready(function() { $(this).next().stop().slideToggle(250); }); + // Comment editing below $('.edit-comment').click(function(e) { e.preventDefault(); $(this).closest('.comment').toggleClass('is-editing'); @@ -84,7 +85,7 @@ $(document).ready(function() { var $this = $(this), text = $(this).text(), until = $this.data('until'); - + var displayTimeRemaining = function() { var diff = Math.max(0, until - (Date.now() / 1000) | 0), min = Math.floor(diff / 60), @@ -110,7 +111,7 @@ $(document).ready(function() { data: $this.serialize() }).done(function(data) { var $comment = $this.closest('.comment'); - $comment.find('.comment-content').html(markdown.render(data.comment)); + $comment.find('.comment-content').html(markdown.render(data.comment)); $comment.toggleClass('is-editing'); }).fail(function(xhr) { var error = xhr.responseJSON && xhr.responseJSON.error || 'An unknown error occurred.'; @@ -234,15 +235,24 @@ document.addEventListener("DOMContentLoaded", function() { for (var i = 0; i < markdownTargets.length; i++) { var target = markdownTargets[i]; var rendered; + var markdownSource = htmlDecode(target.innerHTML); if (target.attributes["markdown-text-inline"]) { - rendered = markdown.renderInline(target.innerHTML); + rendered = markdown.renderInline(markdownSource); } else { - rendered = markdown.render(target.innerHTML); + rendered = markdown.render(markdownSource); } target.innerHTML = rendered; } }); + +// Decode HTML entities (> etc), used for decoding comment markdown from escaped text +function htmlDecode(input){ + var e = document.createElement('div'); + e.innerHTML = input; + return e.childNodes[0].nodeValue; +} + // // This is the unminified version of the theme changer script in the layout.html @ line: 21 // ===========================================================