Files
postgres-web/media/js/admin_pgweb.js
Magnus Hagander ea9becd746 Re-do markdown handling for better user experience and security
* Get rid of the django_markwhat dependency, and implement our own
  classes to get more control. In passing also remove django-markdown,
  because we never used that.
* Instead of trying to clean markdown with regexps, use the bleach
  library (NEW DEPENDENCY) with special whitelisting of allowed tags
  based off standard markdown. This means that one can input links or
  formatting in HTML if one prefers, as long as it renders to the same
  subset of tags that markdown allows.
* Replace javascript based client side preview with an actual call to a
  preview URL that renders the exact result using the same function,
  since the use of showdown on the client was increasingly starting to
  differ from the server, and since that cannot be kept secure the same
  way. Rewrite the client side javascript to work better with the now
  longer interval between updates of the preview.

Long in planning, but never got around to it.

Suggestion to use bleach for escaping from David Fetter.
2020-11-12 18:52:04 +01:00

27 lines
1.0 KiB
JavaScript

window.onload = function() {
/* Preview in the pure admin views */
let tael = document.getElementsByTagName('textarea');
for (let i = 0; i < tael.length; i++) {
if (tael[i].className.indexOf('markdown_preview') >= 0) {
attach_markdown_preview(tael[i].id, 1);
}
}
/* Preview in the moderation view */
let previews = document.getElementsByClassName('mdpreview');
for (let i = 0; i < previews.length; i++) {
let iframe = previews[i];
let textdiv = iframe.parentElement.previousElementSibling.getElementsByClassName('txtpreview')[0]
let hiddendiv = iframe.nextElementSibling;
/* Copy the HTML into the iframe */
iframe.srcdoc = hiddendiv.innerHTML;
/* Resize the height to to be the same */
if (textdiv.offsetHeight > iframe.offsetHeight)
iframe.style.height = textdiv.offsetHeight + 'px';
if (iframe.offsetHeight > textdiv.offsetHeight)
textdiv.style.height = iframe.offsetHeight + 'px';
}
}