iabudiab / HTMLKit

An Objective-C framework for your everyday HTML needs.
MIT License
239 stars 27 forks source link

Custom self closing tags are not detected properly. #40

Open MohideenSheikSulaiman opened 4 years ago

MohideenSheikSulaiman commented 4 years ago

Hi,

I have an issue with HTML-Kit. When I parse an HTML content which has few self-closing custom tags, it is not detected properly.

Here is the sample code,

Screenshot 2020-05-11 at 11 24 22 AM

NSArray *images = [self.document querySelectorAll:@"MyTag"];

Pls, see the array results in below image

Screenshot 2020-05-11 at 11 24 27 AM
iabudiab commented 4 years ago

@MohideenSheikSulaiman hey there. The behaviour is correct, custom elements can't be self-closing. In this case the parser tries to guess the correct nesting of the custom elements, and you get the second <MyTag> inside the first one. According to the HTML spec only some specified elements can be self-closing (void elements & foreign).

Take a look here: HTML Elements Syntax. The void elements are: area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr

You can put your html in a file and open it in any browser you like, chrome, firefox ..etc. All of them will behave the same. Here is chrome for example doing the same: Screenshot 2020-05-12 at 00 57 23

MohideenSheikSulaiman commented 4 years ago

@iabudiab Thanks for the info. We are using custom self-closing tags in the HTML to transfer the content between the devices. When we parse the HTML, we convert the custom tags to the defined HTML elements. So the above case creates a problem. Data loss happens.

It will be better if you can provide a custom tags support along with the (The void elements are: area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr).

Is it possible to provide an option to pass the custom self-closing tags as an input to the parser.?

MohideenSheikSulaiman commented 4 years ago

@iabudiab