diff --git a/sefht.geany b/sefht.geany index 2dda1faf5bf39e3abb46a7b90b3421975371295c..87290b950b43029b9fa463492ca5a76dc5f48b18 100644 --- a/sefht.geany +++ b/sefht.geany @@ -28,7 +28,7 @@ long_line_behaviour=1 long_line_column=72 [files] -current_page=9 +current_page=55 FILE_NAME_0=139;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2FREADME;0;8 FILE_NAME_1=134;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitignore;0;8 FILE_NAME_2=1737;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8 @@ -42,11 +42,11 @@ FILE_NAME_9=2172;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fpr FILE_NAME_10=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment.c;0;8 FILE_NAME_11=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment.h;0;8 FILE_NAME_12=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_data.c;0;8 -FILE_NAME_13=29;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8 -FILE_NAME_14=4785;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8 +FILE_NAME_13=2476;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8 +FILE_NAME_14=41345;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8 FILE_NAME_15=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8 -FILE_NAME_16=6328;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.c;0;8 -FILE_NAME_17=28;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.h;0;8 +FILE_NAME_16=3454;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.c;0;8 +FILE_NAME_17=1867;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_fragment.h;0;8 FILE_NAME_18=19;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8 FILE_NAME_19=19;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8 FILE_NAME_20=26;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr_static.c;0;8 @@ -75,8 +75,8 @@ FILE_NAME_42=3007;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte% FILE_NAME_43=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Fno_test.sh.in;0;8 FILE_NAME_44=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8 FILE_NAME_45=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8 -FILE_NAME_46=8232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8 -FILE_NAME_47=4815;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 +FILE_NAME_46=1772;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8 +FILE_NAME_47=130867;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8 FILE_NAME_48=5714;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8 FILE_NAME_49=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8 FILE_NAME_50=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8 @@ -84,7 +84,7 @@ FILE_NAME_51=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fpr FILE_NAME_52=926;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 FILE_NAME_53=20787;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8 FILE_NAME_54=58751;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8 -FILE_NAME_55=497;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 +FILE_NAME_55=272;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 FILE_NAME_56=2938;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4 FILE_NAME_57=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8 FILE_NAME_58=683;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4 diff --git a/src/lib/sefht/fragment_class.c b/src/lib/sefht/fragment_class.c index fdbe5eb8e565475b856c1369a0f7c7653b3d8637..9d1e73b811a369f5c938c37ba7de5062e0c8cecc 100644 --- a/src/lib/sefht/fragment_class.c +++ b/src/lib/sefht/fragment_class.c @@ -99,6 +99,15 @@ get_type (const struct SH_Fragment * fragment) return fragment->type; } +static inline +/*@dependent@*/ +struct SH_Data * +get_data (const struct SH_Fragment * fragment) + /*@*/ +{ + return fragment->data; +} + static inline /*@null@*/ /*@dependent@*/ diff --git a/src/lib/sefht/node_fragment.c b/src/lib/sefht/node_fragment.c index 0f98972d10a2fcb92f07db5c4fd8697fcf884f25..10423eb579daf03eed71032a61848824504ae873 100644 --- a/src/lib/sefht/node_fragment.c +++ b/src/lib/sefht/node_fragment.c @@ -64,6 +64,7 @@ struct SH_NodeFragment #define OPEN_TAG_BEGIN "<" #define OPEN_TAG_END ">" +#define SELF_TAG_END " />" #define CLOSE_TAG_BEGIN "</" #define CLOSE_TAG_END ">" @@ -1760,6 +1761,16 @@ SH_NodeFragment_to_html (const struct SH_NodeFragment * fragment, #undef add } + if (SH_Data_is_self_closing_tag (get_data (&fragment->base), + fragment->tag, status)) + { + if (!SH_Text_append_string (html, SELF_TAG_END, status)) + { + goto fail_autoclean; + } + goto after_close_tag; + } + if (!SH_Text_append_string (html, OPEN_TAG_END, status)) { goto fail_autoclean; @@ -1813,6 +1824,7 @@ SH_NodeFragment_to_html (const struct SH_NodeFragment * fragment, goto fail_autoclean; } +after_close_tag: if (mode == WRAP) { if (!SH_Text_append_string (html, NEWLINE, status)) @@ -1824,7 +1836,6 @@ SH_NodeFragment_to_html (const struct SH_NodeFragment * fragment, } set_success (status); - return html; fail_autoclean: diff --git a/src/lib/sefht/text_fragment.c b/src/lib/sefht/text_fragment.c index 9901409e032b6cc3d9562ff8adfc5325505b8ae1..7ac329e477709086011ddb53335b0314584eb29f 100644 --- a/src/lib/sefht/text_fragment.c +++ b/src/lib/sefht/text_fragment.c @@ -143,6 +143,13 @@ SH_TextFragment_copy (const struct SH_TextFragment * fragment, return (struct SH_Fragment *) copy; } +bool +SH_Fragment_is_TextFragment (const struct SH_Fragment * fragment) + /*@*/ +{ + return get_type (fragment) == TEXT; +} + /*@observer@*/ const struct SH_Text * SH_TextFragment_get_text (const struct SH_TextFragment * fragment) diff --git a/src/lib/sefht/text_fragment.h b/src/lib/sefht/text_fragment.h index a9fc3e75f1233776bd4c8a8bea565afd8c889685..b6f145f54bcd9cb461318c8d9717167671d31838 100644 --- a/src/lib/sefht/text_fragment.h +++ b/src/lib/sefht/text_fragment.h @@ -62,6 +62,10 @@ SH_TextFragment_copy (const SH_TextFragment * fragment, /*@modifies fileSystem@*/ /*@modifies status@*/; +bool +SH_Fragment_is_TextFragment (const SH_Fragment * fragment) + /*@*/; + /*@observer@*/ const SH_Text * SH_TextFragment_get_text (const SH_TextFragment * fragment) diff --git a/tests/test_fragment.c b/tests/test_fragment.c index 13f39521f701906981d9821ae6f011e67844c985..003762bd9e7539f60ad10db5f6d570edcf6f11be 100644 --- a/tests/test_fragment.c +++ b/tests/test_fragment.c @@ -41,6 +41,7 @@ START_TEST(test_fragment_type) struct SH_Fragment * node_fragment; struct SH_Fragment * text_fragment; enum SH_FRAGMENT_TYPE type; + bool result; /* setup */ data = SH_Data_new (NULL); @@ -55,9 +56,13 @@ START_TEST(test_fragment_type) /* test */ type = get_type (node_fragment); ck_assert_int_eq (NODE, type); + result = SH_Fragment_is_NodeFragment (node_fragment); + ck_assert_int_eq (TRUE, result); type = get_type (text_fragment); ck_assert_int_eq (TEXT, type); + result = SH_Fragment_is_TextFragment (text_fragment); + ck_assert_int_eq (TRUE, result); /* cleanup */ SH_Fragment_free (node_fragment); diff --git a/tests/test_node_fragment.c b/tests/test_node_fragment.c index 70673f2f59b00f704a79c8692930b29d402945f4..056b828cdf6929a374ee5aa798875979480bcb8e 100644 --- a/tests/test_node_fragment.c +++ b/tests/test_node_fragment.c @@ -4263,6 +4263,17 @@ START_TEST(test_node_fragment_html_inline_no_status) "lang", "de", NULL); ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("meta", data, NULL); + ck_assert_ptr_ne (NULL, child); + + result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child, + "charset", "utf-8", + NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_NodeFragment_append_child (fragment, child, NULL); + ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("body", data, NULL); ck_assert_ptr_ne (NULL, child); @@ -4285,6 +4296,7 @@ START_TEST(test_node_fragment_html_inline_no_status) string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL); ck_assert_str_eq (string, "<html lang=\"de\">" + "<meta charset=\"utf-8\" />" "<body id=\"body\" attr>" "</body>" "</html>"); @@ -4321,6 +4333,17 @@ START_TEST(test_node_fragment_html_inline_with_status) NULL); ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("meta", data, NULL); + ck_assert_ptr_ne (NULL, child); + + result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child, + "charset", "utf-8", + NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_NodeFragment_append_child (fragment, child, NULL); + ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("body", data, NULL); ck_assert_ptr_ne (NULL, child); @@ -4346,6 +4369,7 @@ START_TEST(test_node_fragment_html_inline_with_status) string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL); ck_assert_str_eq (string, "<html lang=\"de\">" + "<meta charset=\"utf-8\" />" "<body id=\"body\" attr>" "</body>" "</html>"); @@ -4381,6 +4405,17 @@ START_TEST(test_node_fragment_html_wrap_no_status) NULL); ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("meta", data, NULL); + ck_assert_ptr_ne (NULL, child); + + result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child, + "charset", "utf-8", + NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_NodeFragment_append_child (fragment, child, NULL); + ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("body", data, NULL); ck_assert_ptr_ne (NULL, child); @@ -4404,6 +4439,7 @@ START_TEST(test_node_fragment_html_wrap_no_status) string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL); ck_assert_str_eq (string, "<html lang=\"de\">\n" + "\t<meta charset=\"utf-8\" />\n" "\t<body id=\"body\" attr>\n" "\t</body>\n" "</html>\n"); @@ -4440,6 +4476,17 @@ START_TEST(test_node_fragment_html_wrap_with_status) NULL); ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("meta", data, NULL); + ck_assert_ptr_ne (NULL, child); + + result = SH_NodeFragment_append_attr_new ((SH_NodeFragment *)child, + "charset", "utf-8", + NULL); + ck_assert_int_eq (TRUE, result); + + result = SH_NodeFragment_append_child (fragment, child, NULL); + ck_assert_int_eq (TRUE, result); + child = SH_NodeFragment_new ("body", data, NULL); ck_assert_ptr_ne (NULL, child); @@ -4465,6 +4512,7 @@ START_TEST(test_node_fragment_html_wrap_with_status) string = SH_Text_get_string (text, 0, SIZE_MAX, &length, NULL); ck_assert_str_eq (string, "<html lang=\"de\">\n" + "\t<meta charset=\"utf-8\" />\n" "\t<body id=\"body\" attr>\n" "\t</body>\n" "</html>\n"); diff --git a/todo.txt b/todo.txt index c2bf52062f518850fd659fd4ef11c8b030ef5684..94dd15a07bfc4bacff9159986e9a02ab01c635f0 100644 --- a/todo.txt +++ b/todo.txt @@ -8,8 +8,8 @@ fix warnings for tests Fragment: - create html on single Text object - add customized styling in html generation -- support self closing tags - specifying of allowed tags/attr/content +- forward compatibility for types only TextFragment: - support indenting (XFAIL) - support of newlines (72/79/80)