File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,16 +130,19 @@ std::string Printer::PrinterImpl::printMath(const std::string &math)
130130
131131 XmlDocPtr xmlDoc = std::make_shared<XmlDoc>();
132132 xmlKeepBlanksDefault (0 );
133- // Remove any XML declarations from the string.
133+ // Remove a leading XML declaration from the string, but preserve other processing instructions such as
134+ // <?xml-stylesheet ...?>.
134135 std::string normalisedMath = math;
135136 size_t pos = 0 ;
136137 while ((pos = normalisedMath.find (" <?xml" , pos)) != std::string::npos) {
137- auto end = normalisedMath.find (" ?>" , pos + 5 );
138- if (end != std::string::npos) {
139- normalisedMath.erase (pos, end + 2 - pos);
140- } else {
141- break ;
138+ if ((pos + 5 < normalisedMath.size ()) && std::isspace (static_cast <unsigned char >(normalisedMath[pos + 5 ]))) {
139+ auto end = normalisedMath.find (" ?>" , pos + 5 );
140+ if (end != std::string::npos) {
141+ normalisedMath.erase (pos, end + 2 - pos);
142+ continue ;
143+ }
142144 }
145+ pos += 5 ;
143146 }
144147 xmlDoc->parse (" <" + wrapElementName + " >" + normalisedMath + " </" + wrapElementName + " >" );
145148 if (xmlDoc->xmlErrorCount () == 0 ) {
You can’t perform that action at this time.
0 commit comments