diff options
-rw-r--r-- | include/svtools/HtmlWriter.hxx | 4 | ||||
-rw-r--r-- | svtools/qa/unit/testHtmlWriter.cxx | 16 | ||||
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 12 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.hxx | 2 |
7 files changed, 47 insertions, 13 deletions
diff --git a/include/svtools/HtmlWriter.hxx b/include/svtools/HtmlWriter.hxx index 67172fd6863a..a842df4870a9 100644 --- a/include/svtools/HtmlWriter.hxx +++ b/include/svtools/HtmlWriter.hxx @@ -28,9 +28,11 @@ private: bool mbElementOpen; bool mbContentWritten; bool mbPrettyPrint; + /// XML namespace, in case of XHTML. + OString maNamespace; public: - HtmlWriter(SvStream& rStream); + HtmlWriter(SvStream& rStream, const OString& rNamespace = OString()); ~HtmlWriter(); void prettyPrint(bool b); 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"); diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 2f2e1805b8dc..ed2d017e6914 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -753,7 +753,7 @@ void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, // if necessary, start a new list item if( rInfo.bInNumBulList && bNumbered ) { - HtmlWriter html(rWrt.Strm()); + HtmlWriter html(rWrt.Strm(), rHWrt.maNamespace); html.start(OOO_STRING_SVTOOLS_HTML_li); if( USHRT_MAX != nNumStart ) html.attribute(OOO_STRING_SVTOOLS_HTML_O_value, OString::number(nNumStart)); @@ -2017,7 +2017,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) rHTMLWrt.m_bLFPossible = true; - HtmlWriter aHtml(rWrt.Strm()); + HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace); aHtml.start(OOO_STRING_SVTOOLS_HTML_horzrule); const SfxItemSet* pItemSet = pNd->GetpSwAttrSet(); @@ -2461,7 +2461,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) if( 0x0a == c ) { HTMLOutFuncs::FlushToAscii( rWrt.Strm(), aContext ); - HtmlWriter aHtml(rWrt.Strm()); + HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace); aHtml.single(OOO_STRING_SVTOOLS_HTML_linebreak); } else if (c == CH_TXT_ATR_FORMELEMENT) @@ -2511,7 +2511,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) } else { - HtmlWriter aHtml(rHTMLWrt.Strm()); + HtmlWriter aHtml(rHTMLWrt.Strm(), rHTMLWrt.maNamespace); aHtml.single(OOO_STRING_SVTOOLS_HTML_linebreak); const SvxULSpaceItem& rULSpace = pNd->GetSwAttrSet().Get(RES_UL_SPACE); if (rULSpace.GetLower() > 0 && @@ -2539,7 +2539,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) pString = OOO_STRING_SVTOOLS_HTML_AL_right; } - HtmlWriter aHtml(rHTMLWrt.Strm()); + HtmlWriter aHtml(rHTMLWrt.Strm(), rHTMLWrt.maNamespace); aHtml.start(OOO_STRING_SVTOOLS_HTML_linebreak); aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_clear, pString); aHtml.end(); diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 0924ad6d6555..4c0decd45437 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1230,7 +1230,7 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat, if( rHTMLWrt.m_bLFPossible ) rHTMLWrt.OutNewLine( true ); - HtmlWriter aHtml(rWrt.Strm()); + HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace); // <a name=...></a>...<img ...> if( pMarkType && !rFrameFormat.GetName().isEmpty() ) diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 717365e535de..3831cee4fbc2 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -183,8 +183,16 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium) { mbEmbedImages = true; } - else if (sFilterOptions == "XHTML") - mbXHTML = true; + + uno::Sequence<OUString> aOptionSeq = comphelper::string::convertCommaSeparated(sFilterOptions); + const OUString aXhtmlNsKey("xhtmlns="); + for (const auto& rOption : aOptionSeq) + { + if (rOption == "XHTML") + mbXHTML = true; + else if (rOption.startsWith(aXhtmlNsKey)) + maNamespace = rOption.copy(aXhtmlNsKey.getLength()).toUtf8(); + } } ErrCode SwHTMLWriter::WriteStream() diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 8a14d96db7d7..488f7eed5a5b 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -386,6 +386,8 @@ public: bool mbEmbedImages : 1; /// If XHTML markup should be written instead of HTML. bool mbXHTML = false; + /// XML namespace, in case of XHTML. + OString maNamespace; #define sCSS2_P_CLASS_leaders "leaders" bool m_bCfgPrintLayout : 1; // PrintLayout option for TOC dot leaders |