Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<source> tags are not parsed properly #50

Open
secretrobotron opened this issue Jun 22, 2012 · 1 comment
Open

<source> tags are not parsed properly #50

secretrobotron opened this issue Jun 22, 2012 · 1 comment

Comments

@secretrobotron
Copy link

I might be doing the readout wrong, but this is the second time I've picked this up. It seems that <source> isn't identified as a void tag, so they become children of one another when listed inside a <video>:

var htmlparser = require('htmlparser');

var htmlContent = "<html><head></head><body><video><source src=\"foo.ogv\"><source src=\"lol.smaz\"></video><div></div></body></html>";

var handler = new htmlparser.DefaultHandler(function (error, dom) {
  function parse(dom, spacing){
    console.log(spacing, dom.name);
    if(dom.children){
      for(var i=0; i<dom.children.length; ++i){
        parse(dom.children[i], spacing + ' ');
      }
    }
  }
  parse(dom[0], '');
});

new htmlparser.Parser(handler).parseComplete(htmlContent);
AndreasMadsen referenced this issue in AndreasMadsen/htmlparser2 Jun 10, 2013
[Tokenizer] don't reset CDATA state in case of long endings
@robcrocombe
Copy link

I came across this and thought I'd post my solution so someone else doesn't have to figure out one.

When I import htmlparser I add the new void elements to the existing list like this:

const htmlparser = require('htmlparser');

htmlparser.DefaultHandler._emptyTags = {
  ...htmlparser.DefaultHandler._emptyTags,
  source: 1,
  track: 1,
  wbr: 1,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants