From 3bdd7a72a21a232740935c49a11d82e4bd8eab03 Mon Sep 17 00:00:00 2001 From: butterkeks Date: Sat, 15 Jun 2024 09:36:49 +0200 Subject: [PATCH] Use correct list style for nested lists --- src/yomichan_parser.c | 6 ++++-- tests/files/dictionary_entries/10_entry | 1 + tests/files/dictionary_entries/10_expected | 11 +++++++++++ tests/files/dictionary_entries/3_expected | 4 ++-- tests/yomichan_parser_tests.c | 9 +++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 tests/files/dictionary_entries/10_entry create mode 100644 tests/files/dictionary_entries/10_expected diff --git a/src/yomichan_parser.c b/src/yomichan_parser.c index 356f861..bd4d2f1 100644 --- a/src/yomichan_parser.c +++ b/src/yomichan_parser.c @@ -94,6 +94,7 @@ static void append_structured_content(yyjson_val *obj, stringbuilder_s sb[static enum tag_type tag = TAG_UNKNOWN; yyjson_val *content = NULL; + bool listStyleType_read = false; size_t idx, max; yyjson_val *key, *val; @@ -110,8 +111,8 @@ static void append_structured_content(yyjson_val *obj, stringbuilder_s sb[static tag = TAG_UL; listdepth++; - if (!liststyle.len) - liststyle = S("•"); // default value + if (!listStyleType_read) + liststyle = S("▪"); // default value } else if (s8equals(s8val, S("ol"))) { tag = TAG_OL; listdepth++; @@ -129,6 +130,7 @@ static void append_structured_content(yyjson_val *obj, stringbuilder_s sb[static yyjson_obj_foreach(val, idx2, max2, key2, val2) { if (yyjson_is_str(key2) && s8equals(yyjson_get_s8(key2), S("listStyleType"))) { liststyle = parse_liststyletype(yyjson_get_s8(val2)); + listStyleType_read = true; } } } else diff --git a/tests/files/dictionary_entries/10_entry b/tests/files/dictionary_entries/10_entry new file mode 100644 index 0000000..4102f71 --- /dev/null +++ b/tests/files/dictionary_entries/10_entry @@ -0,0 +1 @@ +[["洗礼", "せんれい", "⭐", "", 200, [{"type": "structured-content", "content": {"tag": "div", "content": [{"tag": "span", "style": {"verticalAlign": "text-bottom", "marginRight": 0.25}, "data": {"code": "n"}, "content": {"tag": "img", "height": 1.2, "width": 2.67, "sizeUnits": "em", "appearance": "auto", "title": "noun (common) (futsuumeishi)", "collapsible": false, "collapsed": false, "background": false, "path": "jitendex/noun.svg"}}, {"tag": "ol", "content": [{"tag": "li", "style": {"listStyleType": "\"① \""}, "data": {"sense-number": "1"}, "content": [{"tag": "span", "style": {"verticalAlign": "text-bottom", "marginRight": 0.25}, "data": {"code": "Christn"}, "content": {"tag": "img", "height": 1.2, "width": 4.58, "sizeUnits": "em", "appearance": "auto", "title": "Christianity", "collapsible": false, "collapsed": false, "background": false, "path": "jitendex/Christian.svg"}}, {"tag": "ul", "data": {"content": "glossary"}, "content": [{"tag": "li", "content": "baptism"}, {"tag": "li", "content": "christening"}]}, {"tag": "ul", "style": {"marginBottom": 0.5}, "content": [{"tag": "li", "lang": "ja", "style": {"fontSize": "120%", "listStyleType": "circle"}, "data": {"content": "example-sentence-a"}, "content": [{"tag": "ruby", "content": ["彼", {"tag": "rt", "content": "かれ"}]}, "は", {"tag": "span", "style": {"textDecorationLine": "underline"}, "content": [{"tag": "ruby", "content": ["洗", {"tag": "rt", "content": "せん"}]}, {"tag": "ruby", "content": ["礼", {"tag": "rt", "content": "れい"}]}]}, "を", {"tag": "ruby", "content": ["受", {"tag": "rt", "content": "う"}]}, "けてカトリック", {"tag": "ruby", "content": ["教", {"tag": "rt", "content": "きょう"}]}, {"tag": "ruby", "content": ["徒", {"tag": "rt", "content": "と"}]}, "となった。"]}, {"tag": "li", "lang": "en", "style": {"fontSize": "70%", "listStyleType": "none"}, "data": {"content": "example-sentence-b"}, "content": "He was baptized a Catholic."}]}]}, {"tag": "li", "style": {"listStyleType": "\"② \""}, "data": {"sense-number": "2"}, "content": {"tag": "ul", "data": {"content": "glossary"}, "content": [{"tag": "li", "content": "initiation (into a society, group, etc.)"}, {"tag": "li", "content": "baptism"}]}}, {"tag": "li", "style": {"listStyleType": "\"③ \""}, "data": {"sense-number": "3"}, "content": {"tag": "ul", "data": {"content": "glossary"}, "content": [{"tag": "li", "content": "one's first experience of something"}, {"tag": "li", "content": "baptism (by fire, etc.)"}]}}]}]}}], 1391080, ""]] diff --git a/tests/files/dictionary_entries/10_expected b/tests/files/dictionary_entries/10_expected new file mode 100644 index 0000000..e7376bb --- /dev/null +++ b/tests/files/dictionary_entries/10_expected @@ -0,0 +1,11 @@ +① + ▪ baptism + ▪ christening + ◦ 彼は洗礼を受けてカトリック教徒となった。 + He was baptized a Catholic. +② + ▪ initiation (into a society, group, etc.) + ▪ baptism +③ + ▪ one's first experience of something + ▪ baptism (by fire, etc.) diff --git a/tests/files/dictionary_entries/3_expected b/tests/files/dictionary_entries/3_expected index a9be156..a1f929d 100644 --- a/tests/files/dictionary_entries/3_expected +++ b/tests/files/dictionary_entries/3_expected @@ -1,5 +1,5 @@ ▪ kanji repetition mark ➡ see:同の字点 kanji iteration mark -• 々 -• ノマ +▪ 々 +▪ ノマ diff --git a/tests/yomichan_parser_tests.c b/tests/yomichan_parser_tests.c index d6cdce1..b2960ac 100644 --- a/tests/yomichan_parser_tests.c +++ b/tests/yomichan_parser_tests.c @@ -70,10 +70,14 @@ Ensure(Parser, handles_tag_after_content2) { CHECK_NR(7); } -Ensure(Parser, correctly_parses_nested_lists) { +Ensure(Parser, correctly_formats_nested_lists) { CHECK_NR(8); } +Ensure(Parser, uses_correct_list_style) { + CHECK_NR(10); +} + Ensure(Parser, correctly_parses_frequency_entry_with_reading) { const s8 toparse = S("[[\"糞\", \"freq\", {\"reading\": \"くそ\", \"frequency\": 9788}]]"); @@ -122,6 +126,7 @@ TestSuite *yomichan_parser_tests(void) { add_test_with_context(suite, Parser, correctly_extracts_dictionary_name); add_test_with_context(suite, Parser, handles_tag_after_content1); add_test_with_context(suite, Parser, handles_tag_after_content2); - // add_test_with_context(suite, Parser, correctly_parses_nested_lists); + // add_test_with_context(suite, Parser, correctly_formats_nested_lists); + add_test_with_context(suite, Parser, uses_correct_list_style); return suite; } \ No newline at end of file