summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/XML.cpp31
-rw-r--r--src/plugins/html/DemoOutput.cpp40
-rw-r--r--test/plugins/html/DemoOutputTest.cpp4
3 files changed, 37 insertions, 38 deletions
diff --git a/src/core/XML.cpp b/src/core/XML.cpp
index a610daa..9c23e3b 100644
--- a/src/core/XML.cpp
+++ b/src/core/XML.cpp
@@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+
#include <core/common/Rtti.hpp>
#include "XML.hpp"
@@ -71,6 +73,33 @@ void Element::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
}
}
+static std::string escapePredefinedEntities(const std::string &input)
+{
+ std::stringstream ss;
+ for (const char &c : input) {
+ switch (c) {
+ case '<':
+ ss << "&lt;";
+ break;
+ case '>':
+ ss << "&gt;";
+ break;
+ case '&':
+ ss << "&amp;";
+ break;
+ case '\'':
+ ss << "&apos;";
+ break;
+ case '\"':
+ ss << "&quot;";
+ break;
+ default:
+ ss << c;
+ }
+ }
+ return std::move(ss.str());
+}
+
void Text::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
{
if (pretty) {
@@ -78,7 +107,7 @@ void Text::doSerialize(std::ostream &out, unsigned int tabdepth, bool pretty)
out << '\t';
}
}
- out << text;
+ out << escapePredefinedEntities(text);
if (pretty) {
out << '\n';
}
diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp
index 7dc1660..b94b397 100644
--- a/src/plugins/html/DemoOutput.cpp
+++ b/src/plugins/html/DemoOutput.cpp
@@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <sstream>
#include <stack>
#include <core/common/Exceptions.hpp>
@@ -110,9 +109,9 @@ Rooted<xml::Element> DemoHTMLTransformer::transformSection(
// if the input node is no section, we ignore it.
return {nullptr};
}
- // create a div tag containing the sections content.
+ // create a section tag containing the sections content.
Rooted<xml::Element> sec{
- new xml::Element{mgr, parent, "div", {{"class", secclass}}}};
+ new xml::Element{mgr, parent, "section", {{"class", secclass}}}};
// check if we have a heading.
if (section->hasField("heading") &&
section->getField("heading").size() > 0) {
@@ -226,33 +225,6 @@ static Rooted<xml::Element> openAnnotation(
return tmp;
}
-static std::string escapePredefinedEntities(const std::string &input)
-{
- std::stringstream ss;
- for (const char &c : input) {
- switch (c) {
- case '<':
- ss << "&lt;";
- break;
- case '>':
- ss << "&gt;";
- break;
- case '&':
- ss << "&amp;";
- break;
- case '\'':
- ss << "&apos;";
- break;
- case '\"':
- ss << "&quot;";
- break;
- default:
- ss << c;
- }
- }
- return std::move(ss.str());
-}
-
Rooted<xml::Element> DemoHTMLTransformer::transformParagraph(
Handle<xml::Element> parent, Handle<model::StructuredEntity> par,
AnnoMap &startMap, AnnoMap &endMap)
@@ -339,7 +311,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph(
continue;
}
// if this is not an anchor, we can only handle text.
- if(!n->isa(RttiTypes::StructuredEntity)){
+ if (!n->isa(RttiTypes::StructuredEntity)) {
continue;
}
Handle<model::StructuredEntity> t = n.cast<model::StructuredEntity>();
@@ -351,10 +323,8 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph(
if (primitive.isNull()) {
throw OusiaException("Text field is not primitive!");
}
- // here we need to do some escaping with the string content.
- std::string escaped =
- escapePredefinedEntities(primitive->getContent().asString());
- current->addChild(new xml::Text(mgr, current, escaped));
+ current->addChild(new xml::Text(
+ mgr, current, primitive->getContent().asString()));
}
}
return p;
diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp
index c878ba7..d18a314 100644
--- a/test/plugins/html/DemoOutputTest.cpp
+++ b/test/plugins/html/DemoOutputTest.cpp
@@ -56,7 +56,7 @@ TEST(DemoHTMLTransformer, writeHTML)
#ifdef MANAGER_GRAPHVIZ_EXPORT
// dump the manager state
- mgr.exportGraphviz("bookDocument.dot");
+// mgr.exportGraphviz("bookDocument.dot");
#endif
// we can only do a rough check here.
@@ -114,7 +114,7 @@ TEST(DemoHTMLTransformer, AnnotationProcessing)
#ifdef MANAGER_GRAPHVIZ_EXPORT
// dump the manager state
- mgr.exportGraphviz("annotationDocument.dot");
+// mgr.exportGraphviz("annotationDocument.dot");
#endif