--- loncom/interface/lonhtmlcommon.pm 2015/03/31 13:46:01 1.359
+++ loncom/interface/lonhtmlcommon.pm 2015/04/01 16:14:46 1.360
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.359 2015/03/31 13:46:01 damieng Exp $
+# $Id: lonhtmlcommon.pm,v 1.360 2015/04/01 16:14:46 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1308,6 +1308,7 @@ sub htmlareaselectactive {
function startRichEditor(id) {
// fix character entities inside
// NOTE: this is not fixing characters inside
+ // NOTE: < and > inside should fix automatically because there should not be a letter after <.
var ta = document.getElementById(id);
var value = ta.value;
var in_m = false; // in the m element
@@ -1351,36 +1352,41 @@ sub htmlareaselectactive {
function destroyRichEditor(id) {
CKEDITOR.instances[id].destroy();
- // replace character entities < and > in
+ // replace character entities < and > in and
// and "&fctname(" by "&fctname("
// and the quotes inside functions: "&fct(1, "a")" -> "&fct(1, "a")"
var ta = document.getElementById(id);
var value = ta.value;
- var in_m = false; // in the m element
- var in_text = false; // in the text inside the m element
- var im = -1; // position of
+ var in_element = false; // in the m or chem element
+ var tagname = ""; // m or chem
+ var in_text = false; // in the text inside the element
+ var im = -1; // position of start tag
var it = -1; // position of the text inside
for (var i=0; i if found twice
- in_m = true;
+ if (value.substr(i, 2) == "") {
in_text = true;
it = i+1;
}
- } else if (value.substr(i, 4) == "") {
- in_m = false;
+ } else if (value.substr(i, 3+tagname.length) == ""+tagname+">") {
+ in_element = false;
var text = value.substr(it, i-it);
var l1 = text.length;
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
var l2 = text.length;
- value = value.substr(0, it) + text + "" + value.substr(i+4);
+ value = value.substr(0, it) + text + value.substr(i);
i = i + (l2-l1);
}
}