question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue parsing nested HTML elements

See original GitHub issue

First of all thanks for you work on the library. We’ve recently adopted it and encountered an issue when trying to parse and render some markdown mixed with HTML (which is there to provide backwards compatibility with another system, hence can’t be removed).

In fact when trying to parse three nested <div>s:

<div>
  <div>
    <div></div>
  </div>
</div>

markdown-to-jsx will output this:

<div>
  <div></div>
  <div></div>
</div>
<p>&lt;/div&gt;</p>

It can be reproduced on the demo site, and it seems to happen when triple-nesting any HTML element. The issue looks similar to https://github.com/probablyup/markdown-to-jsx/issues/168 but I’m not sure if it’s exactly the same problem.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Oct 12, 2019

True, but none of those are small enough to fit the size requirement of this library. It will never be perfect, but it’s good enough for most use cases.

On Sat, Oct 12, 2019 at 9:36 AM James Thistlewood notifications@github.com wrote:

Ok, so I’ve taken a long look at this. The problem basically stems from the fact that regex is being used to parse HTML. HTML is not a regular language, and you cannot use regex to parse it https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454. You can make it seem like it works, but it will never properly work, hence bugs like this.

I’d recommend using a real XML/HTML parser instead.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/probablyup/markdown-to-jsx/issues/255?email_source=notifications&email_token=AAELFVVKI2KKQSKBY53SPEDQOHHF7A5CNFSM4HXJOSXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBB7TBY#issuecomment-541325703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAELFVRHOFUK5WMS3DGWC4LQOHHF7ANCNFSM4HXJOSXA .

1reaction
jthistlecommented, Oct 12, 2019

Ok, so I’ve taken a long look at this. The problem basically stems from the fact that regex is being used to parse HTML. HTML is not a regular language, and you cannot use regex to parse it. You can make it seem like it works, but it will never properly work, hence bugs like this.

I’d recommend using a real XML/HTML parser instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems when parsing nested html tags from string
I have this code that's to parse a string into html and display the text of each element. That's working good except when...
Read more >
Fix 'cannot parse selector' error for nested HTML elements
We've forked the parser we use for CSS-in-JS into stylelint organisation, and we're looking for help to fix our fork to close this...
Read more >
Possible bug with not parsing "<", "&", ">" correctly in code ...
Hi - I'm working with Github Pages and Jekyll and I've run into an issue with the characters “<”, “>”, and “&” showing...
Read more >
Understanding Success Criterion 4.1.1
4.1.1 Parsing: In content implemented using markup languages, elements have complete start and end tags, elements are nested according to their ...
Read more >
Nested tag parsing problem
… where html_form_tag displays an html form that includes the parsed results of the nested_tag output. This doesn't: {logging_tag} log this: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found