tfix formatting inside <pre> containing markup - webdump - [FORK] git://git.codemadness.org/webdump
 (HTM) git clone git://git.z3bra.org/webdump.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f4dcb532c8a82ac9b3703312e0e1be0de355308b
 (DIR) parent e108b339266f4513f7e2aa97213e87f24b53b9b8
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Thu, 28 Nov 2019 19:16:14 +0100
       
       fix formatting inside <pre> containing markup
       
       refactor the node traversing function, make it more reusable.
       
       Diffstat:
         M webdump.c                           |      23 ++++++++++++++++-------
       
       1 file changed, 16 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/webdump.c b/webdump.c
       t@@ -287,6 +287,18 @@ printc(int c)
                }
        }
        
       +static struct node *
       +findparenttype(int cur, int findtype)
       +{
       +        int i;
       +
       +        for (i = cur; i; i--) {
       +                if ((nodes[i].tag.displaytype & findtype))
       +                        return &nodes[i];
       +        }
       +        return NULL;
       +}
       +
        /* Find nearest parent node belonging to type. For example a listitem -> list */
        static struct node *
        findparentoftype(int cur)
       t@@ -296,12 +308,7 @@ findparentoftype(int cur)
                if (!nodes[cur].tag.parenttype)
                        return NULL;
        
       -        for (i = cur; i; i--) {
       -                if ((nodes[i].tag.displaytype & nodes[cur].tag.parenttype))
       -                        return &nodes[i];
       -        }
       -
       -        return NULL;
       +        return findparenttype(cur, nodes[cur].tag.parenttype);
        }
        
        static void
       t@@ -513,7 +520,9 @@ xmldataend(XMLParser *p)
        
                if (cur->tag.displaytype == DisplayUnknown || (cur->tag.displaytype & DisplayNone)) {
                        /* nothing */
       -        } else if (cur->tag.displaytype & DisplayPre) {
       +        } else if ((cur->tag.displaytype & DisplayPre) ||
       +                   findparenttype(curnode, DisplayPre)) {
       +                /* if <pre> or inside it */
                        printsafe(htmldata.data, htmldata.len);
                } else {
                        start = htmldata.data;