4 ms·
HTML is text. Using something other than strings to process text is unnatural, so even systems that care about correct syntax and correct escaping tend to go fr
by HelloNurse 3y ago
HTML is text. Using something other than strings to process text is unnatural, so even systems that care about correct syntax and correct escaping tend to go from syntax tree to actual HTML eagerly.
Moreover, important parts of HTML processing would be significantly more brittle and complicated and less powerful with objects: "escape some completely arbitrary text to valid PCDATA or a CDATA section, whatever is shorter" is strictly more general, robust and principled than "render a Street Address to a fragment that isn't supposed to contain markup".
- jameshart 3y agoHTML isn’t arbitrary text. HTML is a grammatically restricted subset of text. I can take arbitrary text and embed it in HTML by escaping characters within it. That produces a grammatical fragment of HTML that represents the arbitrary text, but it is not the text.
- ngneer 3y agoExactly. HTML has structure. It is not the same as flat text, although you can flatten and edit it as such. As an example sentence, take the following: "The French equivalent for the English "Good Evening!" is "Bonsoir!", whereas Italians might say "Buonasera!" to one another for similar effect." There are four languages in that sentence, two of which are English. You may need three editors to deal with them, or you can flatten the sentence and simply edit everything assuming you knew all three.
- fnordsensei 3y agoI guess this is true of all formal languages, then. Since we sit in front of text editors most of the time, the fundamental truth of all languages is that they are strings. This is not even true of natural language, which has a vocal representation that is at least as important as the written representation. Though I agree that representing HTML as objects is a poor substitute.
- HelloNurse 3y agoIt's a bit deeper: since HTML is defined as text markup, text is the truth of HTML documents and the standard of their users, while any sort of object representation of HTML documents is someone's idiosyncratic and possibly limited implementation, necessarily specialized and necessarily harder to use.
- jameshart 3y agoOn the contrary - the entire purpose of HTML is to construct a specific object model in a web browser. HTML is a serialization format for expressing DOM structure. It’s not ‘idiosyncratic’, it’s the way the language is defined.
- comex 3y agoJSON is text, but most code that works with JSON sticks with the "syntax tree" (i.e. some native object representation) and only handles decoding/encoding the actual JSON format at communication boundaries. The problem with HTML is that its syntax trees are relatively unpleasant to use.