grunt-dom-munger icon indicating copy to clipboard operation
grunt-dom-munger copied to clipboard

Adhere to Cheerio's XML mode when xmlMode option is specified

Open jcdarwin opened this issue 10 years ago • 3 comments

Cheerio exposes an option "xmlMode: true", which should be used to distinguish between writing out HTML ( $.html() ) and XML ( $.xml() ).

Therefore, in method processFile:

updatedContents = $.html();  

Should become:

if (options.xmlMode) {
        updatedContents = $.xml();
} else {
        updatedContents = $.html();  
}

jcdarwin avatar Aug 19 '13 10:08 jcdarwin

I'm trying to understand the use-case you're hitting. I don't mind making the addition but I was under the assumption that cheerio would endeavor to write the document back out with the same tags as before (plus whatever your modifications were). Is it not doing this or is there some similar kind of issue?

cgross avatar Aug 19 '13 14:08 cgross

The problem I'm having is that I'm appending some elements to an XML file, and unfortunately some other elements are ending up malformed.

In particular I start out with:

and, without this change, end up with:

(note the lack of the self closing /).

Actually, although this suggested change fixes this problem, I strike another problem with Cheerio (which the xmlMode doesn't help with) -- for another element, I start out with:

2012-08-20T03:18:06Z

and end up with:

2012-08-20T03:18:06Z

(i.e. it drops the entire closing tag).

There looks to be something buried in cheerio that specifically treats meta tags incorrectly -- I've yet to find the time to hunt it down but will do so in the next day or two.

Jason

On Tue, Aug 20, 2013 at 2:45 AM, Chris Gross [email protected]:

I'm trying to understand the use-case you're hitting. I don't mind making the addition but I was under the assumption that cheerio would endeavor to write the document back out with the same tags as before (plus whatever your modifications were). Is it not doing this or is there some similar kind of issue?

— Reply to this email directly or view it on GitHubhttps://github.com/cgross/grunt-dom-munger/issues/4#issuecomment-22877065 .

jcdarwin avatar Aug 19 '13 19:08 jcdarwin

Could we get this fixed? If cheerio would just write back the document unchanged, that would not be a problem, but it is removing all slashes from self closing elements (if you use $.html). That will break XHTML and polyglot documents.

A one liner like: var updatedContents = (options.xmlMode) ? $.xml() : $.html(); would suffice …

inta avatar May 08 '14 20:05 inta