Use symbols file to lookup entities for delimiters. Fixes bug #8280.

Based upon work by Josh Hieronymus.
This commit is contained in:
Richard Heck 2016-06-29 22:39:42 -04:00
parent 8ea3d1f130
commit 04b8f5cdc4
4 changed files with 41 additions and 87 deletions

View File

@ -107,48 +107,9 @@ void InsetMathBig::normalize(NormalStream & os) const
void InsetMathBig::mathmlize(MathStream & os) const void InsetMathBig::mathmlize(MathStream & os) const
{ {
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"; os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
if (delim_ == "(" || delim_ == ")" << convertDelimToXMLEscape(delim_)
|| delim_ == "[" || delim_ == "]" << "</mo>";
|| delim_ == "|" || delim_ == "/")
os << delim_;
else if (delim_ == "\\{" || delim_ == "\\lbrace")
os << "{";
else if (delim_ == "\\}" || delim_ == "\\rbrace")
os << "}";
else if (delim_ == "\\slash")
os << "/";
else if (delim_ == "\\|" || delim_ == "\\vert")
os << "|";
else if (delim_ == "\\Vert")
os << "&par;";
else if (delim_ == "\\\\" || delim_ == "\\backslash")
os <<" \\";
else if (delim_ == "\\langle")
os << "&lt;";
else if (delim_ == "\\rangle")
os << "&gt;";
else if (delim_ == "\\lceil")
os << "&lceil;";
else if (delim_ == "\\rceil")
os << "&rceil;";
else if (delim_ == "\\lfloor")
os << "&lfloor;";
else if (delim_ == "\\rfloor")
os << "&rfloor;";
else if (delim_ == "\\downarrow")
os << "&darr;";
else if (delim_ == "\\uparrow")
os << "&uarr;";
else if (delim_ == "\\Downarrow")
os << "&dArr;";
else if (delim_ == "\\Uparrow")
os << "&uArr;";
else if (delim_ == "\\updownarrow")
os << "&varr;";
else if (delim_ == "\\Updownarrow")
os << "&vArr;";
os << "</mo>";
} }
@ -161,48 +122,9 @@ void InsetMathBig::htmlize(HtmlStream & os) const
case 4: case 5: name = "biggg"; break; case 4: case 5: name = "biggg"; break;
default: name = "big"; break; default: name = "big"; break;
} }
os << MTag("span", "class='" + name + "symbol'"); os << MTag("span", "class='" + name + "symbol'")
if (delim_ == "(" || delim_ == ")" << convertDelimToXMLEscape(delim_)
|| delim_ == "[" || delim_ == "]" << ETag("span");
|| delim_ == "|" || delim_ == "/")
os << delim_;
else if (delim_ == "\\{" || delim_ == "\\lbrace")
os << "{";
else if (delim_ == "\\}" || delim_ == "\\rbrace")
os << "}";
else if (delim_ == "\\slash")
os << "/";
else if (delim_ == "\\|" || delim_ == "\\vert")
os << "|";
else if (delim_ == "\\Vert")
os << "&par;";
else if (delim_ == "\\\\" || delim_ == "\\backslash")
os <<" \\";
else if (delim_ == "\\langle")
os << "&lt;";
else if (delim_ == "\\rangle")
os << "&gt;";
else if (delim_ == "\\lceil")
os << "&lceil;";
else if (delim_ == "\\rceil")
os << "&rceil;";
else if (delim_ == "\\lfloor")
os << "&lfloor;";
else if (delim_ == "\\rfloor")
os << "&rfloor;";
else if (delim_ == "\\downarrow")
os << "&darr;";
else if (delim_ == "\\uparrow")
os << "&uarr;";
else if (delim_ == "\\Downarrow")
os << "&dArr;";
else if (delim_ == "\\Uparrow")
os << "&uArr;";
else if (delim_ == "\\updownarrow")
os << "&varr;";
else if (delim_ == "\\Updownarrow")
os << "&vArr;";
os << ETag("span");
} }

View File

@ -193,14 +193,21 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const
void InsetMathDelim::mathmlize(MathStream & os) const void InsetMathDelim::mathmlize(MathStream & os) const
{ {
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>" << left_ << "</mo>" os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< cell(0) << "<mo form='postfix' fence='true' stretchy='true' symmetric='true'>" << right_ << "</mo>"; << convertDelimToXMLEscape(left_)
<< "</mo>\n"
<< cell(0)
<< "\n<mo form='postfix' fence='true' stretchy='true' symmetric='true'>"
<< convertDelimToXMLEscape(right_)
<< "</mo>\n";
} }
void InsetMathDelim::htmlize(HtmlStream & os) const void InsetMathDelim::htmlize(HtmlStream & os) const
{ {
os << left_ << cell(0) << right_; os << convertDelimToXMLEscape(left_)
<< cell(0)
<< convertDelimToXMLEscape(right_);
} }

View File

@ -12,6 +12,7 @@
#include "MathStream.h" #include "MathStream.h"
#include "MathFactory.h"
#include "MathData.h" #include "MathData.h"
#include "MathExtern.h" #include "MathExtern.h"
@ -694,4 +695,25 @@ OctaveStream & operator<<(OctaveStream & os, string const & s)
} }
docstring convertDelimToXMLEscape(docstring const & name)
{
if (name.size() == 1) {
char_type const c = name[0];
if (c == '<')
return from_ascii("&lt;");
else if (c == '>')
return from_ascii("&gt;");
else
return name;
}
MathWordList const & words = mathedWordList();
MathWordList::const_iterator it = words.find(name);
if (it != words.end()) {
docstring const escape = it->second.xmlname;
return escape;
}
LYXERR0("Unable to find `" << name <<"' in the mathWordList.");
return name;
}
} // namespace lyx } // namespace lyx

View File

@ -584,6 +584,9 @@ OctaveStream & operator<<(OctaveStream &, char);
/// ///
OctaveStream & operator<<(OctaveStream &, int); OctaveStream & operator<<(OctaveStream &, int);
docstring convertDelimToXMLEscape(docstring const & name);
} // namespace lyx } // namespace lyx
#endif #endif