1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 14:30:01 +00:00

Decode HTML entities in comments, make blockquotes smaller

Flask escapes < > etc, and the markdown parser does not consider
&gt; as > aka blockquote. Fixed by decoding HTML source before
rendering markdown.
This commit is contained in:
TheAMM 2017-11-10 02:12:08 +02:00
parent f6735219f0
commit 0b094a7229
3 changed files with 22 additions and 6 deletions

View file

@ -182,7 +182,7 @@ class DisabledSelectField(SelectField):
class CommentForm(FlaskForm): class CommentForm(FlaskForm):
comment = TextAreaField('Make a comment', [ 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.'), 'long and %(max)d at most.'),
DataRequired(message='Comment must not be empty.') DataRequired(message='Comment must not be empty.')
]) ])

View file

@ -565,3 +565,9 @@ td.report-action-column {
width: 400px; width: 400px;
} }
} }
/* Override <blockquote> font size (assume main.css comes after bootstrap) */
blockquote {
font-size: inherit;
}

View file

@ -75,6 +75,7 @@ $(document).ready(function() {
$(this).next().stop().slideToggle(250); $(this).next().stop().slideToggle(250);
}); });
// Comment editing below
$('.edit-comment').click(function(e) { $('.edit-comment').click(function(e) {
e.preventDefault(); e.preventDefault();
$(this).closest('.comment').toggleClass('is-editing'); $(this).closest('.comment').toggleClass('is-editing');
@ -234,15 +235,24 @@ document.addEventListener("DOMContentLoaded", function() {
for (var i = 0; i < markdownTargets.length; i++) { for (var i = 0; i < markdownTargets.length; i++) {
var target = markdownTargets[i]; var target = markdownTargets[i];
var rendered; var rendered;
var markdownSource = htmlDecode(target.innerHTML);
if (target.attributes["markdown-text-inline"]) { if (target.attributes["markdown-text-inline"]) {
rendered = markdown.renderInline(target.innerHTML); rendered = markdown.renderInline(markdownSource);
} else { } else {
rendered = markdown.render(target.innerHTML); rendered = markdown.render(markdownSource);
} }
target.innerHTML = rendered; target.innerHTML = rendered;
} }
}); });
// Decode HTML entities (&gt; 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 // This is the unminified version of the theme changer script in the layout.html @ line: 21
// =========================================================== // ===========================================================