[BACK]Return to html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/html.c between version 1.10 and 1.20

version 1.10, 2008/12/05 22:34:30 version 1.20, 2008/12/10 00:58:15
Line 27 
Line 27 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
 #include "libmdocml.h"  #include "html.h"
 #include "private.h"  
 #include "ml.h"  #include "ml.h"
   
   
 /* TODO: allow head/tail-less invocations (just "div" start). */  /* TODO: allow head/tail-less invocations (just "div" start). */
   
 struct  htmlnode {  struct  htmlnode {
Line 42  struct htmlnode {
Line 40  struct htmlnode {
         struct htmlnode *parent;          struct htmlnode *parent;
 };  };
   
   
 struct  htmlq {  struct  htmlq {
         struct htmlnode *last;          struct htmlnode *last;
 };  };
   
   
 static  int             html_loadcss(struct md_mbuf *, const char *);  static  int             html_loadcss(struct md_mbuf *,
                                   const char *);
 static  int             html_alloc(void **);  static  int             html_alloc(void **);
 static  void            html_free(void *);  static  void            html_free(void *);
 static  ssize_t         html_endtag(struct md_mbuf *, void *,  static  ssize_t         html_endtag(struct md_mbuf *, void *,
                                 const struct md_args *,                                  const struct md_args *,
                                 enum md_ns, int);                                  enum md_ns, int);
   static  ssize_t         html_beginstring(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
   static  ssize_t         html_beginhttp(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
   static  ssize_t         html_endstring(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
   static  ssize_t         html_endhttp(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
 static  ssize_t         html_begintag(struct md_mbuf *, void *,  static  ssize_t         html_begintag(struct md_mbuf *, void *,
                                 const struct md_args *,                                  const struct md_args *,
                                 enum md_ns, int,                                  enum md_ns, int,
Line 63  static int  html_begin(struct md_mbuf *,
Line 72  static int  html_begin(struct md_mbuf *,
                                 const struct md_args *,                                  const struct md_args *,
                                 const struct tm *,                                  const struct tm *,
                                 const char *, const char *,                                  const char *, const char *,
                                 const char *, const char *);                                  enum roffmsec, const char *);
 static  int             html_printargs(struct md_mbuf *, int,  static  int             html_printargs(struct md_mbuf *, int,
                                 const char *, const int *,                                  const char *, const int *,
                                 const char **, size_t *);                                  const char **, size_t *);
Line 83  static int  html_headtagname(struct md_mbuf *,
Line 92  static int  html_headtagname(struct md_mbuf *,
 static  int             html_headtagargs(struct md_mbuf *,  static  int             html_headtagargs(struct md_mbuf *,
                                 const struct md_args *, int,                                  const struct md_args *, int,
                                 const int *, const char **, size_t *);                                  const int *, const char **, size_t *);
 static  int             html_blockbodytagname(struct md_mbuf *,  static  int             html_bodytagname(struct md_mbuf *,
                                 const struct md_args *,                                  const struct md_args *,
                                 int, struct htmlq *, const int *,                                  int, struct htmlq *, const int *,
                                 const char **, size_t *);                                  const char **, size_t *);
 static  int             html_blockbodytagargs(struct md_mbuf *,  static  int             html_bodytagargs(struct md_mbuf *,
                                 const struct md_args *, int,                                  const struct md_args *, int,
                                 const int *, const char **, size_t *);                                  const int *, const char **, size_t *);
 static  int             html_inlinetagname(struct md_mbuf *,  static  int             html_inlinetagname(struct md_mbuf *,
Line 107  static int  html_It_headtagname(struct md_mbuf *, 
Line 116  static int  html_It_headtagname(struct md_mbuf *, 
 static  int             html_It_bodytagname(struct md_mbuf *,  static  int             html_It_bodytagname(struct md_mbuf *,
                                 struct htmlq *, const int *,                                  struct htmlq *, const int *,
                                 const char **, size_t *);                                  const char **, size_t *);
   static  int             html_tputln(struct md_mbuf *,
                                   enum ml_scope, int, enum html_tag);
   static  int             html_aputln(struct md_mbuf *, enum ml_scope,
                                   int, enum html_tag,
                                   int, const struct html_pair *);
   
   
 /* ARGSUSED */  /* ARGSUSED */
Line 115  html_It_headtagname(struct md_mbuf *mbuf, struct htmlq
Line 129  html_It_headtagname(struct md_mbuf *mbuf, struct htmlq
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
         struct htmlnode *n;          struct htmlnode *n;
         int              i, c;          int              i;
   
         for (n = q->last; n; n = n->parent)          for (n = q->last; n; n = n->parent)
                 if (n->tok == ROFF_Bl)                  if (n->tok == ROFF_Bl)
                         break;                          break;
   
         assert(n);          assert(n);
         for (i = 0; ROFF_ARGMAX != (c = n->argc[i]) &&  
           /* LINTED */
           for (i = 0; ROFF_ARGMAX != n->argc[i] &&
                         i < ROFF_MAXLINEARG; i++) {                          i < ROFF_MAXLINEARG; i++) {
                 switch (n->argc[i]) {                  switch (n->argc[i]) {
                   case (ROFF_Ohang):
                           return(html_stput(mbuf, HTML_TAG_DIV, res));
                 case (ROFF_Tag):                  case (ROFF_Tag):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Column):                  case (ROFF_Column):
                         return(ml_nputs(mbuf, "td", 2, res));                          return(html_stput(mbuf, HTML_TAG_TD, res));
                 default:                  default:
                         break;                          break;
                 }                  }
         }          }
   
         assert(i != ROFF_MAXLINEARG);          return(0);
         abort();  
         /* NOTREACHED */  
   
         return(1);  
 }  }
   
   
Line 148  html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq
Line 162  html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
         struct htmlnode *n;          struct htmlnode *n;
         int              i, c;          int              i;
   
         for (n = q->last; n; n = n->parent)          for (n = q->last; n; n = n->parent)
                 if (n->tok == ROFF_Bl)                  if (n->tok == ROFF_Bl)
                         break;                          break;
   
         assert(n);          assert(n);
         for (i = 0; ROFF_ARGMAX != (c = n->argc[i]) &&  
           /* LINTED */
           for (i = 0; ROFF_ARGMAX != n->argc[i] &&
                         i < ROFF_MAXLINEARG; i++) {                          i < ROFF_MAXLINEARG; i++) {
                 switch (n->argc[i]) {                  switch (n->argc[i]) {
                 case (ROFF_Enum):                  case (ROFF_Enum):
Line 175  html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq
Line 191  html_It_bodytagname(struct md_mbuf *mbuf, struct htmlq
                 case (ROFF_Ohang):                  case (ROFF_Ohang):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Inset):                  case (ROFF_Inset):
                         return(ml_nputs(mbuf, "div", 3, res));                          return(html_stput(mbuf, HTML_TAG_DIV, res));
                 case (ROFF_Tag):                  case (ROFF_Tag):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Column):                  case (ROFF_Column):
                         return(ml_nputs(mbuf, "td", 2, res));                          return(html_stput(mbuf, HTML_TAG_TD, res));
                 default:                  default:
                         break;                          break;
                 }                  }
         }          }
   
         assert(i != ROFF_MAXLINEARG);          assert(i != ROFF_MAXLINEARG);
         abort();          return(0);
         /* NOTREACHED */  
   
         return(1);  
 }  }
   
   
Line 198  static int
Line 211  static int
 html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq *q,  html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq *q,
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
         int              c, i;          int              i;
   
         for (i = 0; ROFF_ARGMAX != (c = argc[i])          for (i = 0; ROFF_ARGMAX != argc[i]
                         && i < ROFF_MAXLINEARG; i++) {                          && i < ROFF_MAXLINEARG; i++) {
                 switch (argc[i]) {                  switch (argc[i]) {
                 case (ROFF_Enum):                  case (ROFF_Enum):
                         return(ml_nputs(mbuf, "ol", 2, res));                          return(html_stput(mbuf, HTML_TAG_OL, res));
                 case (ROFF_Bullet):                  case (ROFF_Bullet):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Dash):                  case (ROFF_Dash):
Line 220  html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq
Line 233  html_Bl_bodytagname(struct md_mbuf *mbuf, struct htmlq
                 case (ROFF_Ohang):                  case (ROFF_Ohang):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Inset):                  case (ROFF_Inset):
                         return(ml_nputs(mbuf, "ul", 2, res));                          return(html_stput(mbuf, HTML_TAG_UL, res));
                 case (ROFF_Tag):                  case (ROFF_Tag):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Column):                  case (ROFF_Column):
                         return(ml_nputs(mbuf, "table", 5, res));                          return(html_stput(mbuf, HTML_TAG_TABLE, res));
                 default:                  default:
                         break;                          break;
                 }                  }
         }          }
   
         assert(i != ROFF_MAXLINEARG);          assert(i != ROFF_MAXLINEARG);
         abort();          return(0);
         /* NOTREACHED */  
 }  }
   
   
Line 242  html_It_blocktagname(struct md_mbuf *mbuf, struct html
Line 254  html_It_blocktagname(struct md_mbuf *mbuf, struct html
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
         struct htmlnode *n;          struct htmlnode *n;
         int              i, c;          int              i;
   
         for (n = q->last; n; n = n->parent)          for (n = q->last; n; n = n->parent)
                 if (n->tok == ROFF_Bl)                  if (n->tok == ROFF_Bl)
                         break;                          break;
   
         assert(n);          assert(n);
         for (i = 0; ROFF_ARGMAX != (c = n->argc[i]) &&  
           /* LINTED */
           for (i = 0; ROFF_ARGMAX != n->argc[i] &&
                         i < ROFF_MAXLINEARG; i++) {                          i < ROFF_MAXLINEARG; i++) {
                 switch (n->argc[i]) {                  switch (n->argc[i]) {
                 case (ROFF_Enum):                  case (ROFF_Enum):
Line 269  html_It_blocktagname(struct md_mbuf *mbuf, struct html
Line 283  html_It_blocktagname(struct md_mbuf *mbuf, struct html
                 case (ROFF_Ohang):                  case (ROFF_Ohang):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Inset):                  case (ROFF_Inset):
                         return(ml_nputs(mbuf, "li", 2, res));                          return(html_stput(mbuf, HTML_TAG_LI, res));
                 case (ROFF_Tag):                  case (ROFF_Tag):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (ROFF_Column):                  case (ROFF_Column):
                         return(ml_nputs(mbuf, "tr", 2, res));                          return(html_stput(mbuf, HTML_TAG_TR, res));
                 default:                  default:
                         break;                          break;
                 }                  }
         }          }
   
         assert(i != ROFF_MAXLINEARG);          assert(i != ROFF_MAXLINEARG);
         abort();          return(0);
         /* NOTREACHED */  
 }  }
   
   
Line 339  out:
Line 352  out:
 }  }
   
   
   static int
   html_tputln(struct md_mbuf *mbuf, enum ml_scope scope,
                   int i, enum html_tag tag)
   {
   
           if ( ! ml_putchars(mbuf, ' ', INDENT(i) * INDENT_SZ, NULL))
                   return(0);
           if ( ! html_tput(mbuf, scope, tag, NULL))
                   return(0);
           return(ml_nputs(mbuf, "\n", 1, NULL));
   }
   
   
   static int
   html_aputln(struct md_mbuf *mbuf, enum ml_scope scope, int i,
                   enum html_tag tag, int sz, const struct html_pair *p)
   {
   
           if ( ! ml_putchars(mbuf, ' ', INDENT(i) * INDENT_SZ, NULL))
                   return(0);
           if ( ! html_aput(mbuf, scope, tag, NULL, sz, p))
                   return(0);
           return(ml_nputs(mbuf, "\n", 1, NULL));
   }
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  static int
 html_begin(struct md_mbuf *mbuf, const struct md_args *args,  html_begin(struct md_mbuf *mbuf, const struct md_args *args,
                 const struct tm *tm, const char *os,                  const struct tm *tm, const char *os,
                 const char *title, const char *section,                  const char *name, enum roffmsec msec, const char *vol)
                 const char *vol)  
 {  {
         const char      *preamble, *css, *trail;          struct html_pair attr[4];
         char             buf[512];          char             ts[32];
         size_t           res;          int              i;
   
         preamble =          (void)snprintf(ts, sizeof(ts), "%s(%s)",
         "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n"                          name, roff_msecname(msec));
         "    \"http://www.w3.org/TR/html4/strict.dtd\">\n"  
         "<html>\n"  
         "<head>\n"  
         "    <meta http-equiv=\"Content-Type\"\n"  
         "         content=\"text/html;charset=utf-8\">\n"  
         "    <meta name=\"resource-type\" content=\"document\">\n"  
         "    <title>Manual Page for %s(%s)</title>\n";  
   
         css =          i = 0;
         "    <link rel=\"stylesheet\" type=\"text/css\"\n"  
         "         href=\"%s\">\n";  
         trail =  
         "</head>\n"  
         "<body>\n"  
         "<div class=\"mdoc\">";  
   
         res = 0;          if ( ! html_typeput(mbuf, HTML_TYPE_4_01_STRICT, NULL))
                   return(0);
           if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_HTML))
                   return(0);
           if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_HEAD))
                   return(0);
   
         (void)snprintf(buf, sizeof(buf) - 1,          attr[0].attr = HTML_ATTR_HTTP_EQUIV;
                         preamble, title, section);          attr[0].val = "content-type";
           attr[1].attr = HTML_ATTR_CONTENT;
           attr[1].val = "text/html;charset=utf-8";
   
         if ( ! ml_puts(mbuf, buf, &res))          if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr))
                 return(0);                  return(0);
   
         assert(args->params.html.css);          attr[0].attr = HTML_ATTR_NAME;
           attr[0].val = "resource-type";
           attr[1].attr = HTML_ATTR_CONTENT;
           attr[1].val = "document";
   
           if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_META, 2, attr))
                   return(0);
   
           if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TITLE))
                   return(0);
           if ( ! ml_putstring(mbuf, ts, NULL))
                   return(0);
           if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TITLE))
                   return(0);
   
         if (HTML_CSS_EMBED & args->params.html.flags) {          if (HTML_CSS_EMBED & args->params.html.flags) {
                 if ( ! ml_puts(mbuf, "    <style type=\"text/css\"><!--\n", &res))                  attr[0].attr = HTML_ATTR_TYPE;
                   attr[0].val = "text/css";
   
                   if ( ! html_aputln(mbuf, ML_OPEN, i,
                                           HTML_TAG_STYLE, 1, attr))
                         return(0);                          return(0);
                   if ( ! html_commentput(mbuf, ML_OPEN, NULL))
                           return(NULL);
   
                 if ( ! html_loadcss(mbuf, args->params.html.css))                  if ( ! html_loadcss(mbuf, args->params.html.css))
                         return(0);                          return(0);
                 if ( ! ml_puts(mbuf, "    --!></style>\n", &res))  
                   if ( ! html_commentput(mbuf, ML_CLOSE, NULL))
                           return(NULL);
                   if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_STYLE))
                         return(0);                          return(0);
         } else {          } else {
                 (void)snprintf(buf, sizeof(buf) - 1, css,                  attr[0].attr = HTML_ATTR_REL;
                                 args->params.html.css);                  attr[0].val = "stylesheet";
                 if ( ! ml_puts(mbuf, buf, &res))                  attr[1].attr = HTML_ATTR_TYPE;
                   attr[1].val = "text/css";
                   attr[2].attr = HTML_ATTR_HREF;
                   attr[2].val = args->params.html.css;
   
                   if ( ! html_aputln(mbuf, ML_OPEN, i,
                                           HTML_TAG_LINK, 3, attr))
                         return(0);                          return(0);
         }          }
   
         if ( ! ml_puts(mbuf, trail, &res))          if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_HEAD))
                 return(0);                  return(0);
           if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_BODY))
                   return(0);
   
         return(1);          attr[0].attr = HTML_ATTR_CLASS;
           attr[0].val = "mdoc";
   
           if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_DIV, 1, attr))
                   return(0);
   
           attr[0].attr = HTML_ATTR_WIDTH;
           attr[0].val = "100%";
   
           if ( ! html_aputln(mbuf, ML_OPEN, i++, HTML_TAG_TABLE, 1, attr))
                   return(0);
           if ( ! html_tputln(mbuf, ML_OPEN, i++, HTML_TAG_TR))
                   return(0);
   
           if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TD))
                   return(0);
           if ( ! ml_putstring(mbuf, ts, NULL))
                   return(0);
           if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD))
                   return(0);
   
           if ( ! html_tputln(mbuf, ML_OPEN, i, HTML_TAG_TD))
                   return(0);
           /* TODO: middle. */
           if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD))
                   return(0);
   
           attr[0].attr = HTML_ATTR_ALIGN;
           attr[0].val = "right";
   
           if ( ! html_aputln(mbuf, ML_OPEN, i, HTML_TAG_TD, 1, attr))
                   return(0);
           if ( ! ml_putstring(mbuf, ts, NULL))
                   return(0);
           if ( ! html_tputln(mbuf, ML_CLOSE, i, HTML_TAG_TD))
                   return(0);
   
           if ( ! html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TR))
                   return(0);
           return(html_tputln(mbuf, ML_CLOSE, --i, HTML_TAG_TABLE));
 }  }
   
   
Line 403  static int 
Line 506  static int 
 html_end(struct md_mbuf *mbuf, const struct md_args *args)  html_end(struct md_mbuf *mbuf, const struct md_args *args)
 {  {
   
         return(ml_puts(mbuf, "</div></body>\n</html>", NULL));          if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_DIV))
                   return(0);
           if ( ! html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_BODY))
                   return(0);
           return(html_tputln(mbuf, ML_CLOSE, 0, HTML_TAG_HTML));
 }  }
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  static int
 html_blockbodytagname(struct md_mbuf *mbuf,  html_bodytagname(struct md_mbuf *mbuf,
                 const struct md_args *args, int tok, struct htmlq *q,                  const struct md_args *args, int tok, struct htmlq *q,
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
Line 417  html_blockbodytagname(struct md_mbuf *mbuf, 
Line 524  html_blockbodytagname(struct md_mbuf *mbuf, 
         switch (tok) {          switch (tok) {
         case (ROFF_Bl):          case (ROFF_Bl):
                 return(html_Bl_bodytagname(mbuf, q, argc, argv, res));                  return(html_Bl_bodytagname(mbuf, q, argc, argv, res));
           case (ROFF_Fo):
                   return(html_stput(mbuf, HTML_TAG_SPAN, res));
         case (ROFF_It):          case (ROFF_It):
                 return(html_It_bodytagname(mbuf, q, argc, argv, res));                  return(html_It_bodytagname(mbuf, q, argc, argv, res));
           case (ROFF_Oo):
                   return(html_stput(mbuf, HTML_TAG_SPAN, res));
         default:          default:
                 break;                  break;
         }          }
   
         return(ml_puts(mbuf, "div", res));          return(html_stput(mbuf, HTML_TAG_DIV, res));
 }  }
   
   
Line 437  html_headtagname(struct md_mbuf *mbuf, 
Line 548  html_headtagname(struct md_mbuf *mbuf, 
         switch (tok) {          switch (tok) {
         case (ROFF_It):          case (ROFF_It):
                 return(html_It_headtagname(mbuf, q, argc, argv, res));                  return(html_It_headtagname(mbuf, q, argc, argv, res));
           case (ROFF_Fo):
                   /* FALLTHROUGH */
           case (ROFF_Oo):
                   return(html_stput(mbuf, HTML_TAG_SPAN, res));
         case (ROFF_Sh):          case (ROFF_Sh):
                 return(ml_puts(mbuf, "h1", res));                  return(html_stput(mbuf, HTML_TAG_H1, res));
         case (ROFF_Ss):          case (ROFF_Ss):
                 return(ml_puts(mbuf, "h2", res));                  return(html_stput(mbuf, HTML_TAG_H2, res));
         default:          default:
                 break;                  break;
         }          }
   
         return(ml_puts(mbuf, "div", res));          return(html_stput(mbuf, HTML_TAG_DIV, res));
 }  }
   
   
Line 457  html_blocktagname(struct md_mbuf *mbuf, const struct m
Line 572  html_blocktagname(struct md_mbuf *mbuf, const struct m
 {  {
   
         switch (tok) {          switch (tok) {
           case (ROFF_Fo):
                   /* FALLTHROUGH */
           case (ROFF_Oo):
                   return(html_stput(mbuf, HTML_TAG_SPAN, res));
         case (ROFF_It):          case (ROFF_It):
                 return(html_It_blocktagname(mbuf, q, argc, argv, res));                  return(html_It_blocktagname(mbuf, q, argc, argv, res));
         default:          default:
                 break;                  break;
         }          }
   
         return(ml_puts(mbuf, "div", res));          return(html_stput(mbuf, HTML_TAG_DIV, res));
 }  }
   
   
Line 473  html_printargs(struct md_mbuf *mbuf, int tok, const ch
Line 592  html_printargs(struct md_mbuf *mbuf, int tok, const ch
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
   
           /* FIXME: use API in ml.h. */
   
         if ( ! ml_puts(mbuf, " class=\"", res))          if ( ! ml_puts(mbuf, " class=\"", res))
                 return(0);                  return(0);
         if ( ! ml_puts(mbuf, ns, res))          if ( ! ml_puts(mbuf, ns, res))
Line 498  html_headtagargs(struct md_mbuf *mbuf, 
Line 619  html_headtagargs(struct md_mbuf *mbuf, 
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  static int
 html_blockbodytagargs(struct md_mbuf *mbuf,  html_bodytagargs(struct md_mbuf *mbuf,
                 const struct md_args *args, int tok,                  const struct md_args *args, int tok,
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
Line 525  html_inlinetagargs(struct md_mbuf *mbuf, 
Line 646  html_inlinetagargs(struct md_mbuf *mbuf, 
                 const int *argc, const char **argv, size_t *res)                  const int *argc, const char **argv, size_t *res)
 {  {
   
         return(html_printargs(mbuf, tok, "inline", argc, argv, res));          if ( ! html_printargs(mbuf, tok, "inline", argc, argv, res))
                   return(0);
   
           switch (tok) {
           case (ROFF_Sx):
   
                   /* FIXME: use API in ml.h. */
   
                   assert(*argv);
                   if ( ! ml_nputs(mbuf, " href=\"#", 8, res))
                           return(0);
                   if ( ! ml_putstring(mbuf, *argv, res))
                           return(0);
                   if ( ! ml_nputs(mbuf, "\"", 1, res))
                           return(0);
                   break;
           default:
                   break;
           }
   
           return(1);
 }  }
   
   
Line 537  html_inlinetagname(struct md_mbuf *mbuf, 
Line 678  html_inlinetagname(struct md_mbuf *mbuf, 
   
         switch (tok) {          switch (tok) {
         case (ROFF_Pp):          case (ROFF_Pp):
                 return(ml_puts(mbuf, "div", res));                  return(html_stput(mbuf, HTML_TAG_DIV, res));
           case (ROFF_Sx):
                   return(html_stput(mbuf, HTML_TAG_A, res));
         default:          default:
                 break;                  break;
         }          }
   
         return(ml_puts(mbuf, "span", res));          return(html_stput(mbuf, HTML_TAG_SPAN, res));
 }  }
   
   
Line 554  html_begintag(struct md_mbuf *mbuf, void *data,
Line 697  html_begintag(struct md_mbuf *mbuf, void *data,
         size_t           res;          size_t           res;
         struct htmlq    *q;          struct htmlq    *q;
         struct htmlnode *node;          struct htmlnode *node;
         int              i, c;          int              i;
   
         assert(ns != MD_NS_DEFAULT);          assert(ns != MD_NS_DEFAULT);
         res = 0;          res = 0;
Line 575  html_begintag(struct md_mbuf *mbuf, void *data,
Line 718  html_begintag(struct md_mbuf *mbuf, void *data,
                 /* TODO: argv. */                  /* TODO: argv. */
   
                 assert(argv);                  assert(argv);
                 for (i = 0; ROFF_ARGMAX != (c = argc[i])                  /* LINTED */
                   for (i = 0; ROFF_ARGMAX != argc[i]
                                 && i < ROFF_MAXLINEARG; i++)                                  && i < ROFF_MAXLINEARG; i++)
                         node->argc[i] = argc[i];                          node->argc[i] = argc[i];
                 assert(i != ROFF_MAXLINEARG);                  assert(i != ROFF_MAXLINEARG);
         } else          }
                 assert(NULL == argv);  
   
   
         q->last = node;          q->last = node;
Line 595  html_begintag(struct md_mbuf *mbuf, void *data,
Line 738  html_begintag(struct md_mbuf *mbuf, void *data,
                         return(-1);                          return(-1);
                 break;                  break;
         case (MD_NS_BODY):          case (MD_NS_BODY):
                 if ( ! html_blockbodytagname(mbuf, args, tok,                  if ( ! html_bodytagname(mbuf, args, tok,
                                         q, argc, argv, &res))                                          q, argc, argv, &res))
                         return(-1);                          return(-1);
                 if ( ! html_blockbodytagargs(mbuf, args, tok,                  if ( ! html_bodytagargs(mbuf, args, tok,
                                         argc, argv, &res))                                          argc, argv, &res))
                         return(-1);                          return(-1);
                 break;                  break;
Line 646  html_endtag(struct md_mbuf *mbuf, void *data,
Line 789  html_endtag(struct md_mbuf *mbuf, void *data,
                         return(-1);                          return(-1);
                 break;                  break;
         case (MD_NS_BODY):          case (MD_NS_BODY):
                 if ( ! html_blockbodytagname(mbuf, args, tok,                  if ( ! html_bodytagname(mbuf, args, tok,
                                         q, node->argc,                                          q, node->argc,
                                         (const char **)node->argv, &res))                                          (const char **)node->argv, &res))
                         return(-1);                          return(-1);
Line 692  html_free(void *p)
Line 835  html_free(void *p)
         assert(p);          assert(p);
         q = (struct htmlq *)p;          q = (struct htmlq *)p;
   
           /* LINTED */
         while ((n = q->last)) {          while ((n = q->last)) {
                 q->last = n->parent;                  q->last = n->parent;
                 free(n);                  free(n);
Line 701  html_free(void *p)
Line 845  html_free(void *p)
 }  }
   
   
   static ssize_t
   html_beginhttp(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
           size_t           res;
           struct html_pair pair;
   
           res = 0;
           pair.attr = HTML_ATTR_HREF;
           pair.val = (char *)buf;
   
           if ( ! html_aput(mbuf, ML_OPEN, HTML_TAG_A, &res, 1, &pair))
                   return(-1);
           return((ssize_t)res);
   }
   
   
   static ssize_t
   html_endhttp(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
           size_t           res;
   
           res = 0;
           if ( ! html_tput(mbuf, ML_CLOSE, HTML_TAG_A, &res))
                   return(-1);
           return((ssize_t)res);
   }
   
   
   /* ARGSUSED */
   static ssize_t
   html_beginstring(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
   
           if (0 == strncmp(buf, "http://", 7))
                   return(html_beginhttp(mbuf, args, buf, sz));
   
           return(0);
   }
   
   
   /* ARGSUSED */
   static ssize_t
   html_endstring(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
   
           if (0 == strncmp(buf, "http://", 7))
                   return(html_endhttp(mbuf, args, buf, sz));
   
           return(0);
   }
   
   
 int  int
 md_line_html(void *data, char *buf)  md_line_html(void *data, char *buf)
 {  {
Line 729  md_init_html(const struct md_args *args,
Line 933  md_init_html(const struct md_args *args,
         cbs.ml_endtag = html_endtag;          cbs.ml_endtag = html_endtag;
         cbs.ml_begin = html_begin;          cbs.ml_begin = html_begin;
         cbs.ml_end = html_end;          cbs.ml_end = html_end;
           cbs.ml_beginstring = html_beginstring;
           cbs.ml_endstring = html_endstring;
   
         return(mlg_alloc(args, rbuf, mbuf, &cbs));          return(mlg_alloc(args, rbuf, mbuf, &cbs));
 }  }
   

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.20

CVSweb