Skip to content

Commit

Permalink
Use correct list style for nested lists
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed Jun 15, 2024
1 parent 3728fb4 commit 3bdd7a7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/yomichan_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/files/dictionary_entries/10_entry
Original file line number Diff line number Diff line change
@@ -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, ""]]
11 changes: 11 additions & 0 deletions tests/files/dictionary_entries/10_expected
Original file line number Diff line number Diff line change
@@ -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.)
4 changes: 2 additions & 2 deletions tests/files/dictionary_entries/3_expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
▪ kanji repetition mark
➡ see:同の字点
kanji iteration mark
ノマ
ノマ
9 changes: 7 additions & 2 deletions tests/yomichan_parser_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}]]");

Expand Down Expand Up @@ -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;
}

0 comments on commit 3bdd7a7

Please sign in to comment.