invenio
invenio copied to clipboard
BibEdit: problems when saving changes
Originally on 2012-11-13
In some cases, after saving the changes with BibEdit, there might be a js error when the preview window is shown (maybe due to some incompatibilities with the javascript used in bibformat to render the record). In this cases, the changes will remain in the bibedit cache but will not be sent to the bibsched.
Originally on 2012-12-06
Fixed in http://invenio-software.org/repo/personal/invenio-jmartinm/log/?h=bibedit-fix-preview
Originally on 2013-02-13
Since branch bibedit-fix-preview
apparently disappeared, I have made available a patch on the basis of code already deployed on CDS (+ minor changes to still display MathJax in preview, as well as adding MathJax in header, not in-between header and body tags): invenio-jerome/master-bibedit-preview-clean-scripts
.
Hopefully this is covering everything that was in the original branch...
Originally on 2013-02-13
That seems about right. As fas as I remember the only code introduced was the BeautifulSoup bit that was stripping off javascript, so it should be good with your changes.
@jmartinm I think this has been already integrated into master? Can you confirm so we can close the ticket?
I don't see the BeautifulSoup part in BibEdit code in master, I have not seen any problem with this so don't know if it was some CDS-specific JavaScript that was conflicting at the time? Did you get any error report lately?
There is still an issue on CDS, for pages that contain some javascript, for example videos.
FYI @egabancho if you'd like to try it out, here is @jeromecaffaro's edited version of @jmartinm's patch:
commit af1107b175ab2494f5f1c2400d71b36b291f4078
tree d53a70bbbd5a7c4cec4765f1d766cb3a49e64e9d
parent fc4e5a42e3210fd00c727b2505764b801403a50b
author Javier Martin Montull <[email protected]> 1360762429 +0100
committer Jerome Caffaro <[email protected]> 1360762429 +0100
BibEdit: wash Javascript in preview
* When previewing a record, wash away <script> tags in order
to avoid possible conflicts with BibEdit Javascript. Only
MathJax is retained, when previewing in separate window.
* Includes MathJax script inside the header of the page, not
in-between header and body tags.
Co-authored-by: Jerome Caffaro <[email protected]>
diff --git a/modules/bibedit/lib/bibedit_engine.py b/modules/bibedit/lib/bibedit_engine.py
index f0f3f58..e46f378 100644
--- a/modules/bibedit/lib/bibedit_engine.py
+++ b/modules/bibedit/lib/bibedit_engine.py
@@ -26,6 +26,11 @@ import re
import difflib
import zlib
import copy
+try:
+ import BeautifulSoup
+ BEAUTIFUL_SOUP_IMPORTED = True
+except ImportError:
+ BEAUTIFUL_SOUP_IMPORTED = False
from invenio import bibrecord
from invenio import bibformat
@@ -1546,7 +1551,7 @@ def _get_formated_record(record, new_window):
"""%{'site_url': CFG_SITE_URL,
'cssskin': CFG_WEBSTYLE_TEMPLATE_SKIN != 'default' and '_' + CFG_WEBSTYLE_TEMPLATE_SKIN or ''
}
- result += get_mathjax_header(True) + '<body>'
+ result += '<body>'
result += "<h2> Brief format preview </h2><br />"
result += bibformat.format_record(recID=None,
of="hb",
@@ -1571,6 +1576,13 @@ def _get_formated_record(record, new_window):
if new_window:
result += "</body></html>"
+ if BEAUTIFUL_SOUP_IMPORTED:
+ # Remove all script tags to avoid conflicts
+ soup = BeautifulSoup.BeautifulSoup(result)
+ [s.extract() for s in soup('script')]
+ result = str(soup)
+
+ result = result.replace('</head>', get_mathjax_header(True) + '</head>', 1)
return result
@egabancho I think we could close this, as on CDS we have solved it by disabling the previewer for some records.