OSDN Git Service

* version up for freeBSD
[modchxj/mod_chxj.git] / src / chxj_chtml10.c
index 88bf076..cc51397 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 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");
 #include "chxj_cookie.h"
 #include "chxj_encoding.h"
 #include "chxj_buffered_write.h"
+#include "chxj_str_util.h"
+#include "chxj_header_inf.h"
+#include "chxj_conv_z2h.h"
 
 #define GET_CHTML10(X) ((chtml10_t *)(X))
+#undef W_L
+#undef W_V
 #define W_L(X)          do { chtml10->out = BUFFERED_WRITE_LITERAL(chtml10->out, &doc->buf, (X)); } while(0)
 #define W_V(X)          do { chtml10->out = (X) ? BUFFERED_WRITE_VALUE(chtml10->out, &doc->buf, (X))  \
                                                   : BUFFERED_WRITE_LITERAL(chtml10->out, &doc->buf, ""); } while(0)
 
-#define W_NLCODE()     do { char *nlcode = TO_NLCODE(chtml10->conf); W_V(nlcode); } while (0); 
+#undef W_NLCODE
+#define W_NLCODE()     do { char *nlcode = TO_NLCODE(chtml10->conf); W_V(nlcode); } while (0)
 
 static char *s_chtml10_start_html_tag     (void *pdoc, Node *node);
 static char *s_chtml10_end_html_tag       (void *pdoc, Node *node);
@@ -105,6 +111,7 @@ static char *s_chtml10_end_menu_tag       (void *pdoc, Node *node);
 static char *s_chtml10_start_plaintext_tag(void *pdoc, Node *node);
 static char *s_chtml10_start_plaintext_tag_inner(void  *pdoc, Node *node);
 static char *s_chtml10_end_plaintext_tag  (void *pdoc, Node *node);
+static char *s_chtml10_newline_mark       (void *pdoc, Node *node);
 
 static void  s_init_chtml10(chtml10_t *chtml, Doc *doc, request_rec *r, device_table *spec);
 
@@ -283,6 +290,11 @@ tag_handler chtml10_handler[] = {
     s_chtml10_chxjif_tag,
     NULL,
   },
+  /* tagCHXJRAW */
+  {
+    s_chtml10_chxjif_tag,
+    NULL,
+  },
   /* tagNOBR */
   {
     NULL,
@@ -378,6 +390,11 @@ tag_handler chtml10_handler[] = {
     NULL,
     NULL,
   },
+  /* tagNLMARK */
+  {
+    s_chtml10_newline_mark,
+    NULL,
+  },
 };
 
 
@@ -410,7 +427,7 @@ chxj_convert_chtml10(
   dst = NULL;
 
   t = apr_time_now();
-  DBG(r, "start chxj_convert_chtml10() cookie_id=[%s]", (cookie) ? cookie->cookie_id : "");
+  DBG(r, "REQ[%X] start %s() cookie_id=[%s]", TO_ADDR(r),__func__, (cookie) ? cookie->cookie_id : "");
 
   /*--------------------------------------------------------------------------*/
   /* If qrcode xml                                                            */
@@ -418,10 +435,11 @@ chxj_convert_chtml10(
   *dstlen = srclen;
   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
   if (dst) {
-    DBG(r,"i found qrcode xml");
+    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");
+  DBG(r,"REQ[%X] not found qrcode xml", TO_ADDR(r));
 
   /*--------------------------------------------------------------------------*/
   /* The CHTML structure is initialized.                                      */
@@ -430,7 +448,7 @@ chxj_convert_chtml10(
   chtml10.entryp    = entryp;
   chtml10.cookie    = cookie;
 
-  chxj_set_content_type(r, "text/html; charset=Windows-31J");
+  chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
 
   /*--------------------------------------------------------------------------*/
   /* The character string of the input is analyzed.                           */
@@ -460,6 +478,7 @@ chxj_convert_chtml10(
   qs_all_free(&doc,QX_LOGMARK);
 
   if (!dst) {
+    DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
     return apr_pstrdup(r->pool,ss);
   }
 
@@ -472,7 +491,8 @@ chxj_convert_chtml10(
   chxj_dump_out("[dst] CHTML -> CHTML1.0", dst, *dstlen);
 #endif
 
-  DBG(r, "end   chxj_convert_chtml10() cookie_id=[%s] time=[%lld]", (cookie) ? cookie->cookie_id : "", apr_time_now() - t);
+  DBG(r, "REQ[%X] cookie_id=[%s] time=[%" APR_TIME_T_FMT "]", TO_ADDR(r),(cookie) ? cookie->cookie_id : "", apr_time_now() - t);
+  DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
 
   return dst;
 }
@@ -501,7 +521,7 @@ s_init_chtml10(
   doc->r      = r;
   chtml10->doc  = doc;
   chtml10->spec = spec;
-  chtml10->out  = qs_alloc_zero_byte_string(r);
+  chtml10->out  = qs_alloc_zero_byte_string(r->pool);
   chtml10->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
   chtml10->doc->parse_mode = PARSE_MODE_CHTML;
 }
@@ -532,7 +552,7 @@ s_chtml10_search_emoji(chtml10_t *chtml10, char *txt, char **rslt)
   r = chtml10->doc->r;
 
   if (!spec) {
-    DBG(r,"spec is NULL");
+    DBG(r,"REQ[%X] spec is NULL", TO_ADDR(r));
   }
 
   for (ee = chtml10->conf->emoji;
@@ -540,7 +560,7 @@ s_chtml10_search_emoji(chtml10_t *chtml10, char *txt, char **rslt)
        ee = ee->next) {
 
     if (!ee->imode) {
-      DBG(r,"emoji->imode is NULL");
+      DBG(r,"REQ[%X] emoji->imode is NULL", TO_ADDR(r));
       continue;
     }
 
@@ -549,20 +569,77 @@ s_chtml10_search_emoji(chtml10_t *chtml10, char *txt, char **rslt)
     &&  strlen(ee->imode->string) > 0
     &&  *ee->imode->string == *txt
     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
-      if (!spec || !spec->emoji_type) {
-        *rslt = apr_palloc(r->pool, 3);
-        (*rslt)[0] = ee->imode->hex1byte & 0xff;
-        (*rslt)[1] = ee->imode->hex2byte & 0xff;
-        (*rslt)[2] = 0;
-        return strlen(ee->imode->string);
-      }
-
-      return 0;
+      *rslt = apr_palloc(r->pool, 3);
+      (*rslt)[0] = ee->imode->hex1byte & 0xff;
+      (*rslt)[1] = ee->imode->hex2byte & 0xff;
+      (*rslt)[2] = 0;
+      return strlen(ee->imode->string);
     }
   }
   return 0;
 }
 
+char *
+chxj_chtml10_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
+{
+  apr_size_t ii;
+  Doc __doc;
+  Doc *doc;
+  chtml10_t __chtml10;
+  chtml10_t *chtml10;
+  char one_byte[2];
+  char two_byte[3];
+  apr_pool_t *pool;
+
+  chtml10 = &__chtml10;
+  doc     = &__doc;
+
+  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
+  memset(doc,     0, sizeof(Doc));
+  memset(chtml10, 0, sizeof(chtml10_t));
+
+  doc->r        = r;
+  chtml10->doc  = doc;
+  chtml10->spec = spec;
+  chtml10->out  = qs_alloc_zero_byte_string(r->pool);
+  chtml10->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+  chtml10->doc->parse_mode = PARSE_MODE_CHTML;
+
+  apr_pool_create(&pool, r->pool);
+
+  chxj_buffered_write_init(pool, &doc->buf);
+
+  for (ii=0; ii<len; ii++) {
+    char *out;
+    int   rtn;
+
+    rtn = s_chtml10_search_emoji(chtml10, (char *)&src[ii], &out);
+    if (rtn) {
+      W_V(out);
+      ii+=(rtn - 1);
+      continue;
+    }
+  
+    if (is_sjis_kanji(src[ii])) {
+      two_byte[0] = src[ii+0];
+      two_byte[1] = src[ii+1];
+      two_byte[2] = 0;
+      W_V(two_byte);
+      ii++;
+    }
+    else {
+      one_byte[0] = src[ii+0];
+      one_byte[1] = 0;
+      W_V(one_byte);
+    }
+  }
+
+  chtml10->out = chxj_buffered_write_flush(chtml10->out, &doc->buf);
+
+  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
+  return chtml10->out;
+}
+
 
 /**
  * It is a handler who processes the HTML tag.
@@ -587,8 +664,6 @@ s_chtml10_start_html_tag(void *pdoc, Node *UNUSED(node))
   /* start HTML tag                                                           */
   /*--------------------------------------------------------------------------*/
   W_L("<html>");
-  W_NLCODE();
-
   return chtml10->out;
 }
 
@@ -614,8 +689,6 @@ s_chtml10_end_html_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</html>");
-  W_NLCODE();
-
   return chtml10->out;
 }
 
@@ -676,7 +749,6 @@ s_chtml10_start_head_tag(void *pdoc, Node *UNUSED(node))
   r       = doc->r;
 
   W_L("<head>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -702,7 +774,6 @@ s_chtml10_end_head_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</head>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -728,7 +799,6 @@ s_chtml10_start_ol_tag(void *pdoc, Node *UNUSED(node))
   r       = doc->r;
 
   W_L("<ol>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -754,7 +824,6 @@ s_chtml10_end_ol_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</ol>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -780,7 +849,6 @@ s_chtml10_start_ul_tag(void *pdoc, Node *UNUSED(node))
   r          = doc->r;
 
   W_L("<ul>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -806,7 +874,6 @@ s_chtml10_end_ul_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</ul>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -914,7 +981,6 @@ s_chtml10_end_h1_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</h1>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -979,7 +1045,6 @@ s_chtml10_end_h2_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</h2>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1046,7 +1111,6 @@ s_chtml10_end_h3_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</h3>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1109,7 +1173,6 @@ s_chtml10_end_h4_tag(void *pdoc, Node *UNUSED(child))
   doc      = chtml10->doc;
 
   W_L("</h4>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1174,7 +1237,6 @@ s_chtml10_end_h5_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml10->doc;
 
   W_L("</h5>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1237,7 +1299,6 @@ s_chtml10_end_h6_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml10->doc;
 
   W_L("</h6>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1284,7 +1345,6 @@ s_chtml10_end_title_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml10->doc;
 
   W_L("</title>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1325,7 +1385,6 @@ s_chtml10_start_base_tag(void *pdoc, Node *node)
   }
 
   W_L(">");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1431,7 +1490,6 @@ s_chtml10_start_body_tag(void *pdoc, Node *node)
   }
 
   W_L(">");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1455,7 +1513,6 @@ s_chtml10_end_body_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml10->doc;
 
   W_L("</body>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1511,7 +1568,9 @@ s_chtml10_start_a_tag(void *pdoc, Node *node)
         /* CHTML1.0                                                           */
         /*--------------------------------------------------------------------*/
         value = chxj_encoding_parameter(r, value);
-        value = chxj_add_cookie_parameter(r, value, chtml10->cookie);
+        if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
+          value = chxj_add_cookie_parameter(r, value, chtml10->cookie);
+        }
         W_L(" href=\"");
         W_V(value);
         W_L("\"");
@@ -1648,7 +1707,7 @@ s_chtml10_end_a_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</a>");
-  W_NLCODE();
+
   return chtml10->out;
 }
 
@@ -1692,7 +1751,7 @@ s_chtml10_start_br_tag(void *pdoc, Node *node)
     }
   }
   W_L(">");
-  W_NLCODE();
+
   return chtml10->out;
 }
 
@@ -1751,7 +1810,6 @@ s_chtml10_end_tr_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("<br>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1810,12 +1868,14 @@ s_chtml10_start_form_tag(void *pdoc, Node *node)
   Doc          *doc;
   request_rec  *r;
   Attr         *attr;
+  char         *new_hidden_tag = NULL;
+  char         *attr_value = NULL;
+  char         *attr_method = NULL;
 
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   r       = doc->r;
 
-  W_L("<form");
 
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
@@ -1832,12 +1892,8 @@ s_chtml10_start_form_tag(void *pdoc, Node *node)
         /*--------------------------------------------------------------------*/
         /* CHTML 1.0                                                          */
         /*--------------------------------------------------------------------*/
-        value = chxj_encoding_parameter(r, value);
-        value = chxj_add_cookie_parameter(r, value, chtml10->cookie);
-  
-        W_L(" action=\"");
-        W_V(value);
-        W_L("\"");
+        attr_value = chxj_encoding_parameter(r, value);
+        attr_value = chxj_add_cookie_parameter(r, attr_value, chtml10->cookie);
       }
       break;
 
@@ -1847,9 +1903,7 @@ s_chtml10_start_form_tag(void *pdoc, Node *node)
         /*--------------------------------------------------------------------*/
         /* CHTML 1.0                                                          */
         /*--------------------------------------------------------------------*/
-        W_L(" method=\"");
-        W_V(value);
-        W_L("\"");
+        attr_method = apr_pstrdup(doc->pool, value);
       }
       break;
 
@@ -1868,8 +1922,36 @@ s_chtml10_start_form_tag(void *pdoc, Node *node)
     }
   }
 
+  int post_flag = (attr_method && strcasecmp(attr_method, "post") == 0) ? 1 : 0;
+
+  W_L("<form");
+  if (attr_value) {
+    char *q;
+    char *new_query_string = NULL;
+    q = strchr(attr_value, '?');
+    if (q) {
+      new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_value, 0, post_flag, &new_query_string, CHXJ_TRUE, CHXJ_FALSE, chtml10->entryp);
+      if (new_hidden_tag || new_query_string) {
+        *q = 0;
+      }
+    }
+    W_L(" action=\"");
+    W_V(attr_value);
+    if (new_query_string) {
+      W_L("?");
+      W_V(new_query_string);
+    }
+    W_L("\"");
+  }
+  if (attr_method) {
+    W_L(" method=\"");
+    W_V(attr_method);
+    W_L("\"");
+  }
   W_L(">");
-  W_NLCODE();
+  if (new_hidden_tag) {
+    W_V(new_hidden_tag);
+  }
 
   return chtml10->out;
 }
@@ -1895,7 +1977,6 @@ s_chtml10_end_form_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</form>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -1943,14 +2024,14 @@ s_chtml10_start_input_tag(void *pdoc, Node *node)
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
 
-  type       = qs_get_type_attr(doc, node, r);
-  name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
-  istyle     = qs_get_istyle_attr(doc,node,r);
-  max_length = qs_get_maxlength_attr(doc,node,r);
-  checked    = qs_get_checked_attr(doc,node,r);
-  accesskey  = qs_get_accesskey_attr(doc, node, r);
-  size       = qs_get_size_attr(doc, node, r);
+  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);
@@ -1980,8 +2061,13 @@ s_chtml10_start_input_tag(void *pdoc, Node *node)
   }
 
   if (value && *value != 0) {
+    if (type && (STRCASEEQ('s','S',"submit",type) || STRCASEEQ('r','R',"reset",type))) {
+      apr_size_t value_len = strlen(value);
+      value = chxj_conv_z2h(r, value, &value_len, chtml10->entryp);
+    }
+
     W_L(" value=\"");
-    W_V(value);
+    W_V(chxj_add_slash_to_doublequote(doc->pool, value));
     W_L("\"");
   }
 
@@ -2011,7 +2097,6 @@ s_chtml10_start_input_tag(void *pdoc, Node *node)
   }
 
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2078,7 +2163,6 @@ s_chtml10_end_center_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</center>");
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -2179,7 +2263,6 @@ s_chtml10_start_hr_tag(void *pdoc, Node *node)
     }
   }
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2247,13 +2330,7 @@ s_chtml10_start_img_tag(void *pdoc, Node *node)
 #ifdef IMG_NOT_CONVERT_FILENAME
         value = chxj_encoding_parameter(r, value);
         value = chxj_add_cookie_parameter(r, value, chtml10->cookie);
-        if (value) {
-          value = apr_psprintf(doc->buf.pool, 
-                               "%s%c%s=true", 
-                               value, 
-                               (strchr(value, '?')) ? '&' : '?',
-                               CHXJ_COOKIE_NOUPDATE_PARAM);
-        }
+        value = chxj_add_cookie_no_update_parameter(r, value);
         W_L(" src=\"");
         W_V(value);
         W_L("\"");
@@ -2261,13 +2338,7 @@ s_chtml10_start_img_tag(void *pdoc, Node *node)
         value = chxj_img_conv(r, spec, value);
         value = chxj_encoding_parameter(r, value);
         value = chxj_add_cookie_parameter(r, value, chtml10->cookie);
-        if (value) {
-          value = apr_psprintf(doc->buf.pool,
-                               "%s%c%s=true",
-                               value,
-                               (strchr(value, '?')) ? '&' : '?',
-                               CHXJ_COOKIE_NOUPDATE_PARAM);
-        }
+        value = chxj_add_cookie_no_update_parameter(r, value);
         W_L(" src=\"");
         W_V(value);
         W_L("\"");
@@ -2372,7 +2443,6 @@ s_chtml10_start_img_tag(void *pdoc, Node *node)
   }
 
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2475,7 +2545,6 @@ s_chtml10_start_select_tag(void *pdoc, Node *child)
   }
 
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2500,7 +2569,6 @@ s_chtml10_end_select_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</select>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2563,7 +2631,7 @@ s_chtml10_start_option_tag(void *pdoc, Node *child)
     }
   }
 
-  if (value && *value != 0) {
+  if (value) {
     W_L(" value=\"");
     W_V(value);
     W_L("\"");
@@ -2590,10 +2658,8 @@ static char *
 s_chtml10_end_option_tag(void *pdoc, Node *UNUSED(child))
 {
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
-  Doc       *doc     = chtml10->doc;
 
   /* Don't close */
-  W_NLCODE();
 
   return chtml10->out;
 }
@@ -2645,7 +2711,6 @@ s_chtml10_start_div_tag(void *pdoc, Node *child)
   }
 
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2670,7 +2735,6 @@ s_chtml10_end_div_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</div>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2727,7 +2791,6 @@ s_chtml10_start_pre_tag(void *pdoc, Node *UNUSED(node))
 
   chtml10->pre_flag++;
   W_L("<pre>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2752,7 +2815,6 @@ s_chtml10_end_pre_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</pre>");
-  W_NLCODE();
   chtml10->pre_flag--;
 
   return chtml10->out;
@@ -2803,7 +2865,6 @@ s_chtml10_start_p_tag(void *pdoc, Node *node)
   }
 
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2828,7 +2889,6 @@ s_chtml10_end_p_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</p>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2905,7 +2965,6 @@ s_chtml10_start_textarea_tag(void *pdoc, Node *node)
     }
   }
   W_L(">");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -2930,7 +2989,6 @@ s_chtml10_end_textarea_tag(void *pdoc, Node *UNUSED(child))
   r       = doc->r;
 
   W_L("</textarea>");
-  W_NLCODE();
   chtml10->textarea_flag--;
 
   return chtml10->out;
@@ -2949,6 +3007,7 @@ s_chtml10_text(void *pdoc, Node *child)
   chtml10_t   *chtml10;
   Doc         *doc;
   request_rec *r;
+  apr_size_t  z2h_input_len;
 
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
@@ -2962,7 +3021,7 @@ s_chtml10_text(void *pdoc, Node *child)
   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
   memset(tmp, 0, qs_get_node_size(doc,child)+1);
   
-  tdst     = qs_alloc_zero_byte_string(r);
+  tdst     = qs_alloc_zero_byte_string(doc->buf.pool);
   memset(one_byte, 0, sizeof(one_byte));
   tdst_len = 0;
   
@@ -3001,6 +3060,9 @@ s_chtml10_text(void *pdoc, Node *child)
     }
   }
 
+  z2h_input_len = strlen(tdst);
+  tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, chtml10->entryp);
+
   W_V(tdst);
   return chtml10->out;
 }
@@ -3022,7 +3084,6 @@ s_chtml10_start_blockquote_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("<blockquote>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3044,7 +3105,6 @@ s_chtml10_end_blockquote_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("</blockquote>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3065,7 +3125,6 @@ s_chtml10_start_dir_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("<dir>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3087,7 +3146,6 @@ s_chtml10_end_dir_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("</dir>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3128,7 +3186,6 @@ s_chtml10_end_dl_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("</dl>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3165,9 +3222,7 @@ static char *
 s_chtml10_end_dt_tag(void *pdoc, Node *UNUSED(child))
 {
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
-  Doc       *doc     = chtml10->doc;
   
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3204,8 +3259,6 @@ static char *
 s_chtml10_end_dd_tag(void *pdoc, Node *UNUSED(child))
 {
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
-  Doc       *doc     = chtml10->doc;
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3226,7 +3279,6 @@ s_chtml10_start_menu_tag(void *pdoc, Node *UNUSED(child))
   chtml10 = GET_CHTML10(pdoc);
   doc     = chtml10->doc;
   W_L("<menu>");
-  W_NLCODE();
   return chtml10->out;
 }
 
@@ -3245,13 +3297,12 @@ s_chtml10_end_menu_tag(void *pdoc, Node *UNUSED(child))
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
   Doc *doc = chtml10->doc;
   W_L("</menu>");
-  W_NLCODE();
   return chtml10->out;
 }
 
 
 /**
- * It is a hanplaintexter who processes the PLAINTEXT tag.
+ * It is a handler who processes the PLAINTEXT tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3290,7 +3341,7 @@ s_chtml10_start_plaintext_tag_inner(void *pdoc, Node *node)
 
 
 /**
- * It is a hanplaintexter who processes the PLAINTEXT tag.
+ * It is a handler who processes the PLAINTEXT tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3303,6 +3354,19 @@ s_chtml10_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
   return chtml10->out;
 }
+
+
+/**
+ * It is handler who processes the New Line Code.
+ */
+static char *
+s_chtml10_newline_mark(void *pdoc, Node *UNUSED(node))
+{
+  chtml10_t *chtml10 = GET_CHTML10(pdoc);
+  Doc *doc = chtml10->doc;
+  W_NLCODE();
+  return chtml10->out;
+}
 /*
  * vim:ts=2 et
  */