Skip to content

Commit

Permalink
Working towards support for \pro ...\pro*
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Feb 23, 2025
1 parent b2068bd commit 6286a80
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 64 deletions.
2 changes: 2 additions & 0 deletions editor/styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ std::string Editor_Styles::getAction (Webserver_Request& webserver_request, cons
return mono ();
case stylesv2::Type::published_verse_marker:
return character ();
case stylesv2::Type::character_style:
return character ();
case stylesv2::Type::introduction_end:
return mono ();
default:
Expand Down
20 changes: 19 additions & 1 deletion editor/usfm2html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ void Editor_Usfm2Html::process ()
const bool is_embedded_marker = filter::usfm::is_embedded_marker (current_item);
// Clean up the marker, so we remain with the basic version, e.g. 'id'.
const std::string marker = filter::usfm::get_marker (current_item);
std::cout << "marker " << marker << std::endl; // Todo
// Handle preview mode: Strip word-level attributes.
// Likely this can be removed from preview since word-level ttributes get extracted.
if (m_preview)
if (is_opening_marker)
filter::usfm::remove_word_level_attributes (marker, m_markers_and_text, m_markers_and_text_pointer);
if (m_styles.count (marker) && (!stylesv2::marker_moved_to_v2(marker, {""})))
{
std::cout << "v1" << std::endl; // Todo
const database::styles1::Item& style = m_styles.at(marker);
switch (style.type)
{
Expand Down Expand Up @@ -400,6 +402,7 @@ void Editor_Usfm2Html::process ()
}
else if (const stylesv2::Style* style {database::styles2::get_marker_data (m_stylesheet, marker)}; style)
{
std::cout << "v2" << std::endl; // Todo
switch (style->type) {
case stylesv2::Type::starting_boundary:
case stylesv2::Type::none:
Expand Down Expand Up @@ -436,6 +439,21 @@ void Editor_Usfm2Html::process ()
output_as_is (marker, is_opening_marker);
break;
}
case stylesv2::Type::character_style:
{
if (is_opening_marker) {
// Be sure the road ahead is clear.
if (road_is_clear ()) {
open_text_style (style->marker, is_embedded_marker);
extract_word_level_attributes();
} else {
add_text (filter::usfm::get_opening_usfm (marker));
}
} else {
close_text_style (is_embedded_marker);
}
break;
}
case stylesv2::Type::stopping_boundary: // Todo
default:
break;
Expand Down Expand Up @@ -691,7 +709,7 @@ void Editor_Usfm2Html::add_notel_link (pugi::xml_node& dom_node, const int ident


// Returns true if the road ahead is clear for the current marker.
bool Editor_Usfm2Html::road_is_clear ()
bool Editor_Usfm2Html::road_is_clear () // Update this version for v2. Make unit test first on this.
{
// Determine the input.
std::string input_marker {};
Expand Down
32 changes: 31 additions & 1 deletion filter/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
std::string marker = filter::strings::trim (currentItem); // Change, e.g. '\id ' to '\id'.
marker = marker.substr (1); // Remove the initial backslash, e.g. '\id' becomes 'id'.
if (filter::usfm::is_opening_marker (marker)) {
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {"ca"}))) // Todo
if ((styles.find (marker) != styles.end()) && (!stylesv2::marker_moved_to_v2(marker, {""}))) // Todo
{
database::styles1::Item style = styles [marker];
note_citations.evaluate_style(style);
Expand Down Expand Up @@ -344,6 +344,8 @@ void Filter_Text::pre_process_usfm (const std::string& stylesheet)
}
case stylesv2::Type::introduction_end:
break;
case stylesv2::Type::character_style:
break;
case stylesv2::Type::stopping_boundary: // Todo
default:
break;
Expand Down Expand Up @@ -1059,6 +1061,34 @@ void Filter_Text::process_usfm (const std::string& stylesheet)
add_to_info (R"(Introduction end: \)" + marker, false);
break;
}
case stylesv2::Type::character_style: // Todo fix one by one.
{
// Support for a normal and an embedded character style.
if (is_opening_marker) {
// if (odf_text_standard)
// odf_text_standard->open_text_style (style, false, is_embedded_marker);
// if (odf_text_text_only)
// odf_text_text_only->open_text_style (style, false, is_embedded_marker);
// if (odf_text_text_and_note_citations)
// odf_text_text_and_note_citations->open_text_style (style, false, is_embedded_marker);
// if (html_text_standard)
// html_text_standard->open_text_style (style, false, is_embedded_marker);
// if (html_text_linked)
// html_text_linked->open_text_style (style, false, is_embedded_marker);
} else {
// if (odf_text_standard)
// odf_text_standard->close_text_style (false, is_embedded_marker);
// if (odf_text_text_only)
// odf_text_text_only->close_text_style (false, is_embedded_marker);
// if (odf_text_text_and_note_citations)
// odf_text_text_and_note_citations->close_text_style (false, is_embedded_marker);
// if (html_text_standard)
// html_text_standard->close_text_style (false, is_embedded_marker);
// if (html_text_linked)
// html_text_linked->close_text_style (false, is_embedded_marker);
}
break;
}
case stylesv2::Type::stopping_boundary: // Todo v2
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion styles/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ int styles_logic_get_userstring3_function (int type, int subtype)

// It returns true if the combination of type and subtype start a new line in well-formed USFM.
// Otherwise it returns false.
bool styles_logic_starts_new_line_in_usfm (int type, int subtype)
bool styles_logic_starts_new_line_in_usfm (int type, int subtype) // Todo write unit test for this.
{
switch (type) {
case StyleTypeIdentifier :
Expand Down
3 changes: 1 addition & 2 deletions styles/sheetm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ std::string styles_sheetm (Webserver_Request& webserver_request)
const std::string marker_name = translate(item.second);
const stylesv2::Style* stylev2 {database::styles2::get_marker_data (name, marker)};
if (stylev2)
if (stylev2->implemented)
continue;
continue;
pugi::xml_node tr_node = html_block.append_child("tr");
{
pugi::xml_node td_node = tr_node.append_child("td");
Expand Down
73 changes: 18 additions & 55 deletions stylesv2/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ std::string type_enum_to_value (const Type type, const bool describe)
if (describe)
return "introduction end";
return "introduction_end";
case Type::character_style:
if (describe)
return "character style";
return "character_style";
case Type::stopping_boundary:
return "stopping_boundary";
default:
Expand Down Expand Up @@ -228,7 +232,6 @@ std::ostream& operator<<(std::ostream& os, const Style& style)
os << std::get<std::string>(parameter);
os << std::endl;
}
os << "implemented: " << style.implemented << std::endl;
return os;
}

Expand All @@ -253,7 +256,6 @@ const std::list<Style> styles {
.name = "Identification",
.info = "File identification information (name of file, book name, language, last edited, date, etc.)",
.properties = {{Property::starts_new_page,true}},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#index-1",
.category = Category::identification,
},
Expand All @@ -263,7 +265,6 @@ const std::list<Style> styles {
.name = "Encoding",
.info = "File encoding information. Bibledit disregards this marker, as all text in Bibledit is in UTF-8 encoding.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#index-3",
.category = Category::identification,
},
Expand All @@ -273,7 +274,6 @@ const std::list<Style> styles {
.name = "Status",
.info = "Project text status tracking.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#sts",
.category = Category::identification,
},
Expand All @@ -283,7 +283,6 @@ const std::list<Style> styles {
.name = "Remark",
.info = "Comments and remarks.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#rem",
.category = Category::identification,
},
Expand All @@ -293,7 +292,6 @@ const std::list<Style> styles {
.name = "Running header",
.info = "Running header text for a book.",
.properties = {{Property::on_left_page,true},{Property::on_right_page,true}},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#h",
.category = Category::identification,
},
Expand All @@ -307,7 +305,6 @@ const std::list<Style> styles {
{Property::on_right_page,true},
{Property::deprecated,std::monostate()}
},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#h",
.category = Category::identification,
},
Expand All @@ -321,7 +318,6 @@ const std::list<Style> styles {
{Property::on_right_page,false},
{Property::deprecated,std::monostate()}
},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#h",
.category = Category::identification,
},
Expand All @@ -335,7 +331,6 @@ const std::list<Style> styles {
{Property::on_right_page,true},
{Property::deprecated,std::monostate()}
},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#h",
.category = Category::identification,
},
Expand All @@ -345,7 +340,6 @@ const std::list<Style> styles {
.name = "Long TOC text",
.info = "Long table of contents text.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#toc",
.category = Category::identification,
},
Expand All @@ -355,7 +349,6 @@ const std::list<Style> styles {
.name = "Short TOC text",
.info = "Short table of contents text.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#toc",
.category = Category::identification,
},
Expand All @@ -365,7 +358,6 @@ const std::list<Style> styles {
.name = "Book abbreviation",
.info = "Book abbreviation for the table of contents.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/identification/index.html#toc",
.category = Category::identification,
},
Expand All @@ -375,7 +367,6 @@ const std::list<Style> styles {
.name = "Introduction end",
.info = "Optionally included to explicitly indicate the end of the introduction material.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/introductions/index.html#ie",
.category = Category::introductions,
},
Expand All @@ -385,7 +376,6 @@ const std::list<Style> styles {
.name = "Chapter label",
.info = "Chapter label used for translations that add a word such as 'Chapter' before chapter numbers, e.g. Psalms.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#cl",
.category = Category::chapters_verses,
},
Expand All @@ -395,7 +385,6 @@ const std::list<Style> styles {
.name = "Published chapter character",
.info = "Published chapter number. This is a chapter marking that would be used in the published text.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#cp",
.category = Category::chapters_verses,
},
Expand All @@ -405,7 +394,6 @@ const std::list<Style> styles {
.name = "Alternate chapter number",
.info = "Second or alternate chapter number. For coding dual versification. Useful for places where different traditions of chapter breaks need to be supported in the same translation.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#ca-ca",
.category = Category::chapters_verses,
},
Expand All @@ -415,10 +403,18 @@ const std::list<Style> styles {
.name = "Published verse marker",
.info = "Published verse marker. This is a verse marking that would be used in the published text.",
.properties = {},
.implemented = true,
.doc = "https://ubsicap.github.io/usfm/chapters_verses/index.html#vp-vp",
.category = Category::chapters_verses,
},
{
.marker = "pro",
.type = Type::character_style,
.name = "Pronunciation annotation",
.info = "For indicating pronunciation in CJK texts.",
.properties = {{Property::deprecated,std::monostate()}},
.doc = "https://ubsicap.github.io/usfm/characters/index.html?highlight=pronunciation#pro-pro",
.category = Category::words_characters,
},



Expand Down Expand Up @@ -4298,39 +4294,6 @@ const std::list<Style> styles {
// /* backgroundcolor */ "#FFFFFF",
// },
// {
// /* marker */ "pro",
// /* name */ "Pronunciation annotation",
// /* info */ "For indicating pronunciation in CJK texts. Deprecated.",
// /* category */ "sf",
// /* type */ 0,
// /* subtype */ 9,
// /* fontsize */ 10,
// /* italic */ 0,
// /* bold */ 0,
// /* underline */ 0,
// /* smallcaps */ 0,
// /* superscript */ 0,
// /* justification */ 0,
// /* spacebefore */ 0,
// /* spaceafter */ 0,
// /* leftmargin */ 0,
// /* rightmargin */ 0,
// /* firstlineindent */ 0,
// /* spancolumns */ 0,
// /* color */ "#000000",
// /* print */ 1,
// /* userbool1 */ 0,
// /* userbool2 */ 0,
// /* userbool3 */ 0,
// /* userint1 */ 0,
// /* userint2 */ 0,
// /* userint3 */ 0,
// /* userstring1 */ "",
// /* userstring2 */ "",
// /* userstring3 */ "",
// /* backgroundcolor */ "#FFFFFF",
// },
// {
// /* marker */ "q",
// /* name */ "Poetic line",
// /* info */ "Poetry text, level 1 indent, if single level.",
Expand Down Expand Up @@ -6732,10 +6695,8 @@ bool marker_moved_to_v2 (const std::string& marker, const std::vector<const char
}
const auto iter = std::find(styles.cbegin(), styles.cend(), marker);
if (iter != styles.cend()) {
if (iter->implemented) {
cache[key] = true;
return true;
}
cache[key] = true;
return true;
}
for (const auto bit : extra) {
if (marker == bit) {
Expand All @@ -6749,7 +6710,7 @@ bool marker_moved_to_v2 (const std::string& marker, const std::vector<const char


// Whether this style starta a new line in USFM.
bool starts_new_line_in_usfm (const Style* style)
bool starts_new_line_in_usfm (const Style* style) // Todo write unit test for this too.
{
switch (style->type) {
case stylesv2::Type::starting_boundary:
Expand All @@ -6767,6 +6728,8 @@ bool starts_new_line_in_usfm (const Style* style)
return true;
case stylesv2::Type::published_verse_marker:
return false;
case stylesv2::Type::character_style:
return false;
case stylesv2::Type::stopping_boundary: // Todo
default:
return true;
Expand Down
3 changes: 1 addition & 2 deletions stylesv2/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class Type : int {
alternate_chapter_number,
published_verse_marker,
introduction_end,
character_style,
stopping_boundary // Should be the last always.
};

Expand Down Expand Up @@ -110,8 +111,6 @@ struct Style final {
std::string info {};
// The parameters indicate the enabled capabilities beyond the capabilities implied in the style type.
std::map<Property,Parameter> properties{};
// Whether this style has been implemented throughout the code.
bool implemented {false};
std::string doc {};
Category category {};
};
Expand Down
3 changes: 1 addition & 2 deletions unittests/styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ TEST_F (styles, editors_application)
{ "pn", "c"},
{ "png", "c"},
{ "po", "p"},
{ "pro", "m"},
{ "pro", "c"},
{ "q", "p"},
{ "q1", "p"},
{ "q2", "p"},
Expand Down Expand Up @@ -736,7 +736,6 @@ TEST_F (styles, save_load_styles_v2)
{
auto loaded_style = load_style(sheet, style.marker);
EXPECT_TRUE(loaded_style);
loaded_style.value().implemented = true;
std::stringstream ss1{};
ss1 << style;
std::stringstream ss2{};
Expand Down
Loading

0 comments on commit 6286a80

Please sign in to comment.