From: konn Date: Thu, 17 Jul 2008 12:45:15 +0000 (+0000) Subject: * Added center tag with CSS for CHTML5.0 converter. X-Git-Tag: v0.13.0~4^2~1369 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=96fab8efbbcc5faef64c55d5c49eefee6e84d3a3;p=modchxj%2Fmod_chxj.git * Added center tag with CSS for CHTML5.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2986 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- diff --git a/src/chxj_chtml40.c b/src/chxj_chtml40.c index 086773a1..932b47aa 100644 --- a/src/chxj_chtml40.c +++ b/src/chxj_chtml40.c @@ -2014,60 +2014,6 @@ s_chtml40_start_hr_tag(void *pdoc, Node *node) W_L(" noshade"); } W_L(">"); -#if 0 - for (attr = qs_get_attr(doc,node); - attr; - attr = qs_get_next_attr(doc,attr)) { - char *name = qs_get_attr_name(doc,attr); - char *value = qs_get_attr_value(doc,attr); - if (STRCASEEQ('a','A',"align", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) { - W_L(" align=\""); - W_V(value); - W_L("\""); - } - } - else if (STRCASEEQ('s','S',"size", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - if (value && *value) { - W_L(" size=\""); - W_V(value); - W_L("\""); - } - } - else if (STRCASEEQ('w','W',"width", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - if (value && *value) { - W_L(" width=\""); - W_V(value); - W_L("\""); - } - } - else if (STRCASEEQ('n','N',"noshade", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" noshade"); - } - else if (STRCASEEQ('c','C',"color", name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 4.0 */ - /*----------------------------------------------------------------------*/ - W_L(" color=\""); - W_V(value); - W_L("\""); - } - } - W_L(""); -#endif return chtml40->out; } diff --git a/src/chxj_chtml50.c b/src/chxj_chtml50.c index ff1170f7..6f60f4fe 100644 --- a/src/chxj_chtml50.c +++ b/src/chxj_chtml50.c @@ -1975,6 +1975,156 @@ s_chtml50_start_hr_tag(void *pdoc, Node *node) chtml50_t *chtml50; Doc *doc; request_rec *r; + char *attr_align = NULL; + char *attr_size = NULL; + char *attr_width = NULL; + char *attr_noshade = NULL; + char *attr_style = NULL; + char *attr_color = NULL; + + chtml50 = GET_CHTML50(pdoc); + doc = chtml50->doc; + r = doc->r; + + for (attr = qs_get_attr(doc,node); + attr; + attr = qs_get_next_attr(doc,attr)) { + char *name = qs_get_attr_name (doc,attr); + char *value = qs_get_attr_value(doc,attr); + switch(*name) { + case 'a': + case 'A': + if (strcasecmp(name, "align") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) { + attr_align = value; + } + } + break; + + case 's': + case 'S': + if (strcasecmp(name, "size") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && *value) { + attr_size = value; + } + } + else if (strcasecmp(name, "style") == 0) { + if (value && *value) { + attr_style = value; + } + } + break; + + case 'w': + case 'W': + if (strcasecmp(name, "width") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && *value) { + attr_width = value; + } + } + break; + + case 'n': + case 'N': + if (strcasecmp(name, "noshade") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_noshade = apr_pstrdup(doc->pool, "noshade"); + } + break; + + case 'c': + case 'C': + if (strcasecmp(name, "color") == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 4.0 */ + /*--------------------------------------------------------------------*/ + attr_color = value; + } + break; + + default: + break; + } + } + if (IS_CSS_ON(chtml50->entryp)) { + css_prop_list_t *style = s_chtml50_nopush_and_get_now_style(pdoc, node, attr_style); + if (style) { + css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style"); + css_property_t *height_prop = chxj_css_get_property_value(doc, style, "height"); + css_property_t *width_prop = chxj_css_get_property_value(doc, style, "width"); + css_property_t *cur; + for (cur = border_style_prop->next; cur != border_style_prop; cur = cur->next) { + if (STRCASEEQ('s','S',"solid",cur->value)) { + attr_noshade = "noshade"; + } + } + for (cur = height_prop->next; cur != height_prop; cur = cur->next) { + char *tmp = apr_pstrdup(doc->pool, cur->value); + char *tmpp = strstr(tmp, "px"); + if (tmpp) { + *tmpp = 0; + attr_size = apr_pstrdup(doc->pool, tmp); + } + } + for (cur = width_prop->next; cur != width_prop; cur = cur->next) { + char *tmp = apr_pstrdup(doc->pool, cur->value); + char *tmpp = strstr(tmp, "px"); + if (tmpp) { + *tmpp = 0; + attr_width = apr_pstrdup(doc->pool, tmp); + } + else { + tmpp = strstr(tmp, "%"); + if (tmpp) { + attr_width = apr_pstrdup(doc->pool, tmp); + } + } + } + } + } + W_L(""); + return chtml50->out; + +#if 0 + Attr *attr; + chtml50_t *chtml50; + Doc *doc; + request_rec *r; chtml50 = GET_CHTML50(pdoc); doc = chtml50->doc; @@ -2033,6 +2183,7 @@ s_chtml50_start_hr_tag(void *pdoc, Node *node) } } W_L(">"); +#endif return chtml50->out; } diff --git a/test/chxj_chtml50/test_chxj_chtml50.c b/test/chxj_chtml50/test_chxj_chtml50.c index 35ab3d44..496b08e4 100644 --- a/test/chxj_chtml50/test_chxj_chtml50.c +++ b/test/chxj_chtml50/test_chxj_chtml50.c @@ -668,6 +668,15 @@ void test_chtml50_center_tag_with_css_013(); void test_chtml50_center_tag_with_css_014(); void test_chtml50_center_tag_with_css_015(); void test_chtml50_center_tag_with_css_016(); + +void test_chtml50_hr_tag_with_css_001(); +void test_chtml50_hr_tag_with_css_002(); +void test_chtml50_hr_tag_with_css_003(); +void test_chtml50_hr_tag_with_css_004(); +void test_chtml50_hr_tag_with_css_005(); +void test_chtml50_hr_tag_with_css_006(); +void test_chtml50_hr_tag_with_css_007(); +void test_chtml50_hr_tag_with_css_008(); /* pend */ int @@ -1297,6 +1306,15 @@ main() CU_add_test(chtml50_suite, "test center with css 014", test_chtml50_center_tag_with_css_014); CU_add_test(chtml50_suite, "test center with css 015", test_chtml50_center_tag_with_css_015); CU_add_test(chtml50_suite, "test center with css 016", test_chtml50_center_tag_with_css_016); + + CU_add_test(chtml50_suite, "test hr with css 001", test_chtml50_hr_tag_with_css_001); + CU_add_test(chtml50_suite, "test hr with css 002", test_chtml50_hr_tag_with_css_002); + CU_add_test(chtml50_suite, "test hr with css 003", test_chtml50_hr_tag_with_css_003); + CU_add_test(chtml50_suite, "test hr with css 004", test_chtml50_hr_tag_with_css_004); + CU_add_test(chtml50_suite, "test hr with css 005", test_chtml50_hr_tag_with_css_005); + CU_add_test(chtml50_suite, "test hr with css 006", test_chtml50_hr_tag_with_css_006); + CU_add_test(chtml50_suite, "test hr with css 007", test_chtml50_hr_tag_with_css_007); + CU_add_test(chtml50_suite, "test hr with css 008", test_chtml50_hr_tag_with_css_008); /* aend */ CU_basic_run_tests(); @@ -19380,6 +19398,327 @@ void test_chtml50_center_tag_with_css_016() #undef TEST_STRING #undef RESULT_STRING } + + +/*===========================================================================*/ +/* hr tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get100(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { border-style:solid }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_hr_tag_with_css_001() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get100; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml50_hr_tag_with_css_002() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get100; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + + +char *test_chxj_serf_get101(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { height:10px }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_hr_tag_with_css_003() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get101; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml50_hr_tag_with_css_004() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get101; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + +char *test_chxj_serf_get102(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { width:10px }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_hr_tag_with_css_005() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get102; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml50_hr_tag_with_css_006() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get102; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + +char *test_chxj_serf_get103(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { width:80% }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_hr_tag_with_css_007() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get103; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml50_hr_tag_with_css_008() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get103; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml50(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */