aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml.c
diff options
context:
space:
mode:
authorUlf Jasper2014-11-21 16:31:30 +0100
committerUlf Jasper2014-11-21 16:31:30 +0100
commitc39443c1d651bab2eb023f4c38db418c3dc04160 (patch)
tree6266035bf6e6f261440caa4bf5a6d3aafcc43b10 /src/xml.c
parente14c4354cf29fab12fb414c7ebc94bf1a9920dd0 (diff)
downloademacs-c39443c1d651bab2eb023f4c38db418c3dc04160.tar.gz
emacs-c39443c1d651bab2eb023f4c38db418c3dc04160.zip
'libxml-parse(html|xml)-region': new optional param 'discard-comments'.
* doc/lispref/text.texi (Parsing HTML/XML): Document new optional parameter 'discard-comments' of 'libxml-parse(html|xml)-region'. * src/xml.c (parse_region): Take care of new optional parameter 'discard-comments' of 'libxml-parse(html|xml)-region'. (Flibxml_parse_html_region, Flibxml_parse_xml_region): New optional parameter 'discard-comments'. * test/automated/libxml-tests.el (libxml-tests--data-comments-preserved): Renamed from 'libxml-tests--data'. (libxml-tests--data-comments-discarded): New. (libxml-tests): Check whether 'libxml-parse-xml-region' is discarding comments correctly.
Diffstat (limited to 'src/xml.c')
-rw-r--r--src/xml.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/xml.c b/src/xml.c
index 7e99beb1d05..d418202182b 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -175,7 +175,7 @@ make_dom (xmlNode *node)
175} 175}
176 176
177static Lisp_Object 177static Lisp_Object
178parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp) 178parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Object discard_comments, int htmlp)
179{ 179{
180 xmlDoc *doc; 180 xmlDoc *doc;
181 Lisp_Object result = Qnil; 181 Lisp_Object result = Qnil;
@@ -214,21 +214,24 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
214 214
215 if (doc != NULL) 215 if (doc != NULL)
216 { 216 {
217 /* If the document is just comments, then this should get us the
218 nodes anyway. */
219 xmlNode *n = doc->children;
220 Lisp_Object r = Qnil; 217 Lisp_Object r = Qnil;
221 218 if (NILP(discard_comments))
222 while (n) { 219 {
223 if (!NILP (r)) 220 /* If the document has toplevel comments, then this should
224 result = Fcons (r, result); 221 get us the nodes and the comments. */
225 r = make_dom (n); 222 xmlNode *n = doc->children;
226 n = n->next; 223
227 } 224 while (n) {
225 if (!NILP (r))
226 result = Fcons (r, result);
227 r = make_dom (n);
228 n = n->next;
229 }
230 }
228 231
229 if (NILP (result)) { 232 if (NILP (result)) {
230 /* The document isn't just comments, so get the tree the 233 /* The document doesn't have toplevel comments or we discarded
231 proper way. */ 234 them. Get the tree the proper way. */
232 xmlNode *node = fn_xmlDocGetRootElement (doc); 235 xmlNode *node = fn_xmlDocGetRootElement (doc);
233 if (node != NULL) 236 if (node != NULL)
234 result = make_dom (node); 237 result = make_dom (node);
@@ -251,25 +254,27 @@ xml_cleanup_parser (void)
251 254
252DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region, 255DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,
253 Slibxml_parse_html_region, 256 Slibxml_parse_html_region,
254 2, 3, 0, 257 2, 4, 0,
255 doc: /* Parse the region as an HTML document and return the parse tree. 258 doc: /* Parse the region as an HTML document and return the parse tree.
256If BASE-URL is non-nil, it is used to expand relative URLs. */) 259If BASE-URL is non-nil, it is used to expand relative URLs.
257 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 260If DISCARD-COMMENTS is non-nil, all HTML comments are discarded. */)
261 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Object discard_comments)
258{ 262{
259 if (init_libxml2_functions ()) 263 if (init_libxml2_functions ())
260 return parse_region (start, end, base_url, 1); 264 return parse_region (start, end, base_url, discard_comments, 1);
261 return Qnil; 265 return Qnil;
262} 266}
263 267
264DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region, 268DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region,
265 Slibxml_parse_xml_region, 269 Slibxml_parse_xml_region,
266 2, 3, 0, 270 2, 4, 0,
267 doc: /* Parse the region as an XML document and return the parse tree. 271 doc: /* Parse the region as an XML document and return the parse tree.
268If BASE-URL is non-nil, it is used to expand relative URLs. */) 272If BASE-URL is non-nil, it is used to expand relative URLs.
269 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url) 273If DISCARD-COMMENTS is non-nil, all HTML comments are discarded. */)
274 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, Lisp_Object discard_comments)
270{ 275{
271 if (init_libxml2_functions ()) 276 if (init_libxml2_functions ())
272 return parse_region (start, end, base_url, 0); 277 return parse_region (start, end, base_url, discard_comments, 0);
273 return Qnil; 278 return Qnil;
274} 279}
275 280