Live data from Hacker News

Preventing line breaks in elements

alexwlchan.net

1–10 of 23 posts

Re: Preventing line breaks in <code> elements

#3
post #2

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

You can parse a subset of it though, like if you're in control of the html yourself and avoid certain structures

Re: Preventing line breaks in <code> elements

#6
post #4
post #2

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

Parsing HTML with a regex is never a good option, but it's sometimes the only option.

In the example from the article it certainly is an option. In Python you could either use a "soup" library or you could play around with a tool like https://www.w3.org/Tools/HTML-XML-utils/man1/hxpipe.html.

The more fundamental question for me is why the author didn't decide to make make code blocks non-breaking by default, or just add the class annotations when he writes the HTML?

Re: Preventing line breaks in <code> elements

#8
post #2

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

You can absolutely parse HTML with regex, so long as the document is finite in length. Every finite language is regular, hence can be parsed with regex's.

Re: Preventing line breaks in <code> elements

#10
post #8
post #2

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.

You can absolutely parse HTML with regex, so long as the document is finite in length. Every finite language is regular, hence can be parsed with regex's.

Do a web search for the parent of your comment, read the Stackoverflow answer. It's a classic. Learn about Zalgo and Tony the pony, he comes.
Post reply on HN