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

<br /> tag ends up getting doubled #33

Closed
memloom-development opened this issue Jun 9, 2014 · 3 comments
Closed

<br /> tag ends up getting doubled #33

memloom-development opened this issue Jun 9, 2014 · 3 comments

Comments

@memloom-development
Copy link
Contributor

My input document uses the br tag inside of a foreign object. It uses the form <br />
The regex in svg() continues to produce valid markup:

"this is valid <br />".replace(/<(\w+)([^<]+?)\/>/g, '<$1$2></$1>')

produces what it should produce:

"this is valid <br ></br>"

However, then along comes the assignment to well.innerHTML and (on Chrome Version 35.0.1916.114) the HTML parser messes everything up. It replaces the correctly closed br tag with two unclosed br tags - as can be seen by the following console output

> well.innerHTML = "this is valid <br />".replace(/<(\w+)([^<]+?)\/>/g, '<$1$2></$1>')
"this is valid <br ></br>"
> well.innerHTML
"this is valid <br><br>"  // it's still valid html markup but not valid svg nor does it match the initial format

I don't think the regex should be changed - but there may need to be special handling for br (and hr plus any others?)

@wout
Copy link
Member

wout commented Jun 10, 2014

Unfortunately I can't help you with HTML inside a foreignObject as it is not related to svg or svg.js. I think stackoverflow will be the place to be.

@memloom-development
Copy link
Contributor Author

I have a hackish fix in place - I break the well formed tag by replacing <br /> with <br> so that your regex fixes them and it seems to give me the desired output. I'm not entirely sure why that works - but it does.

However, I think the "ultimate" solution would be for your import routine to not touch anything inside of a foreignObject tag. As you rightly say the content inside of the foreignObject tag is nothing to do with svg - because of that the contents shouldn't really be affected by your import routine...

However, I'm sure it's a low priority edge case for svg.js to deal with.

@wout
Copy link
Member

wout commented Jun 10, 2014

Great to hear you found a fix. Although, it might be a good idea to rework the import plugin to "adopt" html nodes in the foreignObject rather than importing them individually.

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