initial support for <select> <option> - webdump - HTML to plain-text converter for webpages
 (HTM) git clone git://git.codemadness.org/webdump
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f4f2dc53e082fcbf627d567810c399c306009ea0
 (DIR) parent 20841145c9fd597e82c3da9dfa7c9d9caf606567
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed, 13 Sep 2023 20:37:28 +0200
       
       initial support for <select> <option>
       
       Show the first item, or all of the attribute is multiple.
       
       This ignores the actual selected item if <select><option selected>. This would
       require a state of all the option nodes which it doesn't do.
       
       Diffstat:
         M webdump.c                           |      27 +++++++++++++++++++++++++++
       
       1 file changed, 27 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/webdump.c b/webdump.c
       @@ -1598,6 +1598,11 @@ handleendtag(struct tag *tag)
                if (reader_ignore)
                        return;
        
       +        if (tag->displaytype & (DisplayButton | DisplayOption)) {
       +                hputchar(']');
       +                hflush();
       +        }
       +
                if (tag->displaytype & (DisplayBlock | DisplayHeader | DisplayTable | DisplayTableRow |
                        DisplayList | DisplayListItem | DisplayPre)) {
                        endblock(); /* break line if needed */
       @@ -1704,6 +1709,10 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort)
                        childs[0] = "td";
                        nchilds = 1;
                        parenttype = DisplayTable;
       +        } else if (found && found->displaytype & DisplaySelect) {
       +                childs[0] = "option";
       +                nchilds = 1;
       +                parenttype = DisplaySelect;
                } else if (found && found->displaytype & DisplayDl) {
                        childs[0] = "p";
                        childs[1] = "dd";
       @@ -1829,6 +1838,10 @@ xmltagstart(XMLParser *p, const char *t, size_t tl)
                                childs[0] = "p";
                                nchilds = 1;
                                parenttype = 0; /* seek until the root */
       +                } else if (!tagcmp(t, "option")) {
       +                        childs[0] = "option";
       +                        nchilds = 1;
       +                        parenttype = DisplaySelect;
                        } else if (!tagcmp(t, "dt")) {
                                childs[0] = "dd";
                                nchilds = 1;
       @@ -1954,6 +1967,15 @@ xmltagstartparsed(XMLParser *p, const char *t, size_t tl, int isshort)
                        handleinlinealt();
                }
        
       +        /* <select><option> */
       +        if (cur->tag.displaytype & DisplayOption) {
       +                /* <select multiple>: show all options */
       +                if (parent->tag.displaytype & DisplaySelectMulti)
       +                        cur->tag.displaytype |= DisplayBlock;
       +                else if (parent->nchildren > 1) /* show the first item as selected */
       +                        cur->tag.displaytype |= DisplayNone; /* else hide */
       +        }
       +
                if (cur->tag.displaytype & DisplayNone)
                        return;
        
       @@ -1968,6 +1990,11 @@ xmltagstartparsed(XMLParser *p, const char *t, size_t tl, int isshort)
                        startblock(); /* break line if needed */
                }
        
       +        if (cur->tag.displaytype & (DisplayButton | DisplayOption)) {
       +                hflush();
       +                hputchar('[');
       +        }
       +
                margintop = cur->tag.margintop;
                if (cur->tag.displaytype & (DisplayList)) {
                        for (i = curnode - 1; i >= 0; i--) {