diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-27 13:51:13 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-02-28 11:41:50 +0100 |
commit | 9df0ce081eac287154ea496e9eb299b4bc4fa776 (patch) | |
tree | 662ab6bae70678e9a5d9a760e37b6c0bf21966a5 /svtools | |
parent | 81260c448911069ce8cb051d3a973ec52b9b43a3 (diff) |
sw HTML export: allow custom XHTML namespace alias
This helps in case the HTML filter expected to produce an XHTML fragment that
has an explicit namespace alias for <http://www.w3.org/1999/xhtml>.
This only has an effect when HtmlWriter is used to write elements,
though.
Change-Id: I161caf4bb6bc6d0c21a7a67433b08bb060b447f1
Reviewed-on: https://gerrit.libreoffice.org/50448
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/qa/unit/testHtmlWriter.cxx | 16 | ||||
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 14 |
2 files changed, 26 insertions, 4 deletions
diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx index dc0816b7875d..bdb5c5814fd7 100644 --- a/svtools/qa/unit/testHtmlWriter.cxx +++ b/svtools/qa/unit/testHtmlWriter.cxx @@ -39,6 +39,7 @@ public: void testSingleElementWithContent(); void testSingleElementWithContentAndAttributes(); void testNested(); + void testNamespace(); void testAttributeValues(); CPPUNIT_TEST_SUITE(Test); @@ -47,6 +48,7 @@ public: CPPUNIT_TEST(testSingleElementWithContent); CPPUNIT_TEST(testSingleElementWithContentAndAttributes); CPPUNIT_TEST(testNested); + CPPUNIT_TEST(testNamespace); CPPUNIT_TEST(testAttributeValues); CPPUNIT_TEST_SUITE_END(); @@ -157,6 +159,20 @@ void Test::testNested() CPPUNIT_ASSERT_EQUAL(OString("<abc><xyz/></abc>"), aString); } +void Test::testNamespace() +{ + SvMemoryStream aStream; + + HtmlWriter aHtml(aStream, "reqif-xhtml"); + aHtml.prettyPrint(false); + aHtml.single("br"); + + OString aString = extractFromStream(aStream); + + // This was <br/>, namespace request was ignored. + CPPUNIT_ASSERT_EQUAL(OString("<reqif-xhtml:br/>"), aString); +} + void Test::testAttributeValues() { SvMemoryStream aStream; diff --git a/svtools/source/svhtml/HtmlWriter.cxx b/svtools/source/svhtml/HtmlWriter.cxx index befadafbea3e..499aa7ed8ab0 100644 --- a/svtools/source/svhtml/HtmlWriter.cxx +++ b/svtools/source/svhtml/HtmlWriter.cxx @@ -11,12 +11,18 @@ #include <svtools/HtmlWriter.hxx> #include <tools/stream.hxx> -HtmlWriter::HtmlWriter(SvStream& rStream) : +HtmlWriter::HtmlWriter(SvStream& rStream, const OString& rNamespace) : mrStream(rStream), mbElementOpen(false), mbContentWritten(false), mbPrettyPrint(true) -{} +{ + if (!rNamespace.isEmpty()) + { + // Convert namespace alias to a prefix. + maNamespace = rNamespace + ":"; + } +} HtmlWriter::~HtmlWriter() {} @@ -46,7 +52,7 @@ void HtmlWriter::start(const OString& aElement) } mrStream.WriteChar('<'); - mrStream.WriteOString(aElement); + mrStream.WriteOString(maNamespace + aElement); mbElementOpen = true; } @@ -93,7 +99,7 @@ void HtmlWriter::end() } } mrStream.WriteCharPtr("</"); - mrStream.WriteOString(maElementStack.back()); + mrStream.WriteOString(maNamespace + maElementStack.back()); mrStream.WriteCharPtr(">"); if (mbPrettyPrint) mrStream.WriteCharPtr("\n"); |