Skip to content

Commit

Permalink
Extra unit test
Browse files Browse the repository at this point in the history
Have a test with attributes where text was removed from the main body, and the attributes are still in the xML tree.
#977
  • Loading branch information
teusbenschop committed Dec 31, 2024
1 parent 2ac6e95 commit c491927
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions editor/html2usfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ void Editor_Html2Usfm::close_element_node (const pugi::xml_node& node)
if (!wla_class.empty()) {
const std::string contents = m_word_level_attributes[wla_class];
m_word_level_attributes.erase(wla_class);
// The vertical bar separates the canonical word from the attribute(s) following it.
current_line.append("|");
current_line.append(contents);
if (!contents.empty()) {
// The vertical bar separates the canonical word from the attribute(s) following it.
current_line.append("|");
current_line.append(contents);
}
}
// Add closing USFM, optionally closing embedded tags in reverse order.
character_styles = filter::strings::array_diff (character_styles, classes);
Expand Down
14 changes: 14 additions & 0 deletions unittests/usfm-html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,4 +1783,18 @@ TEST_F (usfm_html, word_level_attributes_linking)
}


TEST_F (usfm_html, word_level_attributes_removed)
{
// This tests a situation where the \w ... is removed from the text body,
// but the word-level attributes themselves are still in the XML tree.
const std::string html = R"(<p class="b-p"><span>A</span><span class="i-w0wla2">B</span></p><p class="b-wordlevelattributes"> </p><p class="b-wla1">C="D"</p>)";
const std::string usfm = R"(\p A\w B\w*)";
Editor_Html2Usfm editor_html2usfm;
editor_html2usfm.load (html);
editor_html2usfm.stylesheet (styles_logic_standard_sheet ());
editor_html2usfm.run ();
EXPECT_EQ (usfm, editor_html2usfm.get());
}


#endif

0 comments on commit c491927

Please sign in to comment.