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

Diff for /mandoc/html.c between version 1.195 and 1.196

version 1.195, 2017/01/17 15:32:43 version 1.196, 2017/01/18 19:22:21
Line 38 
Line 38 
 struct  htmldata {  struct  htmldata {
         const char       *name;          const char       *name;
         int               flags;          int               flags;
 #define HTML_CLRLINE     (1 << 0)  #define HTML_NOSTACK     (1 << 0)
 #define HTML_NOSTACK     (1 << 1)  #define HTML_AUTOCLOSE   (1 << 1)
 #define HTML_AUTOCLOSE   (1 << 2) /* Tag has auto-closure. */  #define HTML_NLBEFORE    (1 << 2)
   #define HTML_NLBEGIN     (1 << 3)
   #define HTML_NLEND       (1 << 4)
   #define HTML_NLAFTER     (1 << 5)
   #define HTML_NLAROUND    (HTML_NLBEFORE | HTML_NLAFTER)
   #define HTML_NLINSIDE    (HTML_NLBEGIN | HTML_NLEND)
   #define HTML_NLALL       (HTML_NLAROUND | HTML_NLINSIDE)
   #define HTML_INDENT      (1 << 6)
   #define HTML_NOINDENT    (1 << 7)
 };  };
   
 static  const struct htmldata htmltags[TAG_MAX] = {  static  const struct htmldata htmltags[TAG_MAX] = {
         {"html",        HTML_CLRLINE}, /* TAG_HTML */          {"html",        HTML_NLALL},
         {"head",        HTML_CLRLINE}, /* TAG_HEAD */          {"head",        HTML_NLALL | HTML_INDENT},
         {"body",        HTML_CLRLINE}, /* TAG_BODY */          {"body",        HTML_NLALL},
         {"meta",        HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_META */          {"meta",        HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
         {"title",       HTML_CLRLINE}, /* TAG_TITLE */          {"title",       HTML_NLAROUND},
         {"div",         HTML_CLRLINE}, /* TAG_DIV */          {"div",         HTML_NLAROUND},
         {"h1",          0}, /* TAG_H1 */          {"h1",          HTML_NLAROUND},
         {"h2",          0}, /* TAG_H2 */          {"h2",          HTML_NLAROUND},
         {"span",        0}, /* TAG_SPAN */          {"span",        0},
         {"link",        HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_LINK */          {"link",        HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
         {"br",          HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_BR */          {"br",          HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
         {"a",           0}, /* TAG_A */          {"a",           0},
         {"table",       HTML_CLRLINE}, /* TAG_TABLE */          {"table",       HTML_NLALL | HTML_INDENT},
         {"tbody",       HTML_CLRLINE}, /* TAG_TBODY */          {"tbody",       HTML_NLALL | HTML_INDENT},
         {"col",         HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_COL */          {"col",         HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL},
         {"tr",          HTML_CLRLINE}, /* TAG_TR */          {"tr",          HTML_NLALL | HTML_INDENT},
         {"td",          HTML_CLRLINE}, /* TAG_TD */          {"td",          HTML_NLAROUND},
         {"li",          HTML_CLRLINE}, /* TAG_LI */          {"li",          HTML_NLAROUND | HTML_INDENT},
         {"ul",          HTML_CLRLINE}, /* TAG_UL */          {"ul",          HTML_NLALL | HTML_INDENT},
         {"ol",          HTML_CLRLINE}, /* TAG_OL */          {"ol",          HTML_NLALL | HTML_INDENT},
         {"dl",          HTML_CLRLINE}, /* TAG_DL */          {"dl",          HTML_NLALL | HTML_INDENT},
         {"dt",          HTML_CLRLINE}, /* TAG_DT */          {"dt",          HTML_NLAROUND},
         {"dd",          HTML_CLRLINE}, /* TAG_DD */          {"dd",          HTML_NLAROUND | HTML_INDENT},
         {"blockquote",  HTML_CLRLINE}, /* TAG_BLOCKQUOTE */          {"blockquote",  HTML_NLALL | HTML_INDENT},
         {"pre",         HTML_CLRLINE }, /* TAG_PRE */          {"pre",         HTML_NLALL | HTML_NOINDENT},
         {"b",           0 }, /* TAG_B */          {"b",           0},
         {"i",           0 }, /* TAG_I */          {"i",           0},
         {"code",        0 }, /* TAG_CODE */          {"code",        0},
         {"small",       0 }, /* TAG_SMALL */          {"small",       0},
         {"style",       HTML_CLRLINE}, /* TAG_STYLE */          {"style",       HTML_NLALL | HTML_INDENT},
         {"math",        HTML_CLRLINE}, /* TAG_MATH */          {"math",        HTML_NLALL | HTML_INDENT},
         {"mrow",        0}, /* TAG_MROW */          {"mrow",        0},
         {"mi",          0}, /* TAG_MI */          {"mi",          0},
         {"mo",          0}, /* TAG_MO */          {"mo",          0},
         {"msup",        0}, /* TAG_MSUP */          {"msup",        0},
         {"msub",        0}, /* TAG_MSUB */          {"msub",        0},
         {"msubsup",     0}, /* TAG_MSUBSUP */          {"msubsup",     0},
         {"mfrac",       0}, /* TAG_MFRAC */          {"mfrac",       0},
         {"msqrt",       0}, /* TAG_MSQRT */          {"msqrt",       0},
         {"mfenced",     0}, /* TAG_MFENCED */          {"mfenced",     0},
         {"mtable",      0}, /* TAG_MTABLE */          {"mtable",      0},
         {"mtr",         0}, /* TAG_MTR */          {"mtr",         0},
         {"mtd",         0}, /* TAG_MTD */          {"mtd",         0},
         {"munderover",  0}, /* TAG_MUNDEROVER */          {"munderover",  0},
         {"munder",      0}, /* TAG_MUNDER*/          {"munder",      0},
         {"mover",       0}, /* TAG_MOVER*/          {"mover",       0},
 };  };
   
 static  const char      *const roffscales[SCALE_MAX] = {  static  const char      *const roffscales[SCALE_MAX] = {
Line 106  static const char *const roffscales[SCALE_MAX] = {
Line 114  static const char *const roffscales[SCALE_MAX] = {
 };  };
   
 static  void     a2width(const char *, struct roffsu *);  static  void     a2width(const char *, struct roffsu *);
   static  void     html_endline(struct html *);
   static  void     html_indent(struct html *);
 static  void     print_ctag(struct html *, struct tag *);  static  void     print_ctag(struct html *, struct tag *);
 static  int      print_escape(char);  static  int      print_escape(char);
 static  int      print_encode(struct html *, const char *, const char *, int);  static  int      print_encode(struct html *, const char *, const char *, int);
Line 156  print_gen_head(struct html *h)
Line 166  print_gen_head(struct html *h)
         /*          /*
          * Print a default style-sheet.           * Print a default style-sheet.
          */           */
   
         t = print_otag(h, TAG_STYLE, "");          t = print_otag(h, TAG_STYLE, "");
         print_text(h, "table.head, table.foot { width: 100%; }\n"          print_text(h, "table.head, table.foot { width: 100%; }");
               "td.head-rtitle, td.foot-os { text-align: right; }\n"          html_endline(h);
               "td.head-vol { text-align: center; }\n"          print_text(h, "td.head-rtitle, td.foot-os { text-align: right; }");
               "table.foot td { width: 50%; }\n"          html_endline(h);
               "table.head td { width: 33%; }\n"          print_text(h, "td.head-vol { text-align: center; }");
               "div.spacer { margin: 1em 0; }\n");          html_endline(h);
           print_text(h, "table.foot td { width: 50%; }");
           html_endline(h);
           print_text(h, "table.head td { width: 33%; }");
           html_endline(h);
           print_text(h, "div.spacer { margin: 1em 0; }");
         print_tagq(h, t);          print_tagq(h, t);
   
         if (h->style)          if (h->style)
Line 435  print_otag(struct html *h, enum htmltag tag, const cha
Line 451  print_otag(struct html *h, enum htmltag tag, const cha
         const char      *attr;          const char      *attr;
         char            *s;          char            *s;
         double           v;          double           v;
         int              i, have_style;          int              i, have_style, tflags;
   
           tflags = htmltags[tag].flags;
   
         /* Push this tags onto the stack of open scopes. */          /* Push this tags onto the stack of open scopes. */
   
         if ( ! (HTML_NOSTACK & htmltags[tag].flags)) {          if ((tflags & HTML_NOSTACK) == 0) {
                 t = mandoc_malloc(sizeof(struct tag));                  t = mandoc_malloc(sizeof(struct tag));
                 t->tag = tag;                  t->tag = tag;
                 t->next = h->tags.head;                  t->next = h->tags.head;
Line 447  print_otag(struct html *h, enum htmltag tag, const cha
Line 465  print_otag(struct html *h, enum htmltag tag, const cha
         } else          } else
                 t = NULL;                  t = NULL;
   
         if ( ! (HTML_NOSPACE & h->flags))          if (tflags & HTML_NLBEFORE)
                 if ( ! (HTML_CLRLINE & htmltags[tag].flags)) {                  html_endline(h);
                         /* Manage keeps! */          if (h->flags & HTML_NLDONE)
                         if ( ! (HTML_KEEP & h->flags)) {                  html_indent(h);
                                 if (HTML_PREKEEP & h->flags)          else if ((h->flags & HTML_NOSPACE) == 0) {
                                         h->flags |= HTML_KEEP;                  if (h->flags & HTML_KEEP)
                                 putchar(' ');                          printf("&#160;");
                         } else                  else {
                                 printf("&#160;");                          if (h->flags & HTML_PREKEEP)
                                   h->flags |= HTML_KEEP;
                           putchar(' ');
                 }                  }
           }
   
         if ( ! (h->flags & HTML_NONOSPACE))          if ( ! (h->flags & HTML_NONOSPACE))
                 h->flags &= ~HTML_NOSPACE;                  h->flags &= ~HTML_NOSPACE;
Line 596  print_otag(struct html *h, enum htmltag tag, const cha
Line 617  print_otag(struct html *h, enum htmltag tag, const cha
   
         putchar('>');          putchar('>');
   
         h->flags |= HTML_NOSPACE;          if (tflags & HTML_NLBEGIN)
                   html_endline(h);
           else
                   h->flags |= HTML_NOSPACE;
   
         if ((HTML_AUTOCLOSE | HTML_CLRLINE) & htmltags[tag].flags)          if (tflags & HTML_INDENT)
                 putchar('\n');                  h->indent++;
           if (tflags & HTML_NOINDENT)
                   h->noindent++;
   
         return t;          return t;
 }  }
Line 607  print_otag(struct html *h, enum htmltag tag, const cha
Line 633  print_otag(struct html *h, enum htmltag tag, const cha
 static void  static void
 print_ctag(struct html *h, struct tag *tag)  print_ctag(struct html *h, struct tag *tag)
 {  {
           int      tflags;
   
         /*          /*
          * Remember to close out and nullify the current           * Remember to close out and nullify the current
Line 617  print_ctag(struct html *h, struct tag *tag)
Line 644  print_ctag(struct html *h, struct tag *tag)
         if (tag == h->tblt)          if (tag == h->tblt)
                 h->tblt = NULL;                  h->tblt = NULL;
   
           tflags = htmltags[tag->tag].flags;
   
           if (tflags & HTML_INDENT)
                   h->indent--;
           if (tflags & HTML_NOINDENT)
                   h->noindent--;
           if (tflags & HTML_NLEND)
                   html_endline(h);
           html_indent(h);
         printf("</%s>", htmltags[tag->tag].name);          printf("</%s>", htmltags[tag->tag].name);
         if (HTML_CLRLINE & htmltags[tag->tag].flags) {          if (tflags & HTML_NLAFTER)
                 h->flags |= HTML_NOSPACE;                  html_endline(h);
                 putchar('\n');  
         }  
   
         h->tags.head = tag->next;          h->tags.head = tag->next;
         free(tag);          free(tag);
Line 632  print_gen_decls(struct html *h)
Line 666  print_gen_decls(struct html *h)
 {  {
   
         puts("<!DOCTYPE html>");          puts("<!DOCTYPE html>");
           h->flags |= HTML_NLDONE;
 }  }
   
 void  void
 print_text(struct html *h, const char *word)  print_text(struct html *h, const char *word)
 {  {
           if ((h->flags & (HTML_NLDONE | HTML_NOSPACE)) == 0) {
         if ( ! (HTML_NOSPACE & h->flags)) {  
                 /* Manage keeps! */  
                 if ( ! (HTML_KEEP & h->flags)) {                  if ( ! (HTML_KEEP & h->flags)) {
                         if (HTML_PREKEEP & h->flags)                          if (HTML_PREKEEP & h->flags)
                                 h->flags |= HTML_KEEP;                                  h->flags |= HTML_KEEP;
Line 661  print_text(struct html *h, const char *word)
Line 694  print_text(struct html *h, const char *word)
                 print_otag(h, TAG_I, "");                  print_otag(h, TAG_I, "");
                 break;                  break;
         default:          default:
                   html_indent(h);
                 break;                  break;
         }          }
   
Line 713  print_paragraph(struct html *h)
Line 747  print_paragraph(struct html *h)
         print_tagq(h, t);          print_tagq(h, t);
 }  }
   
   /*
    * If something was printed on the current output line, end it.
    * Not to be called right after html_indent().
    */
   static void
   html_endline(struct html *h)
   {
           if (h->flags & HTML_NLDONE)
                   return;
   
           putchar('\n');
           h->flags |= HTML_NLDONE | HTML_NOSPACE;
   }
   
   /*
    * If at the beginning of a new output line,
    * perform indentation and mark the line as containing output.
    * Make sure to really produce some output right afterwards,
    * but do not use print_otag() for producing it.
    */
   static void
   html_indent(struct html *h)
   {
           int      i;
   
           if ((h->flags & HTML_NLDONE) == 0)
                   return;
   
           if (h->noindent == 0)
                   for (i = 0; i < h->indent * 2; i++)
                           putchar(' ');
           h->flags &= ~(HTML_NLDONE | HTML_NOSPACE);
   }
   
 /*  /*
  * Calculate the scaling unit passed in a `-width' argument.  This uses   * Calculate the scaling unit passed in a `-width' argument.  This uses

Legend:
Removed from v.1.195  
changed lines
  Added in v.1.196

CVSweb