Fixes #1619, Underline formatting isn't preserved in citation editor

Frank's patch
This commit is contained in:
Dan Stillman 2009-12-18 21:49:36 +00:00
parent 833ad915f5
commit 18c7e6728f

View File

@ -56,8 +56,6 @@
"</strong>":"\\b0 ",
"<b>":"\\b ",
"</b>":"\\b0 ",
"<u>":"\\ul ",
"</u>":"\\ul0 ",
"<br />":"\x0B",
"<sup>":"\\super ",
"</sup>":"\\super0 ",
@ -68,6 +66,19 @@
'<span class="tab">&nbsp;</span>':"\t"
};
this._rtfRexMap = [
["<span style=\"font-variant:small-caps;\">",
/small-caps/,
"\\scaps ",
"\\scaps0 "
],
["<span style=\"text-decoration:underline;\">",
/underline/,
"\\ul ",
"\\ul0 "
]
]
this._constructed = true;
if (this._loadOnConstruct) {
@ -164,28 +175,29 @@
output = output.replace(needle, this._rtfMap[needle], "g");
}
// Preserve small caps
var l = output.split(/(<\/?span[^>]*>)/);
var current_level = 0;
var tag_level = [];
for (var pos=1; pos<l.length; pos+=2) {
var tag = l[pos];
if (tag[1] == "/") {
current_level--;
if (current_level == tag_level[tag_level.length-1]) {
tag_level.pop();
l[pos] = "\\scaps0 ";
}
} else {
if (l[pos].match(/small-caps/)) {
l[pos] = "\\scaps ";
tag_level.push(current_level);
}
current_level++;
// Preserve small caps and underlining
for each (var tagspec in this._rtfRexMap){
var l = output.split(/(<\/?span[^>]*>)/);
var current_level = 0;
var tag_level = [];
for (var pos=1; pos<l.length; pos+=2) {
var tag = l[pos];
if (tag[1] == "/") {
current_level--;
if (current_level == tag_level[tag_level.length-1]) {
tag_level.pop();
l[pos] = tagspec[3];
}
} else {
if (l[pos].match(tagspec[1])) {
l[pos] = tagspec[2];
tag_level.push(current_level);
}
current_level++;
};
};
output = l.join("");
};
output = l.join("");
output = output.replace("<p>", "", "g");
output = output.replace("</p>", "\\par ", "g");
output = output.replace(/<\/?div[^>]*>/g, "");
@ -258,10 +270,10 @@
html = html.replace(this._rtfMap[needle], needle, "g");
}
}
html = html.replace("\\scaps ", "<span style=\"font-variant:small-caps\">", "g");
html = html.replace("\\scaps0 ", "</span>", "g");
for each (var tagspec in this._rtfRexMap){
html = html.replace(tagspec[2], tagspec[0], "g");
html = html.replace(tagspec[3], "</span>", "g");
}
html = '<div style="'+bodyStyle+'"><p>'+html.replace("\par ", "</p><p>")+"</p></div>";
Zotero.debug("setting content to "+html);
}