sw/qa/extras/htmlexport/htmlexport.cxx | 5 ++--- sw/source/filter/html/wrthtml.cxx | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-)
New commits: commit 4e6327c673075ab4a44f497a06a8dbf759c1a72a Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Jul 26 13:47:54 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jul 26 18:04:54 2022 +0200 sw reqif-xhtml export: fix duplicated bookmark names in fragments The problem was that exporting multiple documents to reqif fragments and then combining them to a single document resulted in non-unique bookmark identifiers, even if they were unique in the original source documents. Writer already tries to ensure unique bookmark names, but if the export result is not a full document on its own, this is not enough. On the other hand, bookmarks in these fragments are almost always used unintentionally. Fix the problem by keeping the bookmark output in the HTML/XHTML case, but disable it for ReqIF. Note that we disable unique anchors in general, so this fixes the same problem with section anchors as well. Change-Id: Ib47d1589fa08d205b7904e21656c937bfbca0a2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137464 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 5e5af5e70a17..ac613142c639 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -679,9 +679,8 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml") // This was "<font>" instead of CSS + namespace prefix was missing. CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"color: #ce181e\"") != -1); - // This was '<a name="Bookmark 1"': missing namespace prefix, wrong - // attribute name, wrong attribute value. - CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:a id=\"Bookmark_1\"></reqif-xhtml:a>") != -1); + // This was '<reqif-xhtml:a id="...">': non-unique bookmark name in reqif fragment. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aStream.indexOf("<reqif-xhtml:a id=")); } DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml") diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index a438503f367e..61c2939227d2 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -1197,6 +1197,14 @@ const SwPageDesc *SwHTMLWriter::MakeHeader( sal_uInt16 &rHeaderAttrs ) void SwHTMLWriter::OutAnchor( const OUString& rName ) { + if (mbReqIF) + { + // <a id=".."> has to be unique inside the whole document, but + // we only write a fragment, so we can't ensure the ID is indeed + // unique. Just don't write anchors in the ReqIF case. + return; + } + OStringBuffer sOut; sOut.append("<" + GetNamespace() + OOO_STRING_SVTOOLS_HTML_anchor " "); if (!mbXHTML)