@@ -2113,17 +2113,18 @@ static void write_document(document_t *doc)
2113
2113
2114
2114
cprintf_init (param_charset_out , param_outputf );
2115
2115
2116
- /* write <?xml... */
2117
- cprintf ("%s?xml version=\"1.0\"" , lt );
2118
- /* if (document->encoding[0]) */
2119
- /* cprintf(" encoding=\"%s\"",document->encoding); */
2120
- cprintf (" encoding=\"%s\"" , param_charset_out -> preferred_name );
2121
- cprintf ("?%s%s%s" , gt , eol , eol );
2122
-
2123
- /* write <!DOCTYPE... */
2124
- cprintf ("%s!DOCTYPE html%s %s%s \"%s\" %s%s" ,
2125
- lt , eol , doctype_string [doctype ], eol , dtd_string [doctype ], gt , eol );
2126
-
2116
+ if (!param_generate_snippet ) {
2117
+ /* write <?xml... */
2118
+ cprintf ("%s?xml version=\"1.0\"" , lt );
2119
+ /* if (document->encoding[0]) */
2120
+ /* cprintf(" encoding=\"%s\"",document->encoding); */
2121
+ cprintf (" encoding=\"%s\"" , param_charset_out -> preferred_name );
2122
+ cprintf ("?%s%s%s" , gt , eol , eol );
2123
+
2124
+ /* write <!DOCTYPE... */
2125
+ cprintf ("%s!DOCTYPE html%s %s%s \"%s\" %s%s" ,
2126
+ lt , eol , doctype_string [doctype ], eol , dtd_string [doctype ], gt , eol );
2127
+ }
2127
2128
p = doc -> inicio ;
2128
2129
indent = 0 ;
2129
2130
write_node (p );
@@ -2157,14 +2158,29 @@ static int write_node(tree_node_t *node)
2157
2158
return len ;
2158
2159
}
2159
2160
2161
+ static int should_write_element (tree_node_t * nodo )
2162
+ {
2163
+ return !(param_generate_snippet && (ELM_ID (nodo ) == ELMID_HEAD ));
2164
+ }
2165
+
2166
+ static int should_write_tags (tree_node_t * nodo )
2167
+ {
2168
+ return !(param_generate_snippet && (ELM_ID (nodo ) == ELMID_HTML
2169
+ || ELM_ID (nodo ) == ELMID_BODY ));
2170
+ }
2160
2171
2161
2172
static int write_element (tree_node_t * elm )
2162
2173
{
2163
2174
int len = 0 ;
2164
2175
tree_node_t * n ;
2165
2176
int is_block ;
2166
2177
int xml_space_activated ;
2178
+ int writes_tags ;
2167
2179
2180
+ if (!should_write_element (elm ))
2181
+ return 0 ;
2182
+
2183
+ writes_tags = should_write_tags (elm );
2168
2184
is_block = dtd_elm_is_block (ELM_ID (elm ));
2169
2185
2170
2186
/* activate "xml:space preserve" if necessary */
@@ -2183,45 +2199,50 @@ static int write_element(tree_node_t *elm)
2183
2199
}
2184
2200
2185
2201
/* write start tag */
2186
- if (is_block ) {
2187
- len += write_indent (indent , 1 );
2188
- inline_on = 0 ;
2189
- } else {
2190
- if (!inline_on ) {
2191
- inline_on = 1 ;
2192
- whitespace_needed = 0 ;
2193
- if (!param_compact_block_elms )
2194
- len += write_indent (indent , 1 );
2202
+ // if (param_generate_snippet && elm == html
2203
+ if (writes_tags ) {
2204
+ if (is_block ) {
2205
+ len += write_indent (indent , 1 );
2206
+ inline_on = 0 ;
2207
+ } else {
2208
+ if (!inline_on ) {
2209
+ inline_on = 1 ;
2210
+ whitespace_needed = 0 ;
2211
+ if (!param_compact_block_elms )
2212
+ len += write_indent (indent , 1 );
2213
+ }
2195
2214
}
2215
+ len += write_start_tag (elm );
2196
2216
}
2197
- len += write_start_tag (elm );
2198
2217
2199
2218
/* process children nodes */
2200
2219
n = elm -> cont .elemento .hijo ;
2201
- if (is_block )
2220
+ if (is_block && writes_tags )
2202
2221
indent += param_tab_len ;
2203
2222
while (n ) {
2204
2223
len += write_node (n );
2205
2224
n = n -> sig ;
2206
2225
}
2207
- if (is_block )
2226
+ if (is_block && writes_tags )
2208
2227
indent -= param_tab_len ;
2209
2228
2210
2229
/* write end tag if not empty */
2211
- if (elm -> cont .elemento .hijo ) {
2230
+ if (writes_tags ) {
2231
+ if (elm -> cont .elemento .hijo ) {
2212
2232
if (is_block ) {
2213
2233
if (inline_on ) {
2214
- inline_on = 0 ;
2215
- if (!param_compact_block_elms )
2216
- len += write_indent (indent , 1 );
2234
+ inline_on = 0 ;
2235
+ if (!param_compact_block_elms )
2236
+ len += write_indent (indent , 1 );
2217
2237
} else {
2218
- len += write_indent (indent , 1 );
2238
+ len += write_indent (indent , 1 );
2219
2239
}
2220
2240
}
2221
2241
len += write_end_tag (elm );
2222
- } else if (!param_empty_tags
2223
- && elm_list [ELM_ID (elm )].contenttype [doctype ] != CONTTYPE_EMPTY ) {
2242
+ } else if (!param_empty_tags
2243
+ && elm_list [ELM_ID (elm )].contenttype [doctype ] != CONTTYPE_EMPTY ) {
2224
2244
len += write_end_tag (elm );
2245
+ }
2225
2246
}
2226
2247
2227
2248
/* deactivate "xml:space preserve" if activated */
@@ -2403,7 +2424,6 @@ static int write_start_tag(tree_node_t* nodo)
2403
2424
char * elm_name ;
2404
2425
int elm_name_len ;
2405
2426
int printed ;
2406
-
2407
2427
2408
2428
elm_name = elm_list [ELM_ID (nodo )].name ;
2409
2429
elm_name_len = strlen (elm_name );
0 commit comments