Preserve format tags and entities in bibliography editor
- Fixes errors in previous commits55bfe54a
and9431e0de
, to wit ... - Apply unescapeHTML after RTF tag and entity conversions - Remove high-bit character escape from entity converter, and apply separately after remaining HTML entities are decoded by unescapeHTML
This commit is contained in:
parent
53d2aa43d6
commit
2a2e5e4e39
|
@ -51,19 +51,26 @@
|
||||||
this._onInitCallbacks = [];
|
this._onInitCallbacks = [];
|
||||||
this._iframe = document.getAnonymousElementByAttribute(this, "anonid", "rt-view");
|
this._iframe = document.getAnonymousElementByAttribute(this, "anonid", "rt-view");
|
||||||
|
|
||||||
this._htmlRTFmap = [
|
|
||||||
// Atomic units, HTML -> RTF (cleanup)
|
// Atomic units, HTML -> RTF (cleanup)
|
||||||
|
//[/<\/p>(?!\s*$)/g, "\\par{}"],
|
||||||
|
//[/ /g, " "],
|
||||||
|
//[/\u00A0/g, " "],
|
||||||
|
this._htmlRTFmap = [
|
||||||
[/<br \/>/g, "\x0B"],
|
[/<br \/>/g, "\x0B"],
|
||||||
|
[/<span class=\"tab\"> <\/span>/g, "\\tab{}"],
|
||||||
|
[/‘/g, "‘"],
|
||||||
|
[/’/g, "’"],
|
||||||
|
[/“/g, "“"],
|
||||||
|
[/”/g, "”"],
|
||||||
|
[/ /g, "\u00A0"],
|
||||||
[/"(\w)/g, "“$1"],
|
[/"(\w)/g, "“$1"],
|
||||||
[/([\w,.?!])"/g, "$1”"],
|
[/([\w,.?!])"/g, "$1”"],
|
||||||
[/<p>/g, ""],
|
[/<p>/g, ""],
|
||||||
//[/<\/p>(?!\s*$)/g, "\\par{}"],
|
[/<\/?div[^>]*>/g, ""]
|
||||||
[/<\/?div[^>]*>/g, ""],
|
|
||||||
[/[\x7F-\uFFFF]/g, function(aChar) { return "\\uc0\\u"+aChar.charCodeAt(0).toString()+"{}"}]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
this._rtfHTMLmap = [
|
|
||||||
// Atomic units, RTF -> HTML (cleanup)
|
// Atomic units, RTF -> HTML (cleanup)
|
||||||
|
this._rtfHTMLmap = [
|
||||||
[/\\uc0\{?\\u([0-9]+)\}?(?:{}| )?/g, function(wholeStr, aCode) { return String.fromCharCode(aCode) }],
|
[/\\uc0\{?\\u([0-9]+)\}?(?:{}| )?/g, function(wholeStr, aCode) { return String.fromCharCode(aCode) }],
|
||||||
[/\\tab(?:\{\}| )/g, '<span class="tab"> </span>'],
|
[/\\tab(?:\{\}| )/g, '<span class="tab"> </span>'],
|
||||||
[/(?:\\par{}|\\\r?\n)/g, "</p><p>"]
|
[/(?:\\par{}|\\\r?\n)/g, "</p><p>"]
|
||||||
|
@ -339,14 +346,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.htmlToRTF = function(txt) {
|
this.htmlToRTF = function(txt) {
|
||||||
// Catch this one before is clobbered by unescape
|
txt = this.convert("htmlRTF", txt);
|
||||||
txt = txt.replace(/<span class=\"tab\"> <\/span>/g, "\\tab{}");
|
|
||||||
txt = Zotero.Utilities.unescapeHTML(txt);
|
|
||||||
for (var i=0,ilen=this._htmlRTFmap.length; i < ilen; i++) {
|
for (var i=0,ilen=this._htmlRTFmap.length; i < ilen; i++) {
|
||||||
var entry = this._htmlRTFmap[i];
|
var entry = this._htmlRTFmap[i];
|
||||||
txt = txt.replace(entry[0], entry[1]);
|
txt = txt.replace(entry[0], entry[1]);
|
||||||
}
|
}
|
||||||
txt = this.convert("htmlRTF", txt);
|
txt = Zotero.Utilities.unescapeHTML(txt);
|
||||||
|
txt = txt.replace(/[\x7F-\uFFFF]/g, function(aChar) { return "\\uc0\\u"+aChar.charCodeAt(0).toString()+"{}"});
|
||||||
return txt.trim();
|
return txt.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user