bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

html font tags fixed


From: Werner LEMBERG
Subject: html font tags fixed
Date: Thu, 24 Oct 2002 10:52:17 +0200 (CEST)

Below is a patch (relative to texinfo 4.2) which finally fixes html
font tags.  With this patch, groff.texinfo is processed perfectly.

The only drawback is that there are a lot of redundant <foo></foo>
tags; using

  sed -e 's|<\(.*\)></\1||g'

afterwards cleans this up.  Handling such redundant tags within
makeinfo is quite complicated; I think it's not worth the trouble.


    Werner


PS: Contrary to what you've told me, I couldn't see my latest patches
    applied to the CVS.  Maybe a missing commit?

======================================================================

2002-10-24  Werner Lemberg  <address@hidden>

        Fix html font tags, i.e., make the output similar to
        texinfo.tex.  The main idea is to avoid nested font tags.

        * makeinfo/html.c (push_tag, pop_tag): New functions.
        (insert_html_tag): Use them.
        Don't emit more than a single font attribute.

        * makeinfo/html.h (HSTACK): New structure.

        * makeinfo/defun.c: Include cmds.h and html.h.
        (process_defun_args): Don't apply <i>...</i> to parentheses
        and brackets.
        (defun_internal): Use insert_html_tag for emitting font tags.

        * makeinfo/cmds.c (cm_url): Use insert_html_tag for emitting
        font tag.
        (cm_r): Simplify.

======================================================================

--- ./makeinfo/defun.c.old      Mon Mar 18 17:54:54 2002
+++ ./makeinfo/defun.c  Thu Oct 24 10:48:11 2002
@@ -22,6 +22,8 @@
 #include "docbook.h"
 #include "insertion.h"
 #include "makeinfo.h"
+#include "cmds.h"
+#include "html.h"
 
 
 #define DEFUN_SELF_DELIMITING(c) \
@@ -239,7 +241,13 @@
         }
 
       if (DEFUN_SELF_DELIMITING (defun_arg[0]))
-        add_char (defun_arg[0]);
+        {
+          /* Within @deffn and friends, texinfo.tex makes parentheses
+             sans serif and brackets bold.  We use roman instead.  */
+          insert_html_tag (START, "");
+          add_char (defun_arg[0]);
+          insert_html_tag (END, "");
+        }
       else if (defun_arg[0] == '&')
         if (html)
           {
@@ -506,30 +514,34 @@
         case defvr:
         case deftp:
           /* <i> is for the following function arguments.  */
-          add_word ("<b>");
+          insert_html_tag (START, "b");
           execute_string ("%s", defined_name);
-          add_word ("</b><i>");
+          insert_html_tag (END, "b");
+          insert_html_tag (START, "i");
           break;
         case deftypefn:
         case deftypevr:
           execute_string ("%s ", type_name);
-          add_word ("<b>");
+          insert_html_tag (START, "b");
           execute_string ("%s", defined_name);
-          add_word ("</b><i>");
+          insert_html_tag (END, "b");
+          insert_html_tag (START, "i");
           break;
         case defcv:
         case defop:
-          add_word ("<b>");
+          insert_html_tag (START, "b");
           execute_string ("%s", defined_name);
-          add_word ("</b><i>");
+          insert_html_tag (END, "b");
+          insert_html_tag (START, "i");
           break;
         case deftypemethod:
         case deftypeop:
         case deftypeivar:
           execute_string ("%s ", type_name2);
-          add_word ("<b>");
+          insert_html_tag (START, "b");
           execute_string ("%s", defined_name);
-          add_word ("</b><i>");
+          insert_html_tag (END, "b");
+          insert_html_tag (START, "i");
           break;
         }
     } /* if (html)... */
@@ -602,7 +614,7 @@
         case deftp:
         case deftypefn:
         case deftypevr:
-          add_word ("</i>"); /* close italic area for arguments */
+          insert_html_tag (END, "i"); /* close italic area for arguments */
           /* put the rest into the second column */
          add_word ("</td>\n");
           add_html_elt ("<td align=\"right\">");
@@ -618,14 +630,14 @@
         case defop:
         case deftypemethod:
         case deftypeop:
-         add_word ("</i>");
+          insert_html_tag (END, "i");
          add_word ("</td>\n");
          add_html_elt ("<td align=\"right\">");
          execute_string ("%s %s %s", category, _("on"), type_name);
          break;
 
         case deftypeivar:
-         add_word ("</i>");
+          insert_html_tag (END, "i");
          add_word ("</td>\n");
          add_html_elt ("<td align=\"right\">");
          execute_string ("%s %s %s", category, _("of"), type_name);
--- ./makeinfo/cmds.c.old       Thu Mar 28 17:35:29 2002
+++ ./makeinfo/cmds.c   Thu Oct 24 10:00:09 2002
@@ -604,9 +604,10 @@
   else if (html)
     {
       if (arg == START)
-        add_word ("&lt;<code>");
-      else
-       add_word ("</code>&gt;");
+        add_word ("&lt;");
+      insert_html_tag (arg, "code");
+      if (arg != START)
+        add_word ("&gt;");
     }
   else
     if (arg == START)
@@ -872,25 +873,9 @@
     xml_insert_element (R, arg);
   else
     {
-      extern int printing_index;
+      if (html)
+       insert_html_tag (arg, "");
 
-      /* People use @r{} in index entries like this:
-        
-      @findex address@hidden, some text}
-      
-      This is supposed to produce output as if the entry were saying
-      "@code{foo}, some text", since the "fn" index is typeset as
-      @code.  The following attempts to do the same in HTML.  Note that
-      this relies on the fact that only @code bumps up the variable
-      in_fixed_width_font while processing index entries in HTML mode.  */
-      if (html && printing_index)
-       {
-         int level = in_fixed_width_font;
-         
-         while (level--)
-           insert_html_tag (arg == START ? END : START, "code");
-       }
-      
       not_fixed_width (arg);
     }
 }
@@ -1115,7 +1100,7 @@
   execute_string ("%s", (char *)line);
   free (line);
   uninhibit_output_flushing ();
-   if (html)
+  if (html)
     add_word ("</div>");
 
    else
--- ./makeinfo/html.c.old       Mon Apr  1 16:03:36 2002
+++ ./makeinfo/html.c   Thu Oct 24 10:11:39 2002
@@ -24,6 +24,8 @@
 #include "makeinfo.h"
 #include "sectioning.h"
 
+HSTACK *htmlstack = NULL;
+
 /* See html.h.  */
 int html_output_head_p = 0;
 
@@ -135,6 +137,31 @@
   free (string);
   return newstring - newlen;
 }
+
+/* Save current tag.  */
+void
+push_tag (tag)
+     char *tag;
+{
+  HSTACK *newstack = xmalloc (sizeof (HSTACK));
+
+  newstack->tag = tag;
+  newstack->next = htmlstack;
+  htmlstack = newstack;
+}
+
+/* Get last tag.  */
+void
+pop_tag ()
+{
+  HSTACK *tos = htmlstack;
+
+  if (!tos)
+    abort();
+
+  htmlstack = htmlstack->next;
+  free (tos);
+}
 
 /* Open or close TAG according to START_OR_END. */
 void
@@ -150,11 +177,52 @@
       adjust_braces_following (output_paragraph_offset, 3);
       add_word ("<p>");
     }
-  add_char ('<');
+
+  if (start_or_end == START)
+    {
+      if (htmlstack
+          && (strcmp (htmlstack->tag, tag) == 0))
+        return;
+    }
+  else
+    {
+      if (htmlstack && htmlstack->next
+          && (strcmp (htmlstack->next->tag, tag) == 0))
+        return;
+    }
+
+  if (start_or_end == START)
+    {
+      /* texinfo.tex doesn't support more than one font attribute
+         at the same time.  */
+      if (htmlstack && *(htmlstack->tag))
+        {
+          add_word ("</");
+          add_word (htmlstack->tag);
+          add_char ('>');
+        }
+      push_tag (tag);
+    }
+
+  if (*tag)
+    {
+      add_char ('<');
+      if (start_or_end != START)
+        add_char ('/');
+      add_word (tag);
+      add_char ('>');
+    }
+
   if (start_or_end != START)
-    add_char ('/');
-  add_word (tag);
-  add_char ('>');
+    {
+      pop_tag ();
+      if (htmlstack && *(htmlstack->tag))
+        {
+          add_char ('<');
+          add_word (htmlstack->tag);
+          add_char ('>');
+        }
+    }
 }
 
 /* Output an HTML <link> to the filename for NODE, including the
--- ./makeinfo/html.h.old       Mon Mar 18 20:45:18 2002
+++ ./makeinfo/html.h   Thu Oct 24 10:25:05 2002
@@ -20,6 +20,13 @@
 #ifndef HTML_H
 #define HTML_H
 
+/* A stack of font tags.  */
+typedef struct hstack
+{
+  struct hstack *next;
+  char *tag;
+} HSTACK;
+
 /* Nonzero if we have output the <head>.  */
 extern int html_output_head_p;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]