@@ -546,6 +546,7 @@ typedef struct {
546546 GumboNode * * nested_lists ;
547547 int * nested_count ;
548548 int max_nested ;
549+ bool has_emitted ;
549550} li_ctx_t ;
550551
551552static void flatten_li_node (GumboNode * node , buffer_t * ib , buffer_t * out ,
@@ -562,6 +563,7 @@ static void flush_li_buffer(buffer_t *ib, buffer_t *out, li_ctx_t *ctx) {
562563 emit_styles_close (out , ctx -> styles );
563564 buffer_append_str (out , "</li>" );
564565 buffer_clear (ib );
566+ ctx -> has_emitted = true;
565567}
566568
567569static void flatten_li_children (GumboNode * node , buffer_t * ib , buffer_t * out ,
@@ -885,6 +887,14 @@ static void walk_node(GumboNode *node, buffer_t *out) {
885887 li_ctx_t ctx = {el , es , nested_lists , & nested_count , 16 };
886888 flatten_li_children (node , & li_ib , out , & ctx );
887889 flush_li_buffer (& li_ib , out , & ctx );
890+
891+ /* if nothing emitted - the <li> is empty, we add it manually */
892+ if (!ctx .has_emitted ) {
893+ buffer_append_str (out , "<li" );
894+ emit_attributes (el , "li" , out );
895+ buffer_append_str (out , "></li>" );
896+ }
897+
888898 free (li_ib .data );
889899 for (int k = 0 ; k < nested_count ; k ++ )
890900 walk_children (nested_lists [k ], out );
0 commit comments