OSDN Git Service

* Changed DEBUG Log.
[modchxj/mod_chxj.git] / src / chxj_chtml40.c
index 711d7f9..03aab33 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@
 #include "chxj_qr_code.h"
 #include "chxj_encoding.h"
 #include "chxj_header_inf.h"
+#include "chxj_conv_z2h.h"
 
 #define GET_CHTML40(X) ((chtml40_t *)(X))
 #undef W_L
 #undef W_NLCODE
 #define W_NLCODE()     do { char *nlcode = TO_NLCODE(chtml40->conf); W_V(nlcode); } while (0)
 
+#define CHTML40_GET_CSS_COLOR_AND_LIST_STYLE_TYPE() \
+  if (IS_CSS_ON(chtml40->entryp)) { \
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style); \
+    if (style) { \
+      css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color"); \
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type"); \
+      css_property_t *cur; \
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) { \
+        if (cur->value && *cur->value) { \
+          attr_color = apr_pstrdup(doc->pool, cur->value); \
+        } \
+      } \
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) { \
+        if (cur->value && *cur->value) { \
+          attr_type = apr_pstrdup(doc->pool, cur->value); \
+        } \
+      } \
+    } \
+  }
+
 static char *s_chtml40_start_html_tag     (void *pdoc, Node *node);
 static char *s_chtml40_end_html_tag       (void *pdoc, Node *node);
 static char *s_chtml40_start_meta_tag     (void *pdoc, Node *node);
@@ -95,7 +116,7 @@ static char *s_chtml40_start_div_tag      (void *pdoc, Node *node);
 static char *s_chtml40_end_div_tag        (void *pdoc, Node *node);
 static char *s_chtml40_chxjif_tag         (void *pdoc, Node *node); 
 static char *s_chtml40_text_tag           (void *pdoc, Node *node);
-static char *s_chtml40_start_blockquote_tag(void *pdoc, Node *node);
+static char *s_chtml40_start_blockquote_tag (void *pdoc, Node *node);
 static char *s_chtml40_end_blockquote_tag  (void *pdoc, Node *node);
 static char *s_chtml40_start_dir_tag      (void *pdoc, Node *node);
 static char *s_chtml40_end_dir_tag        (void *pdoc, Node *node);
@@ -115,10 +136,16 @@ static char *s_chtml40_start_plaintext_tag       (void *pdoc, Node *node);
 static char *s_chtml40_start_plaintext_tag_inner (void *pdoc, Node *node);
 static char *s_chtml40_end_plaintext_tag         (void *pdoc, Node *node);
 static char *s_chtml40_newline_mark       (void *pdoc, Node *node);
+static char *s_chtml40_link_tag           (void *pdoc, Node *node);
+static char *s_chtml40_start_span_tag     (void *pdoc, Node *node);
+static char *s_chtml40_end_span_tag       (void *pdoc, Node *node);
+static char *s_chtml40_style_tag     (void *pdoc, Node *node);
 
 static void  s_init_chtml40(chtml40_t *chtml, Doc *doc, request_rec *r, device_table *spec);
 
-static int   s_chtml40_search_emoji(chtml40_t *chtml, char *txt, char **rslt);
+static int   s_chtml40_search_emoji(chtml40_t *chtml, char *txt, char **rslt, Node *node);
+static css_prop_list_t *s_chtml40_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
+static css_prop_list_t *s_chtml40_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
 
 
 tag_handler chtml40_handler[] = {
@@ -292,6 +319,11 @@ tag_handler chtml40_handler[] = {
     s_chtml40_chxjif_tag,
     NULL,
   },
+  /* tagCHXJRAW */
+  {
+    s_chtml40_chxjif_tag,
+    NULL,
+  },
   /* tagNOBR */
   {
     NULL,
@@ -304,13 +336,13 @@ tag_handler chtml40_handler[] = {
   },
   /* tagSTYLE */
   {
-    NULL,
+    s_chtml40_style_tag,
     NULL,
   },
   /* tagSPAN */
   {
-    NULL,
-    NULL,
+    s_chtml40_start_span_tag,
+    s_chtml40_end_span_tag,
   },
   /* tagTEXT */
   {
@@ -387,11 +419,31 @@ tag_handler chtml40_handler[] = {
     s_chtml40_start_marquee_tag,
     s_chtml40_end_marquee_tag,
   },
+  /* tagLINK */
+  {
+    s_chtml40_link_tag,
+    NULL,
+  },
   /* tagNLMARK */
   {
     s_chtml40_newline_mark,
     NULL,
   },
+  /* tagObject */
+  {
+    NULL,
+    NULL,
+  },
+  /* tagParam */
+  {
+    NULL,
+    NULL,
+  },
+  /* tagCAPTION */
+  {
+    NULL,
+    NULL,
+  },
 };
 
 
@@ -420,7 +472,7 @@ chxj_convert_chtml40(
   chtml40_t chtml40;
   Doc       doc;
 
-  DBG(r, "start chxj_convert_chtml40()");
+  DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
 
   /*--------------------------------------------------------------------------*/
   /* If qrcode xml                                                            */
@@ -428,11 +480,10 @@ chxj_convert_chtml40(
   *dstlen = srclen;
   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
   if (dst) {
-    DBG(r,"i found qrcode xml");
-    DBG(r, "end chxj_convert_chtml40()");
+    DBG(r,"REQ[%X] found qrcode xml",TO_ADDR(r));
+    DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
     return dst;
   }
-  DBG(r,"not found qrcode xml");
 
   /*--------------------------------------------------------------------------*/
   /* The CHTML structure is initialized.                                      */
@@ -457,6 +508,11 @@ chxj_convert_chtml40(
 #ifdef DUMP_LOG
   chxj_dump_out("[src] CHTML -> CHTML4.0", ss, srclen);
 #endif
+  if (IS_CSS_ON(chtml40.entryp)) {
+    /* current property list */
+    chtml40.css_prop_stack = chxj_new_prop_list_stack(&doc);
+  }
+
   chxj_buffered_write_init(r->pool, &doc.buf);
 
   qs_parse_string(&doc,ss, strlen(ss));
@@ -484,7 +540,7 @@ chxj_convert_chtml40(
   chxj_dump_out("[src] CHTML -> CHTML4.0", dst, *dstlen);
 #endif
 
-  DBG(r, "end chxj_convert_chtml40()");
+  DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
   return dst;
 }
 
@@ -523,10 +579,11 @@ s_init_chtml40(chtml40_t *chtml40, Doc *doc, request_rec *r, device_table *spec)
  *                      EMOJI is specified. 
  * @param rslt    [o]   The pointer to the pointer that stores the result is 
  *                      specified. 
+ * @param node    [i]   The current node to check whether tag is span/font for CHXJ_IMODE_EMOJI_COLOR_AUTO.
  * @return When corresponding EMOJI exists, it returns it excluding 0. 
  */
 static int
-s_chtml40_search_emoji(chtml40_t *chtml40, char *txt, char **rslt)
+s_chtml40_search_emoji(chtml40_t *chtml40, char *txt, char **rslt, Node *node)
 {
   emoji_t       *ee;
   request_rec   *r;
@@ -539,7 +596,7 @@ s_chtml40_search_emoji(chtml40_t *chtml40, char *txt, char **rslt)
   r   = chtml40->doc->r;
 
   if (!spec) {
-    DBG(r,"spec is NULL");
+    DBG(r,"REQ[%X] spec is NULL",TO_ADDR(r));
   }
 
   for (ee = chtml40->conf->emoji;
@@ -559,6 +616,20 @@ s_chtml40_search_emoji(chtml40_t *chtml40, char *txt, char **rslt)
         (*rslt)[0] = ee->imode->hex1byte & 0xff;
         (*rslt)[1] = ee->imode->hex2byte & 0xff;
         (*rslt)[2] = 0;
+        
+        if(chtml40->conf->imode_emoji_color >= CHXJ_IMODE_EMOJI_COLOR_AUTO ){
+          if(ee->imode->color != NULL){
+            if(chtml40->conf->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_AUTO && node != NULL ){
+              if(strcasecmp(node->parent->name, "span") == 0 ||
+                 strcasecmp(node->parent->name, "font")  == 0 ){
+                return strlen(ee->imode->string);
+              }
+            }
+            char *tmp = apr_pstrdup(r->pool,*rslt);
+            *rslt = apr_psprintf(r->pool,
+                        "<font color=\"%s\">%s</font>",ee->imode->color,tmp);
+          }
+        }
         return strlen(ee->imode->string);
       }
 
@@ -585,7 +656,7 @@ chxj_chtml40_emoji_only_converter(request_rec *r, device_table *spec, const char
   chtml40 = &__chtml40;
   doc     = &__doc;
 
-  DBG(r, "REQ[%X] start chxj_chtml40_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
+  DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
   memset(doc,     0, sizeof(Doc));
   memset(chtml40, 0, sizeof(chtml40_t));
 
@@ -604,7 +675,7 @@ chxj_chtml40_emoji_only_converter(request_rec *r, device_table *spec, const char
     char *out;
     int   rtn;
 
-    rtn = s_chtml40_search_emoji(chtml40, (char *)&src[ii], &out);
+    rtn = s_chtml40_search_emoji(chtml40, (char *)&src[ii], &out, NULL);
     if (rtn) {
       W_V(out);
       ii+=(rtn - 1);
@@ -626,7 +697,7 @@ chxj_chtml40_emoji_only_converter(request_rec *r, device_table *spec, const char
   }
   chtml40->out = chxj_buffered_write_flush(chtml40->out, &doc->buf);
 
-  DBG(r, "REQ[%X] end chxj_chtml40_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
+  DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
   return chtml40->out;
 }
 
@@ -746,7 +817,7 @@ s_chtml40_start_meta_tag(void *pdoc, Node *node)
             sec = apr_pstrdup(r->pool, buf);
             sec[url-buf] = 0;
             url++;
-            url = chxj_encoding_parameter(r, url);
+            url = chxj_encoding_parameter(r, url, 0);
             url = chxj_add_cookie_parameter(r, url, chtml40->cookie);
             W_L(" ");
             W_V(name);
@@ -946,12 +1017,18 @@ s_chtml40_start_body_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_bgcolor = NULL;
+  char        *attr_text    = NULL;
+  char        *attr_link    = NULL;
+  char        *attr_style   = NULL;
+  char        *attr_alink   = NULL;
+  char        *attr_vlink   = NULL;
+
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<body");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -964,42 +1041,116 @@ s_chtml40_start_body_tag(void *pdoc, Node *node)
       /*----------------------------------------------------------------------*/
       /* CHTML 2.0                                                            */
       /*----------------------------------------------------------------------*/
-      W_L(" bgcolor=\"");
-      W_V(value);
-      W_L("\"");
+      attr_bgcolor = value;
     }
     else if (STRCASEEQ('t','T', "text", name) && value && *value) {
       /*----------------------------------------------------------------------*/
       /* CHTML 2.0                                                            */
       /*----------------------------------------------------------------------*/
-      W_L(" text=\"");
-      W_V(value);
-      W_L("\"");
+      attr_text = value;
     }
     else if (STRCASEEQ('l','L',"link", name) && value && *value) {
       /*----------------------------------------------------------------------*/
       /* CHTML 2.0                                                            */
       /*----------------------------------------------------------------------*/
-      W_L(" link=\"");
-      W_V(value);
-      W_L("\"");
+      attr_link = value;
     }
     else if (STRCASEEQ('a','A',"alink", name) && value && *value) {
       /*----------------------------------------------------------------------*/
       /* CHTML 4.0                                                            */
       /*----------------------------------------------------------------------*/
-      W_L(" alink=\"");
-      W_V(value);
-      W_L("\"");
+      attr_alink = value;
     }
     else if (STRCASEEQ('v','V',"vlink", name) && value && *value) {
       /*----------------------------------------------------------------------*/
       /* CHTML 4.0                                                            */
       /*----------------------------------------------------------------------*/
-      W_L(" vlink=\"");
-      W_V(value);
-      W_L("\"");
+      attr_vlink = value;
+    }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *bgcolor_prop    = chxj_css_get_property_value(doc, style, "background-color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_text = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
     }
+    if (chtml40->style) {
+      css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, chtml40->style);
+      css_selector_t *cur_sel;
+      for (cur_sel = pseudos->selector_head.next; cur_sel != &pseudos->selector_head; cur_sel = cur_sel->next) {
+        if (cur_sel->name && strcasecmp(cur_sel->name, "a:link") == 0) {
+          css_property_t *cur;
+          for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
+            if (cur->name && strcasecmp(cur->name, "color") == 0) {
+              attr_link = apr_pstrdup(doc->pool, cur->value);
+            }
+          }
+        }
+        else if (cur_sel->name && strcasecmp(cur_sel->name, "a:visited") == 0) {
+          css_property_t *cur;
+          for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
+            if (cur->name && strcasecmp(cur->name, "color") == 0) {
+              attr_vlink = apr_pstrdup(doc->pool, cur->value);
+            }
+          }
+        }
+        else if (cur_sel->name && strcasecmp(cur_sel->name, "a:focus") == 0) {
+          css_property_t *cur;
+          for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
+            if (cur->name && strcasecmp(cur->name, "color") == 0) {
+              attr_alink = apr_pstrdup(doc->pool, cur->value);
+            }
+          }
+        }
+      }
+    }
+  }
+
+  W_L("<body");
+  if (attr_bgcolor) {
+    attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
+    W_L(" bgcolor=\"");
+    W_V(attr_bgcolor);
+    W_L("\"");
+  }
+  if (attr_text) {
+    attr_text = chxj_css_rgb_func_to_value(doc->pool, attr_text);
+    W_L(" text=\"");
+    W_V(attr_text);
+    W_L("\"");
+  }
+  if (attr_link) {
+    attr_link = chxj_css_rgb_func_to_value(doc->pool, attr_link);
+    W_L(" link=\"");
+    W_V(attr_link);
+    W_L("\"");
+  }
+  if (attr_alink) {
+    attr_alink = chxj_css_rgb_func_to_value(doc->pool, attr_alink);
+    W_L(" alink=\"");
+    W_V(attr_alink);
+    W_L("\"");
+  }
+  if (attr_vlink) {
+    attr_vlink = chxj_css_rgb_func_to_value(doc->pool, attr_vlink);
+    W_L(" vlink=\"");
+    W_V(attr_vlink);
+    W_L("\"");
   }
   W_L(">");
 
@@ -1025,6 +1176,9 @@ s_chtml40_end_body_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml40->doc;
 
   W_L("</body>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -1041,10 +1195,11 @@ s_chtml40_end_body_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_a_tag(void *pdoc, Node *node) 
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_style = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
@@ -1071,7 +1226,7 @@ s_chtml40_start_a_tag(void *pdoc, Node *node)
       /*----------------------------------------------------------------------*/
       /* CHTML1.0                                                             */
       /*----------------------------------------------------------------------*/
-      value = chxj_encoding_parameter(r, value);
+      value = chxj_encoding_parameter(r, value, 0);
       if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
         value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
       }
@@ -1150,8 +1305,16 @@ s_chtml40_start_a_tag(void *pdoc, Node *node)
       /*----------------------------------------------------------------------*/
       /* ignore */
     }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
   }
   W_L(">");
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+  }
+
   return chtml40->out;
 }
 
@@ -1175,6 +1338,10 @@ s_chtml40_end_a_tag(void *pdoc, Node *UNUSED(child))
 
   W_L("</a>");
 
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
+
   return chtml40->out;
 }
 
@@ -1295,7 +1462,8 @@ s_chtml40_start_font_tag(void *pdoc, Node *node)
   chtml40_t     *chtml40;
   Doc           *doc;
   request_rec   *r;
-  char          *color = NULL;
+  char          *attr_color = NULL;
+  char          *attr_style = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
@@ -1305,12 +1473,12 @@ s_chtml40_start_font_tag(void *pdoc, Node *node)
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
   for (attr = qs_get_attr(doc,node);
-       attr && color == NULL
+       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('c','C',"color", name) && value && *value) {
-      color = apr_pstrdup(doc->buf.pool, value);
+      attr_color = apr_pstrdup(doc->buf.pool, value);
       break;
     }
     else if (STRCASEEQ('s','S',"size", name)) {
@@ -1319,12 +1487,33 @@ s_chtml40_start_font_tag(void *pdoc, Node *node)
       /*----------------------------------------------------------------------*/
       /* ignore */
     }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
   }
-  if (color) {
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
     W_L("<font color=\"");
-    W_V(color);
+    W_V(attr_color);
     W_L("\">");
-    chtml40->font_flag++;
+    chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(*flg));
+    flg->with_font_flag = 1;
+    node->userData = flg;
+  }
+  else {
+    node->userData = NULL;
   }
   return chtml40->out;
 }
@@ -1339,7 +1528,7 @@ s_chtml40_start_font_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_font_tag(void *pdoc, Node *UNUSED(child)) 
+s_chtml40_end_font_tag(void *pdoc, Node *node)
 {
   chtml40_t     *chtml40;
   Doc           *doc;
@@ -1349,9 +1538,12 @@ s_chtml40_end_font_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml40->doc;
   r       = doc->r;
 
-  if (chtml40->font_flag) {
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
     W_L("</font>");
-    chtml40->font_flag--;
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
   }
 
   return chtml40->out;
@@ -1369,14 +1561,17 @@ s_chtml40_end_font_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_form_tag(void *pdoc, Node *node) 
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
-  char          *new_hidden_tag = NULL;
-  char          *attr_method = NULL;
-  char          *attr_action = NULL;
-  char          *attr_utn    = NULL;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_action = NULL;
+  char        *attr_method = NULL;
+  char        *attr_style  = NULL;
+  char        *attr_color  = NULL;
+  char        *attr_align  = NULL;
+  char        *attr_utn    = NULL;
+  char        *new_hidden_tag = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
@@ -1390,25 +1585,68 @@ s_chtml40_start_form_tag(void *pdoc, Node *node)
        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',"action", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      attr_action = chxj_encoding_parameter(r, value);
-      attr_action = chxj_add_cookie_parameter(r, attr_action, chtml40->cookie);
-    }
-    else if (STRCASEEQ('m','M',"method", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      attr_method = apr_pstrdup(doc->pool, value);
+    switch(*name) {
+    case 'a':
+    case 'A':
+      if (strcasecmp(name, "action") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_action = value;
+      }
+      break;
+
+    case 'm':
+    case 'M':
+      if (strcasecmp(name, "method") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_method = value;
+      }
+      break;
+
+    case 'u':
+    case 'U':
+      if (strcasecmp(name, "utn") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 3.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_utn = value;
+      }
+      break;
+
+    case 's':
+    case 'S':
+      if (strcasecmp(name, "style") == 0) {
+        attr_style = value;
+      }
+      break;
+
+    default:
+      break;
     }
-    else if (STRCASEEQ('u','U',"utn", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 3.0                                                            */
-      /* It is special only for CHTML.                                        */
-      /*----------------------------------------------------------------------*/
-      attr_utn = value;
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = text_align_prop->next; cur != text_align_prop; 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");
+        }
+      }
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        attr_color = apr_pstrdup(doc->pool, cur->value);
+      }
     }
   }
 
@@ -1416,6 +1654,8 @@ s_chtml40_start_form_tag(void *pdoc, Node *node)
 
   W_L("<form");
   if (attr_action) {
+    attr_action = chxj_encoding_parameter(r, attr_action, 0);
+    attr_action = chxj_add_cookie_parameter(r, attr_action, chtml40->cookie);
     char *q;
     char *new_query_string = NULL;
     q = strchr(attr_action, '?');
@@ -1445,6 +1685,24 @@ s_chtml40_start_form_tag(void *pdoc, Node *node)
   if (new_hidden_tag) {
     W_V(new_hidden_tag);
   }
+
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  if (attr_align) {
+    W_L("<div align=\"");
+    W_V(attr_align);
+    W_L("\">");
+    flg->with_div_flag = 1;
+  }
+  node->userData = flg;
+
   return chtml40->out;
 }
 
@@ -1458,7 +1716,7 @@ s_chtml40_start_form_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_form_tag(void *pdoc, Node *UNUSED(child)) 
+s_chtml40_end_form_tag(void *pdoc, Node *node)
 {
   chtml40_t    *chtml40;
   Doc          *doc;
@@ -1466,7 +1724,17 @@ s_chtml40_end_form_tag(void *pdoc, Node *UNUSED(child))
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
 
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_div_flag) {
+    W_L("</div>");
+  }
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</form>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -1486,96 +1754,148 @@ s_chtml40_start_input_tag(void *pdoc, Node *node)
   chtml40_t   *chtml40;
   Doc         *doc;
   request_rec *r;
-  char        *max_length  = NULL;
-  char        *type        = NULL;
-  char        *name        = NULL;
-  char        *value       = NULL;
-  char        *istyle      = NULL;
-  char        *size        = NULL;
-  char        *checked     = NULL;
-  char        *accesskey   = NULL;
-
-  chtml40   = GET_CHTML40(pdoc);
-  doc       = chtml40->doc;
-  r         = doc->r;
-  W_L("<input");
+  Attr        *attr;
+  char        *attr_accesskey  = NULL;
+  char        *attr_max_length = NULL;
+  char        *attr_type       = NULL;
+  char        *attr_name       = NULL;
+  char        *attr_value      = NULL;
+  char        *attr_istyle     = NULL;
+  char        *attr_size       = NULL;
+  char        *attr_checked    = NULL;
+  char        *attr_style      = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  r       = doc->r;
+
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
-  type       = qs_get_type_attr(doc, node, doc->buf.pool);
-  name       = qs_get_name_attr(doc, node, doc->buf.pool);
-  value      = qs_get_value_attr(doc,node, doc->buf.pool);
-  istyle     = qs_get_istyle_attr(doc,node,doc->buf.pool);
-  max_length = qs_get_maxlength_attr(doc,node,doc->buf.pool);
-  checked    = qs_get_checked_attr(doc,node,doc->buf.pool);
-  accesskey  = qs_get_accesskey_attr(doc, node, doc->buf.pool);
-  size       = qs_get_size_attr(doc, node, doc->buf.pool);
-
-  if (type) {
-    type = qs_trim_string(doc->buf.pool, type);
-    if (type && (STRCASEEQ('t','T',"text",    type) ||
-                 STRCASEEQ('p','P',"password",type) ||
-                 STRCASEEQ('c','C',"checkbox",type) ||
-                 STRCASEEQ('r','R',"radio",   type) ||
-                 STRCASEEQ('h','H',"hidden",  type) ||
-                 STRCASEEQ('s','S',"submit",  type) ||
-                 STRCASEEQ('r','R',"reset",   type))) {
-      W_L(" type=\"");
-      W_V(type);
-      W_L("\"");
+  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('t','T',"type",name) && value && *value) {
+      char *tmp_type = qs_trim_string(doc->buf.pool, value);
+      if (tmp_type && (STRCASEEQ('t','T',"text",    tmp_type) ||
+                       STRCASEEQ('p','P',"password",tmp_type) ||
+                       STRCASEEQ('c','C',"checkbox",tmp_type) ||
+                       STRCASEEQ('r','R',"radio",   tmp_type) ||
+                       STRCASEEQ('h','H',"hidden",  tmp_type) ||
+                       STRCASEEQ('s','S',"submit",  tmp_type) ||
+                       STRCASEEQ('r','R',"reset",   tmp_type))) {
+        attr_type = tmp_type;
+      }
+    }
+    else if (STRCASEEQ('n','N',"name",name) && value && *value) {
+      attr_name = value;
+    }
+    else if (STRCASEEQ('v','V',"value",name) && value && *value) {
+      attr_value = value;
+    }
+    else if (STRCASEEQ('i','I',"istyle",name) && value && *value) {
+      attr_istyle = value;
+    }
+    else if (STRCASEEQ('m','M',"maxlength",name) && value && *value) {
+      attr_max_length = value;
+    }
+    else if (STRCASEEQ('c','C',"checked", name)) {
+      attr_checked = value;
+    }
+    else if (STRCASEEQ('a','A',"accesskey", name) && value && *value) {
+      attr_accesskey = value;
+    }
+    else if (STRCASEEQ('s','S',"size", name) && value && *value) {
+      attr_size = value;
+    }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
     }
   }
-  if (size && *size) {
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
+      css_property_t *cur;
+      for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
+        if (strcasestr(cur->value, "<ja:n>")) {
+          attr_istyle = "4";
+        }
+        else if (strcasestr(cur->value, "<ja:en>")) {
+          attr_istyle = "3";
+        }
+        else if (strcasestr(cur->value, "<ja:hk>")) {
+          attr_istyle = "2";
+        }
+        else if (strcasestr(cur->value, "<ja:h>")) {
+          attr_istyle = "1";
+        }
+      }
+    }
+  }
+
+  W_L("<input");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
+  }
+  if (attr_size) {
     W_L(" size=\"");
-    W_V(size);
+    W_V(attr_size);
     W_L("\"");
   }
-  if (name && *name) {
+  if (attr_name) {
     W_L(" name=\"");
-    W_V(name);
+    W_V(attr_name);
     W_L("\"");
   }
-  if (value && *value) {
+  if (attr_value) {
+    if (attr_type && (STRCASEEQ('s','S',"submit",attr_type) || STRCASEEQ('r','R',"reset",attr_type))) {
+      apr_size_t value_len = strlen(attr_value);
+      attr_value = chxj_conv_z2h(r, attr_value, &value_len, chtml40->entryp);
+    }
+
     W_L(" value=\"");
-    W_V(chxj_add_slash_to_doublequote(doc->pool, value));
+    W_V(chxj_add_slash_to_doublequote(doc->pool, attr_value));
     W_L("\"");
   }
-  if (accesskey && *accesskey) {
+  if (attr_accesskey) {
     W_L(" accesskey=\"");
-    W_V(accesskey);
+    W_V(attr_accesskey);
     W_L("\"");
   }
-  if (istyle) {
-    /*------------------------------------------------------------------------*/
-    /* CHTML 2.0                                                              */
-    /*------------------------------------------------------------------------*/
-    if (*istyle == '1' || *istyle == '2' || *istyle == '3' || *istyle == '4') {
+  if (attr_istyle) {
+    if (*attr_istyle == '1' || *attr_istyle == '2' || *attr_istyle == '3' || *attr_istyle == '4') {
       W_L(" istyle=\"");
-      W_V(istyle);
+      W_V(attr_istyle);
       W_L("\"");
     }
   }
-
   /*--------------------------------------------------------------------------*/
   /* The figure is default for the password.                                  */
   /*--------------------------------------------------------------------------*/
-  if (max_length && *max_length) {
-    if (chxj_chk_numeric(max_length) != 0) {
-      max_length = apr_psprintf(r->pool, "0");
+  if (attr_max_length) {
+    if (chxj_chk_numeric(attr_max_length) != 0) {
+      attr_max_length = apr_psprintf(doc->buf.pool, "0");
     }
-    if (istyle != NULL && *istyle == '1') {
-      char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length) * 2);
+    if (attr_istyle && *attr_istyle == '1') {
+      char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(attr_max_length) * 2);
       W_V(vv);
     }
-    else  {
-      char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length));
+    else {
+      char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(attr_max_length));
       W_V(vv);
     }
   }
-  if (checked) {
+  if (attr_checked) {
     W_L(" checked");
   }
   W_L(">");
+
   return chtml40->out;
 }
 
@@ -1606,15 +1926,50 @@ s_chtml40_end_input_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_center_tag(void *pdoc, Node *UNUSED(node)) 
+s_chtml40_start_center_tag(void *pdoc, Node *node)
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_color = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
 
+  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('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
+
   W_L("<center>");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = flg;
 
   return chtml40->out;
 }
@@ -1629,7 +1984,7 @@ s_chtml40_start_center_tag(void *pdoc, Node *UNUSED(node))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_center_tag(void *pdoc, Node *UNUSED(child)) 
+s_chtml40_end_center_tag(void *pdoc, Node *node)
 {
   chtml40_t     *chtml40;
   Doc           *doc;
@@ -1637,6 +1992,13 @@ s_chtml40_end_center_tag(void *pdoc, Node *UNUSED(child))
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
 
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</center>");
 
   return chtml40->out;
@@ -1658,72 +2020,157 @@ s_chtml40_start_hr_tag(void *pdoc, Node *node)
   chtml40_t   *chtml40;
   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;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<hr");
   for (attr = qs_get_attr(doc,node);
        attr; 
        attr = qs_get_next_attr(doc,attr)) {
-    char *name = qs_get_attr_name(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("\"");
+    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;
+        }
       }
-    }
-    else if (STRCASEEQ('s','S',"size", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      if (value && *value) {
-        W_L(" size=\"");
-        W_V(value);
-        W_L("\"");
+      break;
+
+    case 's':
+    case 'S':
+      if (strcasecmp(name, "size") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value && *value) {
+          attr_size = value;
+        }
       }
-    }
-    else if (STRCASEEQ('w','W',"width", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      if (value && *value) {
-        W_L(" width=\"");
-        W_V(value);
-        W_L("\"");
+      else if (strcasecmp(name, "style") == 0) {
+        if (value && *value) {
+          attr_style = value;
+        }
       }
-    }
-    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(">");
-  return chtml40->out;
-}
+      break;
 
+    case 'w':
+    case 'W':
+      if (strcasecmp(name, "width") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value && *value) {
+          attr_width = value;
+        }
+      }
+      break;
 
-/**
- * It is a handler who processes the HR tag.
- *
- * @param pdoc  [i/o] The pointer to the CHTML structure at the output
+    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(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_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("<hr");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
+  if (attr_size) {
+    W_L(" size=\"");
+    W_V(attr_size);
+    W_L("\"");
+  }
+  if (attr_width) {
+    W_L(" width=\"");
+    W_V(attr_width);
+    W_L("\"");
+  }
+  if (attr_color) {
+    W_L(" color=\"");
+    W_V(attr_color);
+    W_L("\"");
+  }
+  if (attr_noshade) {
+    W_L(" noshade");
+  }
+  W_L(">");
+  return chtml40->out;
+}
+
+
+/**
+ * It is a handler who processes the HR tag.
+ *
+ * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
  * @param node   [i]   The HR tag node is specified.
  * @return The conversion result is returned.
@@ -1748,108 +2195,191 @@ s_chtml40_end_hr_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_img_tag(void *pdoc, Node *node) 
 {
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_src    = NULL;
+  char        *attr_align  = NULL;
+  char        *attr_style  = NULL;
+  char        *attr_alt    = NULL;
+  char        *attr_width  = NULL;
+  char        *attr_height = NULL;
+  char        *attr_hspace = NULL;
+  char        *attr_vspace = NULL;
 #ifndef IMG_NOT_CONVERT_FILENAME
   device_table *spec;
 #endif
-  chtml40_t    *chtml40;
-  Doc          *doc;
-  request_rec  *r;
-  Attr         *attr;
 
   chtml40 = GET_CHTML40(pdoc);
-  doc     = chtml40->doc;
-  r       = doc->r;
 #ifndef IMG_NOT_CONVERT_FILENAME
   spec    = chtml40->spec;
 #endif
+  doc     = chtml40->doc;
+  r       = doc->r;
 
-  W_L("<img");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
-    char *name  = qs_get_attr_name(doc,attr);
+    char *name  = qs_get_attr_name (doc,attr);
     char *value = qs_get_attr_value(doc,attr);
-    if (STRCASEEQ('s','S',"src", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
+    switch(*name) {
+    case 's':
+    case 'S':
+      if (strcasecmp(name, "src") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
 #ifdef IMG_NOT_CONVERT_FILENAME
-      value = chxj_encoding_parameter(r, value);
+      value = chxj_encoding_parameter(r, value, 0);
       value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
       value = chxj_add_cookie_no_update_parameter(r, value);
-      W_L(" src=\"");
-      W_V(value);
-      W_L("\"");
-
+      value = chxj_img_rewrite_parameter(r,chtml40->conf,value);
+      attr_src = value;
 #else
       value = chxj_img_conv(r,spec,value);
-      value = chxj_encoding_parameter(r, value);
+      value = chxj_encoding_parameter(r, value, 0);
       value = chxj_add_cookie_parameter(r, value, chtml40->cookie);
       value = chxj_add_cookie_no_update_parameter(r, value);
-      W_L(" src=\"");
-      W_V(value);
-      W_L("\"");
+      value = chxj_img_rewrite_parameter(r,chtml40->conf,value);
+      attr_src = value;
 #endif
-    }
-    else if (STRCASEEQ('a','A',"align", name)) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      if (value && (STRCASEEQ('t','T',"top",    value) ||
-                    STRCASEEQ('m','M',"middle", value) ||
-                    STRCASEEQ('b','B',"bottom", value) ||
-                    STRCASEEQ('l','L',"left",   value) ||
-                    STRCASEEQ('c','C',"center", value) ||
-                    STRCASEEQ('r','R',"right",  value))) {
-        W_L(" align=\"");
-        W_V(value);
-        W_L("\"");
       }
+      else if (strcasecmp(name,"style") == 0 && value && *value) {
+        attr_style = value;
+      }
+      break;
+
+    case 'a':
+    case 'A':
+      if (strcasecmp(name, "align" ) == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        /*--------------------------------------------------------------------*/
+        /* CHTML 4.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value) {
+          if (STRCASEEQ('t','T',"top",   value) ||
+              STRCASEEQ('m','M',"middle",value) ||
+              STRCASEEQ('b','B',"bottom",value) ||
+              STRCASEEQ('l','L',"left",  value) ||
+              STRCASEEQ('r','R',"right", value)) {
+            attr_align = value;
+          }
+          else if (STRCASEEQ('c','C',"center",  value)) {
+            attr_align = apr_pstrdup(doc->pool, "middle");
+          }
+        }
+      }
+      else if (strcasecmp(name, "alt"   ) == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_alt = value;
+      }
+      break;
+
+    case 'w':
+    case 'W':
+      if (strcasecmp(name, "width" ) == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_width = value;
+      }
+      break;
+
+    case 'h':
+    case 'H':
+      if (strcasecmp(name, "height") == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_height = value;
+      }
+      else
+      if (strcasecmp(name, "hspace") == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_hspace = value;
+      }
+      break;
+
+    case 'v':
+    case 'V':
+      if (strcasecmp(name, "vspace") == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_vspace = value;
+      }
+      break;
+
+    default:
+      break;
     }
-    else if (STRCASEEQ('w','W',"width", name) && value && *value) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      W_L(" width=\"");
-      W_V(value);
-      W_L("\"");
-    }
-    else if (STRCASEEQ('h','H', "height", name) && value && *value) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      W_L(" height=\"");
-      W_V(value);
-      W_L("\"");
-    }
-    else if (STRCASEEQ('h','H',"hspace", name) && value && *value) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      W_L(" hspace=\"");
-      W_V(value);
-      W_L("\"");
-    }
-    else if (STRCASEEQ('v','V',"vspace", name) && value && *value) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      W_L(" vspace=\"");
-      W_V(value);
-      W_L("\"");
-    }
-    else if (STRCASEEQ('a','A',"alt",name) && value && *value) {
-      /*----------------------------------------------------------------------*/
-      /* CHTML 1.0                                                            */
-      /*----------------------------------------------------------------------*/
-      W_L(" alt=\"");
-      W_V(value);
-      W_L("\"");
+  }
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style);
+    if (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 *valign_prop = chxj_css_get_property_value(doc, style, "vertical-align");
+      css_property_t *cur;
+      for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
+        attr_height = apr_pstrdup(doc->pool, cur->value);
+      }
+      for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
+        attr_width = apr_pstrdup(doc->pool, cur->value);
+      }
+      for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) {
+        attr_align = apr_pstrdup(doc->pool, cur->value);
+      }
     }
   }
+
+  W_L("<img");
+  if (attr_src) {
+    W_L(" src=\"");
+    W_V(attr_src);
+    W_L("\"");
+  }
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
+  if (attr_alt) {
+    W_L(" alt=\"");
+    W_V(attr_alt);
+    W_L("\"");
+  }
+  if (attr_width) {
+    W_L(" width=\"");
+    W_V(attr_width);
+    W_L("\"");
+  }
+  if (attr_height) {
+    W_L(" height=\"");
+    W_V(attr_height);
+    W_L("\"");
+  }
+  if (attr_hspace) {
+    W_L(" hspace=\"");
+    W_V(attr_hspace);
+    W_L("\"");
+  }
+  if (attr_vspace) {
+    W_L(" vspace=\"");
+    W_V(attr_vspace);
+    W_L("\"");
+  }
   W_L(">");
   return chtml40->out;
 }
@@ -1881,7 +2411,7 @@ s_chtml40_end_img_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_select_tag(void *pdoc, Node *child)
+s_chtml40_start_select_tag(void *pdoc, Node *node)
 {
   chtml40_t   *chtml40  = GET_CHTML40(pdoc);
   Doc         *doc      = chtml40->doc;
@@ -1889,9 +2419,10 @@ s_chtml40_start_select_tag(void *pdoc, Node *child)
   char        *name     = NULL;
   char        *multiple = NULL;
   Attr        *attr;
+  char        *attr_style = NULL;
 
   W_L("<select");
-  for (attr = qs_get_attr(doc,child);
+  for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
     char *nm  = qs_get_attr_name(doc,attr);
@@ -1902,6 +2433,12 @@ s_chtml40_start_select_tag(void *pdoc, Node *child)
       /*----------------------------------------------------------------------*/
       size = apr_pstrdup(doc->buf.pool, val);
     }
+    else if (STRCASEEQ('s','S',"style", nm) && val && *val) {
+      /*----------------------------------------------------------------------*/
+      /* CHTML 1.0 version 2.0                                                */
+      /*----------------------------------------------------------------------*/
+      attr_style = apr_pstrdup(doc->buf.pool, val);
+    }
     else if (STRCASEEQ('n','N',"name", nm)) {
       /*----------------------------------------------------------------------*/
       /* CHTML 1.0 version 2.0                                                */
@@ -1929,6 +2466,9 @@ s_chtml40_start_select_tag(void *pdoc, Node *child)
     W_L(" multiple");
   }
   W_L(">");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+  }
   return chtml40->out;
 }
 
@@ -1948,6 +2488,9 @@ s_chtml40_end_select_tag(void *pdoc, Node *UNUSED(child))
   Doc          *doc   = chtml40->doc;
 
   W_L("</select>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -1961,7 +2504,7 @@ s_chtml40_end_select_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_option_tag(void *pdoc, Node *child)
+s_chtml40_start_option_tag(void *pdoc, Node *node)
 {
   Attr        *attr;
   chtml40_t   *chtml40;
@@ -1969,6 +2512,7 @@ s_chtml40_start_option_tag(void *pdoc, Node *child)
   request_rec *r;
   char        *selected;
   char        *value;
+  char        *attr_style = NULL;
 
   chtml40    = GET_CHTML40(pdoc);
   doc        = chtml40->doc;
@@ -1977,7 +2521,7 @@ s_chtml40_start_option_tag(void *pdoc, Node *child)
   value      = NULL;
 
   W_L("<option");
-  for (attr = qs_get_attr(doc,child);
+  for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
     char *nm  = qs_get_attr_name(doc,attr);
@@ -1988,6 +2532,12 @@ s_chtml40_start_option_tag(void *pdoc, Node *child)
       /*----------------------------------------------------------------------*/
       selected = apr_pstrdup(doc->buf.pool, val);
     }
+    else if (STRCASEEQ('s','S',"style", nm) && val && *val) {
+      /*----------------------------------------------------------------------*/
+      /* CHTML 1.0 version 2.0                                                */
+      /*----------------------------------------------------------------------*/
+      attr_style = apr_pstrdup(doc->buf.pool, val);
+    }
     else if (STRCASEEQ('v','V',"value", nm)) {
       /*----------------------------------------------------------------------*/
       /* CHTML 1.0 version 2.0                                                */
@@ -2004,6 +2554,11 @@ s_chtml40_start_option_tag(void *pdoc, Node *child)
     W_L(" selected");
   }
   W_L(">");
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+  }
+
   return chtml40->out;
 }
 
@@ -2022,6 +2577,9 @@ s_chtml40_end_option_tag(void *pdoc, Node *UNUSED(child))
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
 
   /* Don't close */
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2036,40 +2594,165 @@ s_chtml40_end_option_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_div_tag(void *pdoc, Node *child)
+s_chtml40_start_div_tag(void *pdoc, Node *node)
 {
-  Attr          *attr;
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  char          *align;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_style             = NULL;
+  char        *attr_align             = NULL;
+  char        *attr_display           = NULL;
+  char        *attr_decoration        = NULL;
+  char        *attr_wap_marquee_style = NULL;
+  char        *attr_wap_marquee_dir   = NULL;
+  char        *attr_wap_marquee_loop  = NULL;
+  char        *attr_color             = NULL;
+  char        *attr_bgcolor           = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
-  align   = NULL;
 
-  W_L("<div");
-  for (attr = qs_get_attr(doc,child);
+  for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
     char *nm  = qs_get_attr_name(doc,attr);
     char *val = qs_get_attr_value(doc,attr);
-    if (STRCASEEQ('a','A',"align", nm)) {
+    if (STRCASEEQ('a','A', "align", nm)) {
       /*----------------------------------------------------------------------*/
       /* 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);
       }
     }
+    else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
+      attr_style = apr_pstrdup(doc->buf.pool, val);
+    }
   }
-  if (align) {
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *display_prop           = chxj_css_get_property_value(doc, style, "display");
+      css_property_t *text_decoration_prop   = chxj_css_get_property_value(doc, style, "text-decoration");
+      css_property_t *color_prop             = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *text_align_prop        = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *background_color_prop  = chxj_css_get_property_value(doc, style, "background-color");
+      css_property_t *background_prop        = chxj_css_get_property_value(doc, style, "background");
+
+      css_property_t *cur;
+      for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
+        if (strcasecmp("-wap-marquee", cur->value) == 0) {
+          attr_display = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = text_decoration_prop->next; cur != text_decoration_prop; cur = cur->next) {
+        if (STRCASEEQ('b','B',"blink", cur->value)) {
+          attr_decoration = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        attr_color = apr_pstrdup(doc->pool, cur->value);
+        attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+      }
+      for (cur = background_color_prop->next; cur != background_color_prop; cur = cur->next) {
+        attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
+        attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
+      }
+      for (cur = background_prop->next; cur != background_prop; cur = cur->next) {
+        char *ss = strchr(cur->value, '#');
+        if (!ss) {
+          ss = strstr(cur->value, "rgb");
+        }
+        if (ss) {
+          attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
+          attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
+        }
+      }
+      for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
+        attr_align = apr_pstrdup(doc->pool, cur->value);
+      }
+      if (attr_display) {
+        css_property_t *wap_marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
+        css_property_t *wap_marquee_dir_prop   = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
+        css_property_t *wap_marquee_loop_prop  = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
+        for (cur = wap_marquee_style_prop->next; cur != wap_marquee_style_prop; cur = cur->next) {
+          if (STRCASEEQ('s','S',"scroll", cur->value) || STRCASEEQ('s','S',"slide",cur->value) || STRCASEEQ('a','A',"alternate",cur->value)) {
+            attr_wap_marquee_style = apr_pstrdup(doc->pool, cur->value);
+          }
+        }
+        for (cur = wap_marquee_dir_prop->next; cur != wap_marquee_dir_prop; cur = cur->next) {
+          if (STRCASEEQ('l','L',"ltr",cur->value)) {
+            attr_wap_marquee_dir = apr_pstrdup(doc->pool, "right");
+          }
+          else if (STRCASEEQ('r','R',"rtl",cur->value)) {
+            attr_wap_marquee_dir = apr_pstrdup(doc->pool, "left");
+          }
+        }
+        for (cur = wap_marquee_loop_prop->next; cur != wap_marquee_loop_prop; cur = cur->next) {
+          if (STRCASEEQ('i','I',"infinite",cur->value)) {
+            attr_wap_marquee_loop = apr_pstrdup(doc->pool, "16");
+          }
+          else {
+            attr_wap_marquee_loop = apr_pstrdup(doc->pool, cur->value);
+          }
+        }
+      }
+    }
+  }  
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_align) {
+    W_L("<div");
     W_L(" align=\"");
-    W_V(align);
+    W_V(attr_align);
     W_L("\"");
+    W_L(">");
+    flg->with_div_flag = 1;
   }
-  W_L(">");
+  else {
+    W_L("<div>");
+    flg->with_div_flag = 1;
+  }
+  if (attr_color) {
+    if (attr_bgcolor && (STRCASEEQ('w','W',"white",attr_color) || STRCASEEQ('#','#',"#ffffff",attr_color))) {
+      /* nothing */
+    }
+    else {
+      W_L("<font color=\"");
+      W_V(attr_color);
+      W_L("\">");
+      flg->with_font_flag = 1;
+    }
+  }
+  if (attr_decoration) {
+    W_L("<blink>");
+    flg->with_blink_flag = 1;
+  }
+  if (attr_display) {
+    W_L("<marquee");
+    if (attr_wap_marquee_style) {
+      W_L(" behavior=\"");
+      W_V(attr_wap_marquee_style);
+      W_L("\"");
+    }
+    if (attr_wap_marquee_dir) {
+      W_L(" direction=\"");
+      W_V(attr_wap_marquee_dir);
+      W_L("\"");
+    }
+    if (attr_wap_marquee_loop) {
+      W_L(" loop=\"");
+      W_V(attr_wap_marquee_loop);
+      W_L("\"");
+    }
+    W_L(">");
+    flg->with_marquee_flag = 1;
+  }
+  node->userData = flg;
+
   return chtml40->out;
 }
 
@@ -2083,12 +2766,28 @@ s_chtml40_start_div_tag(void *pdoc, Node *child)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_div_tag(void *pdoc, Node *UNUSED(node))
+s_chtml40_end_div_tag(void *pdoc, Node *node)
 {
   chtml40_t    *chtml40 = GET_CHTML40(pdoc);
   Doc          *doc     = chtml40->doc;
 
-  W_L("</div>");
+  chtml40_flags_t *flg = node->userData;
+  if (flg && flg->with_marquee_flag) {
+    W_L("</marquee>");
+  }
+  if (flg && flg->with_blink_flag) {
+    W_L("</blink>");
+  }
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
+  if (flg && flg->with_div_flag) {
+    W_L("</div>");
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
+  node->userData = NULL;
 
   return chtml40->out;
 }
@@ -2108,7 +2807,8 @@ s_chtml40_start_ul_tag(void *pdoc, Node *node)
   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
   Doc         *doc     = chtml40->doc;
   Attr        *attr;
-  W_L("<ul");
+  char        *attr_type = NULL;
+  char        *attr_style = NULL;
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -2119,12 +2819,37 @@ s_chtml40_start_ul_tag(void *pdoc, Node *node)
     char *value  = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('t','T',"type",name)) {
       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
-        W_L(" type=\"");
-        W_V(value);
-        W_L("\"");
+        attr_type = value;
+      }
+    }
+    else if (value && *value && STRCASEEQ('s','S',"style", name)) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
+        if (STRCASEEQ('d','D',"disc",cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "disc");
+        }
+        else if (STRCASEEQ('c','C',"circle",cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "circle");
+        }
+        else if (STRCASEEQ('s','S',"square",cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "square");
+        }
       }
     }
   }
+  W_L("<ul");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
+  }
   W_L(">");
 
   return chtml40->out;
@@ -2146,6 +2871,9 @@ s_chtml40_end_ul_tag(void *pdoc, Node *UNUSED(child))
   Doc           *doc     = chtml40->doc;
 
   W_L("</ul>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2160,10 +2888,26 @@ s_chtml40_end_ul_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_pre_tag(void *pdoc, Node *UNUSED(node)) 
+s_chtml40_start_pre_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc     = chtml40->doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+
+  if (IS_CSS_ON(chtml40->entryp)) {
+    s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+  }
 
   chtml40->pre_flag++;
   W_L("<pre>");
@@ -2188,6 +2932,9 @@ s_chtml40_end_pre_tag(void *pdoc, Node *UNUSED(child))
 
   W_L("</pre>");
   chtml40->pre_flag--;
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2204,17 +2951,19 @@ s_chtml40_end_pre_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_p_tag(void *pdoc, Node *node) 
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
-  char          *align = NULL;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_align = NULL;
+  char        *attr_style = NULL;
+  char        *attr_color = NULL;
+  char        *attr_blink = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<p");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2225,18 +2974,68 @@ s_chtml40_start_p_tag(void *pdoc, Node *node)
       /* 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 (STRCASEEQ('s','S',"style", nm) && val && *val) {
+      attr_style = apr_pstrdup(doc->buf.pool, val);
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *text_deco_prop  = chxj_css_get_property_value(doc, style, "text-decoration");
+      css_property_t *cur;
+      for (cur = text_align_prop->next; cur != text_align_prop; 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");
+        }
+      }
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = text_deco_prop->next; cur != text_deco_prop; cur = cur->next) {
+        if (cur->value && *cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
+          attr_blink = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
   }
-  if (align) {
+  W_L("<p");
+  if (attr_align) {
     W_L(" align=\"");
-    W_V(align);
+    W_V(attr_align);
     W_L("\"");
   }
   W_L(">");
-  return chtml40->out;
+
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  if (attr_blink) {
+    W_L("<blink>");
+    flg->with_blink_flag = 1;
+  }
+  node->userData = (void *)flg;
+
+  return chtml40->out;
 }
 
 
@@ -2249,7 +3048,7 @@ s_chtml40_start_p_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_p_tag(void *pdoc, Node *UNUSED(child)) 
+s_chtml40_end_p_tag(void *pdoc, Node *node)
 {
   chtml40_t   *chtml40;
   Doc         *doc;
@@ -2257,7 +3056,17 @@ s_chtml40_end_p_tag(void *pdoc, Node *UNUSED(child))
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
 
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg->with_font_flag) {
+    W_L("</font>");
+  }
+  if (flg->with_blink_flag) {
+    W_L("</blink>");
+  }
   W_L("</p>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2274,16 +3083,18 @@ s_chtml40_end_p_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_ol_tag(void *pdoc, Node *node)
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_start = NULL;
+  char        *attr_type = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<ol");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -2293,15 +3104,43 @@ s_chtml40_start_ol_tag(void *pdoc, Node *node)
     char *name = qs_get_attr_name(doc,attr);
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('t','T',"type",name) && value && (*value == '1' || *value == 'a' || *value == 'A')) {
-      W_L(" type=\"");
-      W_V(value);
-      W_L("\"");
+      attr_type = value;
     }
     else if (STRCASEEQ('s','S',"start",name) && value && *value) {
-      W_L(" start=\"");
-      W_V(value);
-      W_L("\"");
+      attr_start = value;
     }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
+        if (STRCASEEQ('d','D',"decimal", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "1");
+        }
+        else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "A");
+        }
+        else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "a");
+        }
+      }
+    }
+  }
+  W_L("<ol");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
+  }
+  if (attr_start) {
+    W_L(" start=\"");
+    W_V(attr_start);
+    W_L("\"");
   }
   W_L(">");
 
@@ -2324,6 +3163,9 @@ s_chtml40_end_ol_tag(void *pdoc, Node *UNUSED(node))
   Doc       *doc     = chtml40->doc;
 
   W_L("</ol>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2343,29 +3185,69 @@ s_chtml40_start_li_tag(void *pdoc, Node *node)
   chtml40_t   *chtml40 = GET_CHTML40(pdoc);
   Doc         *doc     = chtml40->doc;
   Attr        *attr;
+  char        *attr_type = NULL;
+  char        *attr_value = NULL;
+  char        *attr_style = NULL;
 
-  W_L("<li");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
-    char *name = qs_get_attr_name(doc,attr);
+    char *name  = qs_get_attr_name(doc,attr);
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('t','T',"type",name)) {
       if (value && (*value == '1' || *value == 'a' || *value == 'A' || STRCASEEQ('d','D',"disc",value) || STRCASEEQ('s','S',"square",value) || STRCASEEQ('c','C',"circle",value))) {
-        W_L(" type=\"");
-        W_V(value);
-        W_L("\"");
+        attr_type = value;
       }
     }
     else if (STRCASEEQ('v','V',"value", name) && value && *value) {
-      W_L(" value=\"");
-      W_V(value);
-      W_L("\"");
+      attr_value = value;
+    }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
+        if (STRCASEEQ('d','D',"decimal", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "1");
+        }
+        else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "A");
+        }
+        else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "a");
+        }
+        else if (STRCASEEQ('d','D',"disc", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "disc");
+        }
+        else if (STRCASEEQ('s','S',"square", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "square");
+        }
+        else if (STRCASEEQ('c','C',"circle", cur->value)) {
+          attr_type = apr_pstrdup(doc->pool, "circle");
+        }
+      }
     }
   }
+
+  W_L("<li");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
+  }
+  if (attr_value) {
+    W_L(" value=\"");
+    W_V(attr_value);
+    W_L("\"");
+  }
   W_L(">");
   return chtml40->out;
 }
@@ -2384,6 +3266,9 @@ s_chtml40_end_li_tag(void *pdoc, Node *UNUSED(child))
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
 
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -2399,30 +3284,55 @@ s_chtml40_end_li_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_h1_tag(void *pdoc, Node *node)
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h1");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
-    char *name = qs_get_attr_name(doc,attr);
+    char *name  = qs_get_attr_name(doc,attr);
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h1");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
 
   return chtml40->out;
@@ -2447,6 +3357,9 @@ s_chtml40_end_h1_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml40->doc;
 
   W_L("</h1>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2463,16 +3376,17 @@ s_chtml40_end_h1_tag(void *pdoc, Node *UNUSED(child))
 static char *
 s_chtml40_start_h2_tag(void *pdoc, Node *node)
 {
-  chtml40_t     *chtml40;
-  Doc           *doc;
-  request_rec   *r;
-  Attr          *attr;
+  chtml40_t   *chtml40;
+  Doc         *doc;
+  request_rec *r;
+  Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h2");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2480,14 +3394,39 @@ s_chtml40_start_h2_tag(void *pdoc, Node *node)
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h2");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
+
   return chtml40->out;
 }
 
@@ -2507,6 +3446,9 @@ s_chtml40_end_h2_tag(void *pdoc, Node *UNUSED(child))
   Doc         *doc     = chtml40->doc;
 
   W_L("</h2>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2527,12 +3469,13 @@ s_chtml40_start_h3_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h3");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2540,13 +3483,37 @@ s_chtml40_start_h3_tag(void *pdoc, Node *node)
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h3");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
 
   return chtml40->out;
@@ -2568,6 +3535,9 @@ s_chtml40_end_h3_tag(void *pdoc, Node *UNUSED(child))
   Doc       *doc   = chtml40->doc;
 
   W_L("</h3>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2588,12 +3558,13 @@ s_chtml40_start_h4_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h4");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2601,14 +3572,39 @@ s_chtml40_start_h4_tag(void *pdoc, Node *node)
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h4");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
+
   return chtml40->out;
 }
 
@@ -2628,6 +3624,9 @@ s_chtml40_end_h4_tag(void *pdoc, Node *UNUSED(child))
   Doc       *doc     = chtml40->doc;
 
   W_L("</h4>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2648,12 +3647,13 @@ s_chtml40_start_h5_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h5");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2661,14 +3661,39 @@ s_chtml40_start_h5_tag(void *pdoc, Node *node)
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h5");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
+
   return chtml40->out;
 }
 
@@ -2688,6 +3713,9 @@ s_chtml40_end_h5_tag(void *pdoc, Node *UNUSED(child))
   Doc       *doc     = chtml40->doc;
 
   W_L("</h5>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2708,12 +3736,13 @@ s_chtml40_start_h6_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_style = NULL;
+  char        *attr_align = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
-  W_L("<h6");
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2721,14 +3750,39 @@ s_chtml40_start_h6_tag(void *pdoc, Node *node)
     char *value = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('a','A',"align", name)) {
       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("\"");
-        break;
+        attr_align = value;
+      }
+    }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *cur;
+      for (cur = list_style_type_prop->next; cur != list_style_type_prop; 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("<h6");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
   W_L(">");
+
   return chtml40->out;
 }
 
@@ -2748,6 +3802,9 @@ s_chtml40_end_h6_tag(void *pdoc, Node *UNUSED(child))
   Doc       *doc     = chtml40->doc;
 
   W_L("</h6>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
 
   return chtml40->out;
 }
@@ -2768,6 +3825,12 @@ s_chtml40_start_textarea_tag(void *pdoc, Node *node)
   Doc           *doc;
   request_rec   *r;
   Attr          *attr;
+  char          *attr_accesskey = NULL;
+  char          *attr_name      = NULL;
+  char          *attr_rows      = NULL;
+  char          *attr_cols      = NULL;
+  char          *attr_istyle    = NULL;
+  char          *attr_style     = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
@@ -2775,38 +3838,77 @@ s_chtml40_start_textarea_tag(void *pdoc, Node *node)
 
   chtml40->textarea_flag++;
 
-  W_L("<textarea");
   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',"accesskey",name) && value && *value != 0) {
-      W_L(" accesskey=\"");
-      W_V(value);
-      W_L("\"");
+      attr_accesskey = value;
     }
     else if (STRCASEEQ('i','I',"istyle", name) && value && (*value == '1' || *value == '2' || *value == '3' || *value == '4')) {
-      W_L(" istyle=\"");
-      W_V(value);
-      W_L("\"");
+      attr_istyle = value;
     }
     else if (STRCASEEQ('n','N',"name", name) && value && *value) {
-      W_L(" name=\"");
-      W_V(value);
-      W_L("\"");
+      attr_name = value;
     }
     else if (STRCASEEQ('r','R',"rows", name) && value && *value) {
-      W_L(" rows=\"");
-      W_V(value);
-      W_L("\"");
+      attr_rows = value;
     }
     else if (STRCASEEQ('c','C',"cols", name) && value && *value) {
-      W_L(" cols=\"");
-      W_V(value);
-      W_L("\"");
+      attr_cols = value;
+    }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
+      css_property_t *cur;
+      for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
+        if (strcasestr(cur->value, "<ja:n>")) {
+          attr_istyle = "4";
+        }
+        else if (strcasestr(cur->value, "<ja:en>")) {
+          attr_istyle = "3";
+        }
+        else if (strcasestr(cur->value, "<ja:hk>")) {
+          attr_istyle = "2";
+        }
+        else if (strcasestr(cur->value, "<ja:h>")) {
+          attr_istyle = "1";
+        }
+      }
     }
   }
+  W_L("<textarea");
+  if (attr_accesskey) {
+    W_L(" accesskey=\"");
+    W_V(attr_accesskey);
+    W_L("\"");
+  }
+  if (attr_name) {
+    W_L(" name=\"");
+    W_V(attr_name);
+    W_L("\"");
+  }
+  if (attr_rows) {
+    W_L(" rows=\"");
+    W_V(attr_rows);
+    W_L("\"");
+  }
+  if (attr_cols) {
+    W_L(" cols=\"");
+    W_V(attr_cols);
+    W_L("\"");
+  }
+  if (attr_istyle) {
+    W_L(" istyle=\"");
+    W_V(attr_istyle);
+    W_L("\"");
+  }
   W_L(">");
   return chtml40->out;
 }
@@ -2869,6 +3971,7 @@ s_chtml40_text_tag(void *pdoc, Node *child)
   char        one_byte[2];
   int         ii;
   int         tdst_len;
+  apr_size_t  z2h_input_len;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
@@ -2888,7 +3991,7 @@ s_chtml40_text_tag(void *pdoc, Node *child)
   
   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
     char* out;
-    int rtn = s_chtml40_search_emoji(chtml40, &textval[ii], &out);
+    int rtn = s_chtml40_search_emoji(chtml40, &textval[ii], &out, child);
     if (rtn) {
       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
       ii+=(rtn - 1);
@@ -2915,6 +4018,8 @@ s_chtml40_text_tag(void *pdoc, Node *child)
       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
     }
   }
+  z2h_input_len = strlen(tdst);
+  tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, chtml40->entryp);
   W_V(tdst);
   return chtml40->out;
 }
@@ -2929,11 +4034,48 @@ s_chtml40_text_tag(void *pdoc, Node *child)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_blockquote_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_start_blockquote_tag(void *pdoc, Node *node)
 {
-  chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc     = chtml40->doc;
+  chtml40_t *chtml40;
+  Doc       *doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
   W_L("<blockquote>");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -2947,11 +4089,18 @@ s_chtml40_start_blockquote_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_blockquote_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_blockquote_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</blockquote>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -2970,7 +4119,9 @@ s_chtml40_start_dir_tag(void *pdoc, Node *node)
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc     = chtml40->doc;
   Attr      *attr;
-  W_L("<dir");
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
+  char      *attr_type  = NULL;
   for (attr = qs_get_attr(doc,node);
        attr;
        attr = qs_get_next_attr(doc,attr)) {
@@ -2978,13 +4129,31 @@ s_chtml40_start_dir_tag(void *pdoc, Node *node)
     char *value  = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('t','T',"type",name)) {
       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
-        W_L(" type=\"");
-        W_V(value);
-        W_L("\"");
+        attr_type = value;
       }
     }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  CHTML40_GET_CSS_COLOR_AND_LIST_STYLE_TYPE();
+  W_L("<dir");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
   }
   W_L(">");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -2998,11 +4167,18 @@ s_chtml40_start_dir_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_dir_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_dir_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</dir>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3016,12 +4192,49 @@ s_chtml40_end_dir_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_dl_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_start_dl_tag(void *pdoc, Node *node)
 {
-  chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc     = chtml40->doc;
-  W_L("<dl>");
-  return chtml40->out;
+  chtml40_t *chtml40;
+  Doc       *doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
+  W_L("<dl>");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
+  return chtml40->out;
 }
 
 
@@ -3034,11 +4247,18 @@ s_chtml40_start_dl_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_dl_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_dl_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</dl>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3052,11 +4272,48 @@ s_chtml40_end_dl_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_dt_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_start_dt_tag(void *pdoc, Node *node)
 {
-  chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc     = chtml40->doc;
+  chtml40_t *chtml40;
+  Doc       *doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
   W_L("<dt>");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -3070,10 +4327,17 @@ s_chtml40_start_dt_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_dt_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_dt_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
-
+  Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3087,13 +4351,48 @@ s_chtml40_end_dt_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_dd_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_start_dd_tag(void *pdoc, Node *node)
 {
-  chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc     = chtml40->doc;
+  chtml40_t *chtml40;
+  Doc       *doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
 
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
   W_L("<dd>");
-
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -3107,10 +4406,17 @@ s_chtml40_start_dd_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_dd_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_dd_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
-
+  Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3129,7 +4435,11 @@ s_chtml40_start_marquee_tag(void *pdoc, Node *node)
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc = chtml40->doc;
   Attr      *attr;
-  W_L("<marquee");
+  char      *attr_direction = NULL;
+  char      *attr_behavior  = NULL;
+  char      *attr_loop      = NULL;
+  char      *attr_style     = NULL;
+  char      *attr_color     = NULL;
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -3140,27 +4450,89 @@ s_chtml40_start_marquee_tag(void *pdoc, Node *node)
     char *value  = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('d','D',"direction", name)) {
       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value))) {
-        W_L(" direction=\"");
-        W_V(value);
-        W_L("\"");
+        attr_direction = value;
       }
     }
     else if (STRCASEEQ('b','B',"behavior",name)) {
       if (value && (STRCASEEQ('s','S',"scroll",value) || STRCASEEQ('s','S',"slide",value) || STRCASEEQ('a','A',"alternate",value))) {
-        W_L(" behavior=\""); 
-        W_V(value);
-        W_L("\"");
+        attr_behavior = value;
       }
     }
     else if (STRCASEEQ('l','L',"loop",name)) {
       if (value && *value) {
-        W_L(" loop=\"");
-        W_V(value);
-        W_L("\"");
+        attr_loop = value;
       }
     }
+    else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *direction_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
+      css_property_t *style_prop     = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
+      css_property_t *loop_prop      = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = style_prop->next; cur != style_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_behavior = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = loop_prop->next; cur != loop_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_loop = apr_pstrdup(doc->pool, cur->value);
+          if (STRCASEEQ('i','I',"infinite",attr_loop)) {
+            attr_loop = "16";
+          }
+        }
+      }
+      for (cur = direction_prop->next; cur != direction_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          if (STRCASEEQ('l','L',"ltr",cur->value)) {
+            attr_direction = "right";
+          }
+          else if (STRCASEEQ('r','R',"rtl",cur->value)) {
+            attr_direction = "left";
+          }
+        }
+      }
+    }
+  }
+  W_L("<marquee");
+  if (attr_direction) {
+    W_L(" direction=\"");
+    W_V(attr_direction);
+    W_L("\"");
+  }
+  if (attr_behavior) {
+    W_L(" behavior=\"");
+    W_V(attr_behavior);
+    W_L("\"");
+  }
+  if (attr_loop) {
+    W_L(" loop=\"");
+    W_V(attr_loop);
+    W_L("\"");
   }
   W_L(">");
+
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -3174,11 +4546,18 @@ s_chtml40_start_marquee_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_marquee_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_marquee_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc = chtml40->doc;
+  Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</marquee>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3192,11 +4571,48 @@ s_chtml40_end_marquee_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_start_blink_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_start_blink_tag(void *pdoc, Node *node)
 {
-  chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc = chtml40->doc;
+  chtml40_t *chtml40;
+  Doc       *doc;
+  Attr      *attr;
+  char      *attr_style = NULL;
+  char      *attr_color = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_color = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+  }
   W_L("<blink>");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
   return chtml40->out;
 }
 
@@ -3210,11 +4626,18 @@ s_chtml40_start_blink_tag(void *pdoc, Node *UNUSED(child))
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_blink_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_blink_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc = chtml40->doc;
+  Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</blink>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3233,7 +4656,9 @@ s_chtml40_start_menu_tag(void *pdoc, Node *node)
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
   Doc       *doc     = chtml40->doc;
   Attr      *attr;
-  W_L("<menu");
+  char      *attr_style = NULL;
+  char      *attr_type  = NULL;
+  char      *attr_color = NULL;
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -3244,13 +4669,32 @@ s_chtml40_start_menu_tag(void *pdoc, Node *node)
     char *value  = qs_get_attr_value(doc,attr);
     if (STRCASEEQ('t','T',"type",name)) {
       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
-        W_L(" type=\"");
-        W_V(value);
-        W_L("\"");
+        attr_type = value;
       }
     }
+    else if (STRCASEEQ('s','S',"style", name) && value && *value) {
+      attr_style = value;
+    }
+  }
+  CHTML40_GET_CSS_COLOR_AND_LIST_STYLE_TYPE();
+  W_L("<menu");
+  if (attr_type) {
+    W_L(" type=\"");
+    W_V(attr_type);
+    W_L("\"");
   }
   W_L(">");
+  chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_flags_t));
+  memset(flg, 0, sizeof(*flg));
+  if (attr_color) {
+    attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+    W_L("<font color=\"");
+    W_V(attr_color);
+    W_L("\">");
+    flg->with_font_flag = 1;
+  }
+  node->userData = (void *)flg;
+
   return chtml40->out;
 }
 
@@ -3264,11 +4708,18 @@ s_chtml40_start_menu_tag(void *pdoc, Node *node)
  * @return The conversion result is returned.
  */
 static char *
-s_chtml40_end_menu_tag(void *pdoc, Node *UNUSED(child))
+s_chtml40_end_menu_tag(void *pdoc, Node *node)
 {
   chtml40_t *chtml40 = GET_CHTML40(pdoc);
-  Doc       *doc = chtml40->doc;
+  Doc       *doc     = chtml40->doc;
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
   W_L("</menu>");
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
   return chtml40->out;
 }
 
@@ -3324,8 +4775,8 @@ s_chtml40_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- *  * It is handler who processes the New Line Code.
- *   */
+ * It is handler who processes the New Line Code.
+ */
 static char *
 s_chtml40_newline_mark(void *pdoc, Node *UNUSED(node))
 {
@@ -3334,6 +4785,355 @@ s_chtml40_newline_mark(void *pdoc, Node *UNUSED(node))
   W_NLCODE();
   return chtml40->out;
 }
+
+
+/**
+ * It is a handler who processes the LINK tag.
+ *
+ * @param pdoc  [i/o] The pointer to the CHTML structure at the output
+ *                     destination is specified.
+ * @param node   [i]   The LINK tag node is specified.
+ * @return The conversion result is returned.
+ */
+static char *
+s_chtml40_link_tag(void *pdoc, Node *node)
+{
+  chtml40_t     *chtml40;
+  Doc           *doc;
+  Attr          *attr;
+  char          *rel  = NULL;
+  char          *href = NULL;
+  char          *type = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+
+  if (! IS_CSS_ON(chtml40->entryp)) {
+    return chtml40->out;
+  }
+
+  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('r','R',"rel", name)) {
+      if (value && *value && STRCASEEQ('s','S',"stylesheet", value)) {
+        rel = value;
+      }
+    }
+    else if (STRCASEEQ('h','H',"href", name)) {
+      if (value && *value) {
+        href = value;
+      }
+    }
+    else if (STRCASEEQ('t','T',"type", name)) {
+      if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
+        type = value;
+      }
+    }
+  }
+
+  if (rel && href && type) {
+    DBG(doc->r, "REQ[%X] start load CSS. url:[%s]", TO_ADDR(doc->r),href);
+    chtml40->style = chxj_css_parse_from_uri(doc->r, doc->pool, chtml40->style, href);
+    DBG(doc->r, "REQ[%X] end load CSS. url:[%s]", TO_ADDR(doc->r),href);
+  }
+
+  return chtml40->out;
+}
+
+static css_prop_list_t *
+s_chtml40_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
+{
+  chtml40_t *chtml40 = GET_CHTML40(pdoc);
+  Doc *doc = chtml40->doc;
+  css_prop_list_t *last_css = NULL;
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *dup_css;
+    css_selector_t  *selector;
+
+    last_css = chxj_css_get_last_prop_list(chtml40->css_prop_stack);
+    dup_css  = chxj_dup_css_prop_list(doc, last_css);
+    selector = chxj_css_find_selector(doc, chtml40->style, node);
+    if (selector) {
+      chxj_css_prop_list_merge_property(doc, dup_css, selector);
+    }
+    chxj_css_push_prop_list(chtml40->css_prop_stack, dup_css);
+    last_css = chxj_css_get_last_prop_list(chtml40->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_chtml40_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
+{
+  chtml40_t *chtml40 = GET_CHTML40(pdoc);
+  Doc *doc = chtml40->doc;
+  css_prop_list_t *last_css = NULL;
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *dup_css;
+    css_selector_t  *selector;
+
+    last_css = chxj_css_get_last_prop_list(chtml40->css_prop_stack);
+    dup_css  = chxj_dup_css_prop_list(doc, last_css);
+    selector = chxj_css_find_selector(doc, chtml40->style, node);
+    if (selector) {
+      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;
+}
+
+
+
+/**
+ * It is a handler who processes the SPAN tag.
+ *
+ * @param pdoc  [i/o] The pointer to the CHTML structure at the output
+ *                     destination is specified.
+ * @param node   [i]   The SPAN tag node is specified.
+ * @return The conversion result is returned.
+ */
+static char *
+s_chtml40_start_span_tag(void *pdoc, Node *node)
+{
+  chtml40_t *chtml40;
+  Doc *doc;
+  Attr *attr;
+  char *attr_style = NULL;
+  char *attr_color = NULL;
+  char *attr_align = NULL;
+  char *attr_blink = NULL;
+  char *attr_marquee = NULL;
+  char *attr_marquee_dir = NULL;
+  char *attr_marquee_style = NULL;
+  char *attr_marquee_loop = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+
+  for (attr = qs_get_attr(doc,node);
+       attr;
+       attr = qs_get_next_attr(doc,attr)) {
+    char *nm  = qs_get_attr_name(doc,attr);
+    char *val = qs_get_attr_value(doc,attr);
+    if (val && STRCASEEQ('s','S',"style", nm)) {
+      attr_style = val;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
+      css_property_t *decoration_prop = chxj_css_get_property_value(doc, style, "text-decoration");
+      css_property_t *display_prop = chxj_css_get_property_value(doc, style, "display");
+      css_property_t *marquee_dir_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
+      css_property_t *marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
+      css_property_t *marquee_loop_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        attr_color = apr_pstrdup(doc->pool, cur->value);
+      }
+      for (cur = decoration_prop->next; cur != decoration_prop; cur = cur->next) {
+        if (cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
+          attr_blink = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
+        if (cur->value && strcasecmp("-wap-marquee",cur->value) == 0) {
+          attr_marquee = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = marquee_dir_prop->next; cur != marquee_dir_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          if (STRCASEEQ('l','L',"ltr",cur->value)) {
+            attr_marquee_dir = "right";
+          }
+          else if (STRCASEEQ('r','R',"rtl",cur->value)) {
+            attr_marquee_dir = "left";
+          }
+        }
+      }
+      for (cur = marquee_style_prop->next; cur != marquee_style_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          if ( STRCASEEQ('s','S',"scroll",cur->value)
+            || STRCASEEQ('s','S',"slide",cur->value)
+            || STRCASEEQ('a','A',"alternate",cur->value)) {
+            attr_marquee_style = apr_pstrdup(doc->pool, cur->value);
+          }
+        }
+      }
+      for (cur = marquee_loop_prop->next; cur != marquee_loop_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          if (STRCASEEQ('i','I',"infinite",cur->value)) {
+            attr_marquee_loop = "16";
+          }
+          else {
+            attr_marquee_loop = apr_pstrdup(doc->pool, cur->value);
+          }
+        }
+      }
+      for (cur = text_align_prop->next; cur != text_align_prop; 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");
+        }
+      }
+    }
+  }
+  if (attr_color || attr_align || attr_blink || attr_marquee) {
+    chtml40_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
+    memset(flg, 0, sizeof(*flg));
+    if (attr_blink) {
+      W_L("<blink>");
+      flg->with_blink_flag = 1;
+    }
+    if (attr_marquee) {
+      W_L("<marquee");
+      if (attr_marquee_dir) {
+        W_L(" direction=\"");
+        W_V(attr_marquee_dir);
+        W_L("\"");
+      }
+      if (attr_marquee_style) {
+        W_L(" behavior=\"");
+        W_V(attr_marquee_style);
+        W_L("\"");
+      }
+      if (attr_marquee_loop) {
+        W_L(" loop=\"");
+        W_V(attr_marquee_loop);
+        W_L("\"");
+      }
+      W_L(">");
+      flg->with_marquee_flag = 1;
+    }
+    if (attr_color) {
+      attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
+      W_L("<font color=\"");
+      W_V(attr_color);
+      W_L("\">");
+      flg->with_font_flag = 1;
+    }
+    if (attr_align) {
+      W_L("<div align=\"");
+      W_V(attr_align);
+      W_L("\">");
+      flg->with_div_flag = 1;
+    }
+    node->userData = flg;
+  }
+  else {
+    node->userData = NULL;
+  }
+  return chtml40->out;
+}
+
+
+/**
+ * It is a handler who processes the SPAN tag.
+ *
+ * @param pdoc  [i/o] The pointer to the CHTML structure at the output
+ *                     destination is specified.
+ * @param node   [i]   The SPAN tag node is specified.
+ * @return The conversion result is returned.
+ */
+static char *
+s_chtml40_end_span_tag(void *pdoc, Node *node)
+{
+  chtml40_t *chtml40 = GET_CHTML40(pdoc);
+  Doc *doc = chtml40->doc;
+
+  chtml40_flags_t *flg = (chtml40_flags_t *)node->userData;
+  if (flg && flg->with_div_flag) {
+    W_L("</div>");
+  }
+  if (flg && flg->with_font_flag) {
+    W_L("</font>");
+  }
+  if (flg && flg->with_marquee_flag) {
+    W_L("</marquee>");
+  }
+  if (flg && flg->with_blink_flag) {
+    W_L("</blink>");
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    chxj_css_pop_prop_list(chtml40->css_prop_stack);
+  }
+  return chtml40->out;
+}
+
+
+/**
+ * It is a handler who processes the STYLE tag.
+ *
+ * @param pdoc  [i/o] The pointer to the CHTML structure at the output
+ *                     destination is specified.
+ * @param node   [i]   The STYLE tag node is specified.
+ * @return The conversion result is returned.
+ */
+static char *
+s_chtml40_style_tag(void *pdoc, Node *node)
+{
+  chtml40_t     *chtml40;
+  Doc           *doc;
+  Attr          *attr;
+  char          *type = NULL;
+
+  chtml40 = GET_CHTML40(pdoc);
+  doc     = chtml40->doc;
+
+  if (! IS_CSS_ON(chtml40->entryp)) {
+    return chtml40->out;
+  }
+
+  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('t','T',"type", name)) {
+      if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
+        type = value;
+      }
+    }
+  }
+
+  Node *child = qs_get_child_node(doc, node);
+  if (type && child) {
+    char *name  = qs_get_node_name(doc, child);
+    if (STRCASEEQ('t','T',"text", name)) {
+      char *value = qs_get_node_value(doc, child);
+      DBG(doc->r, "REQ[%X] start load CSS. buf:[%s]", TO_ADDR(doc->r),value);
+      chtml40->style = chxj_css_parse_style_value(doc, chtml40->style, value);
+      DBG(doc->r, "REQ[%X] end load CSS. value:[%s]", TO_ADDR(doc->r),value);
+    }
+  }
+  return chtml40->out;
+}
 /*
  * vim:ts=2 et
  */