Delete all script tags before parsing html

There is an issue where SVG images containing script tags would cause the SVG
render to error.
This commit is contained in:
Nathaniel Nicandro 2018-11-17 14:45:00 -06:00
parent 9f52459325
commit 465d3222a4

View file

@ -247,16 +247,17 @@ aligns on the current line."
(setf (image-property image :ascent) 50)
(force-window-update)))))
(defun jupyter--delete-javascript-tags (beg end)
(save-restriction
(narrow-to-region beg end)
(goto-char beg)
(while (re-search-forward "<script type='text/javascript'>" nil t)
(delete-region
(match-beginning 0)
(progn
(re-search-forward "</script>")
(point))))))
(defun jupyter--delete-script-tags (beg end)
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char beg)
(while (re-search-forward "<script[^>]*>" nil t)
(delete-region
(match-beginning 0)
(if (re-search-forward "</script>" nil t)
(point)
(point-max)))))))
(defun jupyter-insert-html (html)
"Parse and insert the HTML string using `shr'."
@ -274,7 +275,7 @@ aligns on the current line."
;; widgets?
;; NOTE: Parsing takes a very long time when the text
;; is > ~500000 characters.
(jupyter--delete-javascript-tags beg end)
(jupyter--delete-script-tags beg end)
(shr-render-region beg end)
(jupyter-add-font-lock-properties beg end))))