summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-10-23 19:52:14 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2023-10-23 22:10:06 +0200
commit926826e40955175a8c115472e0d2f6c7f2f1a453 (patch)
treeba914ce7dcb96fa5f8ddb36a1b40e8d5bc1bb805 /sw/qa
parentbae0736bf0ec54828766c3d903e2a27458643395 (diff)
Implement PreserveSpaces boolean HTML/ReqIF export filter option
This option changes how HTML/ReqIF export handles paragraphs with leading/trailing spaces, or multiple sequential spaces. Normally export may insert newlines every ~256 characters, in place of normal space characters; this relies on default processing of spaces, where leading/trailing spaces are trimmed, and runs of spaces are reduced to a single space. When PreserveSpaces is true, HTML/ReqIF export takes care to not alter spaces inside paragraphs. For that, it checks if paragraphs contain sequences of spaces that normally would be reduced; and for those paragraphs, it adds "white-space: pre-wrap" to style (in HTML), or 'xml::space="preserve"' attribute (in ReqIF). Import of 'xml::space' attribute and "white-space: pre-wrap" style is implemented; when paragraph has these, it keeps the spaces read from HTML/ReqIF intact. Import does not currently support this attribute/style in elements other than 'p'. Change-Id: I62dba5eaf313b965bf37d8fa5e3f5bbb8f5e8357 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158362 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index be3c67fb0bba..a106dd53bf14 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2762,6 +2762,67 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf157643_WideHBorder)
assertXPath(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr", 2);
}
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_PreserveSpaces)
+{
+ // Given a document with leading, trailing, and repeating intermediate spaces:
+ createSwDoc();
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ constexpr OUString paraText = u"\t test \t more text \t"_ustr;
+ pWrtShell->Insert(paraText);
+
+ // When exporting to plain HTML, using PreserveSpaces:
+ saveWithParams({
+ comphelper::makePropertyValue("FilterName", u"HTML (StarWriter)"_ustr),
+ comphelper::makePropertyValue("PreserveSpaces", true),
+ });
+
+ // Then make sure that "white-space: pre-wrap" is written into the paragraph's style:
+ htmlDocUniquePtr pHtmlDoc = parseHtml(maTempFile);
+ CPPUNIT_ASSERT(pHtmlDoc);
+ const OUString style = getXPath(pHtmlDoc, "/html/body/p", "style"_ostr);
+ CPPUNIT_ASSERT(style.indexOf("white-space: pre-wrap") >= 0);
+ // Also check that the paragraph text is correct, without modifications in whitespace
+ assertXPathContent(pHtmlDoc, "/html/body/p", paraText);
+
+ // Test import
+
+ setImportFilterName("HTML (StarWriter)");
+ load(maTempFile.GetURL());
+ CPPUNIT_ASSERT_EQUAL(paraText, getParagraph(1)->getString());
+}
+
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_PreserveSpaces)
+{
+ // Given a document with leading, trailing, and repeating intermediate spaces:
+ createSwDoc();
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ constexpr OUString paraText = u"\t test \t more text \t"_ustr;
+ pWrtShell->Insert(paraText);
+
+ // When exporting to ReqIF, using PreserveSpaces:
+ saveWithParams({
+ comphelper::makePropertyValue("FilterName", u"HTML (StarWriter)"_ustr),
+ comphelper::makePropertyValue("FilterOptions", u"xhtmlns=reqif-xhtml"_ustr),
+ comphelper::makePropertyValue("PreserveSpaces", true),
+ });
+
+ // Then make sure that xml:space="preserve" attribute exists in the paragraph element:
+ xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile();
+ assertXPath(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "space"_ostr,
+ u"preserve"_ustr);
+ // Also check that the paragraph text is correct, without modifications in whitespace
+ assertXPathContent(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", paraText);
+
+ // Test import
+
+ setImportFilterOptions("xhtmlns=reqif-xhtml");
+ setImportFilterName("HTML (StarWriter)");
+ load(maTempFile.GetURL());
+ CPPUNIT_ASSERT_EQUAL(paraText, getParagraph(1)->getString());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */