groff
[Top][All Lists]
Advanced

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

[Groff] Suggested patch to post-html.cpp


From: Robert Bocchino
Subject: [Groff] Suggested patch to post-html.cpp
Date: Wed, 17 Sep 2014 20:25:40 -0700

Hi,

Attached for your review is a suggested patch to post-html.cpp.  The motivation 
is that grohtml occasionally bungles the formatting of indented lists.  Bug 
30043 seems related, although that one is focused mainly on interactions with 
-mdoc.  -ms is what I use for my day-to-day formatting.

After studying the problem I noticed that post-html.cpp was inserting spurious 
table breaks into the middle of lists (for example between a bullet and its 
associated item) producing mangled output.  My solution is to add table breaks 
at all line ends and only at line ends within a list.  This seems to correct 
the problem and also simplifies the logic.

For example, this approach produces good results with groff -ms -Thtml applied 
to this:

        .nr PS 12p
        .IP \[bu]
        Item

And to this:

        .if \n[MI]=0 .nr MI 4n
        .nr PS 12
        .LP
        Item
        .IP "\h'\n[MI]u-\w'1.'u'1." 
        Item
        .RS
        .IP "\h'\n[MI]u-\w'a.'u'a." 
        Item
        .RE

whereas the head version in the repository produces mangled output for both.

Please note that I have in no way adequately tested this.  I've just tried out 
a few examples, and they seem to work.  I realize that grohtml has to work with 
lots of macro packages, is doing a lot of complicated stuff only some of which 
I've been able to figure out so far, etc.  Any suggestions about how to do 
proper regression testing on this or other patches would be most welcome!  Also 
suggestions on the patch itself are welcome.  As I mentioned before, my goal is 
to eventually learn enough about how grohtml works that I can do active 
development on it.

Anyway, let me know what you think.

Rob

diff --git a/src/devices/grohtml/post-html.cpp 
b/src/devices/grohtml/post-html.cpp
index f4656a0..95847e8 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -3662,17 +3662,6 @@ void html_printer::lookahead_for_tables (void)
       nf = calc_nf(g, nf);
       calc_po_in(g, nf);
       if (g->is_col()) {
-       if (type_of_col == tab_tag && start_of_table != NULL) {
-         page_contents->glyphs.move_left();
-         insert_tab_te();
-         start_of_table->remember_table(tbl);
-         tbl = new html_table(&html, -1);
-         page_contents->insert_tag(string("*** TAB -> COL ***"));
-         if (tab_defs != NULL)
-           tbl->tab_stops->init(tab_defs);
-         start_of_table = NULL;
-         last = NULL;
-       }
        type_of_col = col_tag;
        found_col = TRUE;
        ncol = g->get_arg();
@@ -3689,15 +3678,6 @@ void html_printer::lookahead_for_tables (void)
        if (colmax > 0)
          colmax += pageoffset + get_troff_indent();
       } else if (g->is_tab0()) {
-       if (type_of_col == col_tag && start_of_table != NULL) {
-         page_contents->glyphs.move_left();
-         insert_tab_te();
-         start_of_table->remember_table(tbl);
-         tbl = new html_table(&html, -1);
-         page_contents->insert_tag(string("*** COL -> TAB ***"));
-         start_of_table = NULL;
-         last = NULL;
-       }
        if (tab_defs != NULL)
          tbl->tab_stops->init(tab_defs);
 
@@ -3712,45 +3692,17 @@ void html_printer::lookahead_for_tables (void)
          && (start_of_line != NULL) && (start_of_table == NULL)) {
        start_of_table = insert_tab_ts(start_of_line);
        start_of_line = NULL;
-      } else if (g->is_ce() && (start_of_table != NULL)) {
-       add_table_end("*** CE ***");
-       start_of_table->remember_table(tbl);
-       tbl = new html_table(&html, -1);
-       start_of_table = NULL;
-       last = NULL;
       } else if (g->is_ta()) {
        tab_defs = g->text_string;
 
        if (type_of_col == col_tag)
          tbl->tab_stops->check_init(tab_defs);
 
-       if (!tbl->tab_stops->compatible(tab_defs)) {
-         if (start_of_table != NULL) {
-           add_table_end("*** TABS ***");
-           start_of_table->remember_table(tbl);
-           tbl = new html_table(&html, -1);
-           start_of_table = NULL;
-           type_of_col = none;
-           last = NULL;
-         }
-         tbl->tab_stops->init(tab_defs);
-       }
       }
 
       if (((! g->is_a_tag()) || g->is_tab()) && (start_of_table != NULL)) {
        // we are in a table and have a glyph
-       if ((ncol == 0) || (! tbl->add_column(ncol, colmin, colmax, align))) {
-         if (ncol == 0)
-           add_table_end("*** NCOL == 0 ***");
-         else
-           add_table_end("*** CROSSED COLS ***");
-
-         start_of_table->remember_table(tbl);
-         tbl = new html_table(&html, -1);
-         start_of_table = NULL;
-         type_of_col = none;
-         last = NULL;
-       }
+        tbl->add_column(ncol, colmin, colmax, align);
       }
       
       /*
@@ -3772,6 +3724,16 @@ void html_printer::lookahead_for_tables (void)
          handle_state_assertion(g);
          nf = calc_nf(g, nf);
        } while ((g != NULL) && (g->is_br() || (nf && g->is_eol())));
+
+        if (start_of_table != NULL) {
+          add_table_end("*** NEW LINE ***");
+         start_of_table->remember_table(tbl);
+         tbl = new html_table(&html, -1);
+         tbl->tab_stops->init(tab_defs);
+         start_of_table = NULL;
+         last = NULL;
+       }
+
        start_of_line = g;
        ncol = 0;
        if (found_col)


Robert L. Bocchino Jr.
291 S. Euclid Ave., Apt. PH8
Pasadena, CA  91101
(217) 979-1053



reply via email to

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