static int s_chtml10_search_emoji(chtml10_t *chtml, char *txt, char **rslt);
static char *s_chtml10_chxjif_tag (void *pdoc, Node *node);
static char *s_chtml10_text (void *pdoc, Node *node);
-static css_prop_list_t *s_chtml10_push_and_get_now_style(void *pdoc, Node *node);
-static css_prop_list_t *s_chtml10_nopush_and_get_now_style(void *pdoc, Node *node);
+static css_prop_list_t *s_chtml10_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
+static css_prop_list_t *s_chtml10_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
+
+/* pend */
tag_handler chtml10_handler[] = {
/* tagHTML */
request_rec *r;
chtml10_t *chtml10;
Attr *attr;
- char *align = NULL;
+ char *attr_align = NULL;
+ char *attr_style = NULL;
chtml10 = GET_CHTML10(pdoc);
doc = chtml10->doc;
r = doc->r;
- W_L("<p");
for (attr = qs_get_attr(doc,node);
attr;
attr = qs_get_next_attr(doc,attr)) {
/* CHTML 1.0 (W3C version 3.2) */
/*----------------------------------------------------------------------*/
if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
- align = apr_pstrdup(doc->buf.pool, val);
+ attr_align = apr_pstrdup(doc->buf.pool, val);
break;
}
}
+ else if (val && STRCASEEQ('s','S',"style", nm)) {
+ attr_style = val;
+ }
}
- if (align) {
+ if (IS_CSS_ON(chtml10->entryp)) {
+ css_prop_list_t *style = s_chtml10_push_and_get_now_style(pdoc, node, attr_style);
+ if (style) {
+ css_property_t *text_align = chxj_css_get_property_value(doc, style, "text-align");
+ css_property_t *cur;
+ for (cur = text_align->next; cur != text_align; cur = cur->next) {
+ if (STRCASEEQ('l','L',"left",cur->value)) {
+ attr_align = apr_pstrdup(doc->pool, "left");
+ }
+ else if (STRCASEEQ('c','C',"center",cur->value)) {
+ attr_align = apr_pstrdup(doc->pool, "center");
+ }
+ else if (STRCASEEQ('r','R',"right",cur->value)) {
+ attr_align = apr_pstrdup(doc->pool, "right");
+ }
+ }
+ }
+ }
+ W_L("<p");
+ if (attr_align) {
W_L(" align=\"");
- W_V(align);
+ W_V(attr_align);
W_L("\"");
}
-
W_L(">");
return chtml10->out;
}
r = doc->r;
W_L("</p>");
+ if (IS_CSS_ON(chtml10->entryp)) {
+ chxj_css_pop_prop_list(chtml10->css_prop_stack);
+ }
return chtml10->out;
}
}
static css_prop_list_t *
-s_chtml10_push_and_get_now_style(void *pdoc, Node *node)
+s_chtml10_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
{
chtml10_t *chtml10 = GET_CHTML10(pdoc);
Doc *doc = chtml10->doc;
}
chxj_css_push_prop_list(chtml10->css_prop_stack, dup_css);
last_css = chxj_css_get_last_prop_list(chtml10->css_prop_stack);
+
+ if (style_attr_value) {
+ css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
+ if (ssheet) {
+ chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
+ }
+ }
}
return last_css;
}
static css_prop_list_t *
-s_chtml10_nopush_and_get_now_style(void *pdoc, Node *node)
+s_chtml10_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
{
chtml10_t *chtml10 = GET_CHTML10(pdoc);
Doc *doc = chtml10->doc;
chxj_css_prop_list_merge_property(doc, dup_css, selector);
}
last_css = dup_css;
+
+ if (style_attr_value) {
+ css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
+ if (ssheet) {
+ chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
+ }
+ }
}
return last_css;
}
void test_chtml10_meta_tag_with_css_001();
void test_chtml10_textarea_tag_with_css_001();
+
+void test_chtml10_p_tag_with_css_001();
+void test_chtml10_p_tag_with_css_002();
+void test_chtml10_p_tag_with_css_003();
/* pend */
int
CU_add_test(chtml10_suite, "test html with css 001", test_chtml10_html_tag_with_css_001);
CU_add_test(chtml10_suite, "test meta with css 001", test_chtml10_meta_tag_with_css_001);
CU_add_test(chtml10_suite, "test textarea with css 001", test_chtml10_textarea_tag_with_css_001);
+
+ CU_add_test(chtml10_suite, "test p with css 001", test_chtml10_p_tag_with_css_001);
+ CU_add_test(chtml10_suite, "test p with css 002", test_chtml10_p_tag_with_css_002);
+ CU_add_test(chtml10_suite, "test p with css 003", test_chtml10_p_tag_with_css_003);
/* aend */
CU_basic_run_tests();
#undef RESULT_STRING
}
+/*===========================================================================*/
+/* p with CSS */
+/*===========================================================================*/
+char *test_chxj_serf_get005(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"
+ "p { text-align: left }\n";
+ *len = strlen(css);
+ call_check = 1;
+ return css;
+}
+void test_chtml10_p_tag_with_css_001()
+{
+#define TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\" type=\"text/css\" />" \
+ "</head><body><p>あいう</p></body></html>"
+#define RESULT_STRING "<html><head></head><body><p align=\"left\">あいう</p></body></html>"
+ 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_get005;
+ 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_chtml10(&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
+}
+char *test_chxj_serf_get006(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"
+ "p { text-align: center }\n";
+ *len = strlen(css);
+ call_check = 1;
+ return css;
+}
+void test_chtml10_p_tag_with_css_002()
+{
+#define TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\" type=\"text/css\" />" \
+ "</head><body><p>あいう</p></body></html>"
+#define RESULT_STRING "<html><head></head><body><p align=\"center\">あいう</p></body></html>"
+ 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_get006;
+ 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_chtml10(&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
+}
+char *test_chxj_serf_get007(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"
+ "p { text-align: right }\n";
+ *len = strlen(css);
+ call_check = 1;
+ return css;
+}
+void test_chtml10_p_tag_with_css_003()
+{
+#define TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\" type=\"text/css\" />" \
+ "</head><body><p>あいう</p></body></html>"
+#define RESULT_STRING "<html><head></head><body><p align=\"right\">あいう</p></body></html>"
+ 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_get007;
+ 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_chtml10(&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
+}
/* test CSS */
/*
* vim:ts=2 et