Live data from Hacker News

Foolproof HTML

pumpula.net

81–90 of 110 posts

Re: Foolproof HTML

#81

Earlier quoted context omitted.

Although the HTML he (lisper) gave is different in that it has the closing tag, I'm failing to see any case where this is bad or would result in different behavior from your example. To be clear, he seems to be talking about rendering HTML only, not parsing it. Wouldn't both your example and his have the same parsed DOM? Am I missing something?

You sometimes need more control over the actual HTML document than that; for instance to work around browser bugs or for efficiency. But if you are only interested in the semantics, then it's still not an adequate representation of the document. How would you, for instance, add an attribute to the body element? If you're dealing with a semantic representation like a DOM library would give you, then this would be triv…

You are confusing syntax and semantics. HTML and the DOM are two different things. HTML is a string of characters (syntax). The DOM is a data structure (semantics). Normally a DOM is produced by parsing HTML, but it can be produced in other ways (by running Javascript code, for example).

S-expressions are a data structure, different from the DOM, but S-expression syntax is a syntax. Normally S-expression syntax is parsed to produce S-expressions, but can also be parsed to produce other things. S-expression syntax can be parsed to produce a DOM. The easiest way to do this is to parse S-expression syntax ino S-expressions, render those S-expressions into HTML code, and then use an off-the-shelf HTML parser to parse the HTML. But you could also write a parser that parsed S-expression syntax directly into a DOM if you wanted to. You could also write a transformation program that compiled S-expressions directly into a DOM without going through the intermediate HTML.

The answer to your question of how to add an attribute to an implied element is that it is not possible to do that in HTML. It is only possible to add an attribute to an implicit element of the DOM produced by parsing an HTML document that omits that element (because at that point the element is no longer implicit). The exact same thing is possible using S-expressions. For example, here's how you write tables in my library:

(:table (header header ...) (data data ...) (data data ...))

This string of characters is parsed by the Lisp reader to produce an S-expression that has a one-to-one correspondence with the string you see above. But then there is an extra processing step that transforms that into a different S-expression whose printed representation is:

(:table (:tr (:th header) (:th header) ...) (:tr (:td data) (:td data) ...) ...)

At that point you can manipulate that S-expression in the same way that you manipulate the DOM (because they are both just data structures). Once you're done, you convert the S-expression to a DOM. At the moment that is done by rendering to HTML, but as I noted above that is just an implementational convenience to take advantage of the fact that HTML->DOM parsers are available off the shelf. You don't have to do it that way (and indeed the world would be a better place if it were not done that way).

All of this is trivial when dealing with S-expressions precisely because of the strict 1-to-1 correspondence between data structure and visual representation that does not exist in SGML-derived languages. That is why writing code for SGML-derived languages using S-expression syntax is so advantageous. (Actually, this is true for any language, not just SGML-derived languages. It's just a little more obvious for SGML-derived languages because SGML syntax already kinda sorta looks like a data structure representation so it's a little easier to grasp what is going on.)

Re: Foolproof HTML

#82

Earlier quoted context omitted.

You sometimes need more control over the actual HTML document than that; for instance to work around browser bugs or for efficiency. But if you are only interested in the semantics, then it's still not an adequate representation of the document. How would you, for instance, add an attribute to the body element? If you're dealing with a semantic representation like a DOM library would give you, then this would be triv…

I agree, and I'd also like to add that I find general discussions about s-expr vs markup (as well as JSON vs XML years ago) pointless. Markup is meant as a text format for content authors that can be parsed into a hierarchical structure, rather than as general-purpose data representation syntax, even though XML is being frequently (ab-)used for this purpose. The original use case for markup is that you can take a pie…

> The original use case for markup is that you can take a piece of plain text and then mark it up with tags

Yes, that was the original use case, but in actual practice HTML has not been used that way for a long time. Nowadays HTML is de facto used as a programming language for the visual representation layer of a browser. No one actually uses HTML to mark up documents by hand any more, for two reasons: first, no one writes plain text documents to use as source material for markup. They write Word documents, or TeX documents, but plain text source is all but unheard of nowadays. And second, HTML syntax is too clumsy and places too many demands on the user. So when ordinary people want to produce HTML they use WYSIWYG editors. When geeks want to produce HTML (and remember I'm talking about documents here) they use markdown. The only time anyone writes HTML nowadays is when they want to make a browser do something fancy.

Re: Foolproof HTML

#83

Earlier quoted context omitted.

Yawn. Hey look, #!/usr/bin/lisp (defun foo () a b c) has an "inferred PROGN" around a b c and the first line isn't part of the tree. What you're not getting here is that the above broken HTML has a canonical HTML representation. That canonical HTML can go to S-exp. If we are doing HTML-in-Sexp, we can throw out some of the non-canonical aspects, keeping the ones we like. We can certainly infer element wrapping if som…

> Yawn. Is that really necessary? > the above broken HTML As I very clearly stated, it's not broken. It's completely correct, valid HTML. Stick it in a validator if you don't believe me. Yes, I know a lot of people assume otherwise. That's because HTML is only superficially simple but has unexpected irregularities once you dig deeper. This just reinforces my point that HTML isn't the nice neat package that fits well…

You don't seem to understand what "canonical" means; it's a certain preferred alternative from among correct alternative forms. Often, the canonical form provides some base definition and the other forms can be understood in terms of equivalence to the canonical form. Do we not understand that a body element is added to the document if it is missing? Is there not a body element in the resulting DOM?  If so, then the source syntax which has that body can be considered canonical.

Re: Foolproof HTML

#84
post #58

Earlier quoted context omitted.

We're talking about syntax here. Start-tag inference is not syntactic. There is no way to tell if there's a missing start tag in: End-tag inference is semi-syntactic. You can tell that the following might have a missing end tag: But the previous example definitely does not.

SGML/HTML tag inference is guided by content model declarations, eg. tells SGML that the html element should contain a head element, followed by a body element. "O O" (capital letter O for omission) are tag omission indicators (in this case meaning that both the start- and the end-element tags for html can be omitted). This is covered in depth in the linked paper/slides (in fact, covering JimDabell's example exactly)…

You really don't seem to understand the difference between syntax and semantics. Syntax has to do with the rules that govern what strings of characters constitute legal programs. Semantics has to do with what strings of characters which are legal programs mean. For example, the following two documents are both syntactically correct:

    
    

    
    
    
They just have different semantics. If parsed as HTML, the first produces a DOM with two nodes and the second produces a DOM with three nodes.

By way of contrast, this is syntactically incorrect:

    data
So is this:

    
There is no DOM that corresponds to those two examples.

One of the (many) problems with SGML is that it muddies the distinction between syntax and semantics. That is one of the (many) reasons that using S-expression syntax to write SGML-like languages is advantageous.

Re: Foolproof HTML

#85

I don't think this is all that helpful. If you use a moderately-decent text editor, it probably has a closing feature, and an autoindent feature. If you're writing a new tag in emacs, you just need to write the opening tag, then press "C-c /", and it will close it for you. If you have a syntax error of this magnitude, the autoindenter will also help you realize. Just select the region (or the whole file) and press ta…

Hi! Article aithor here.

Emmet is a great plugin that has tag matching and all kinds of navigation/editing shortcuts too. Like those emacs shortcuts, it does reduce error rates and speed up editing signifigantly, at least for me, but I'm more interested in exactly a heavy handed approach. I'd like an app/plugin/whatever that makes it impossible to make many types of mistakes, even if it restricts what I can do.

I code html every day (and I do love it), but I'm a terrible and lazy typist. I make typos and mistakes constantly, so I'll take all the help I can get. So I'm trying to make something that will solve my specific woes in html/css development and I'm hoping someone else finds it useful too.

Re: Foolproof HTML

#86
post #84

Earlier quoted context omitted.

SGML/HTML tag inference is guided by content model declarations, eg. tells SGML that the html element should contain a head element, followed by a body element. "O O" (capital letter O for omission) are tag omission indicators (in this case meaning that both the start- and the end-element tags for html can be omitted). This is covered in depth in the linked paper/slides (in fact, covering JimDabell's example exactly)…

You really don't seem to understand the difference between syntax and semantics. Syntax has to do with the rules that govern what strings of characters constitute legal programs. Semantics has to do with what strings of characters which are legal programs mean . For example, the following two documents are both syntactically correct: They just have different semantics. If parsed as HTML, the first produces a DOM with…

> You really don't seem to understand the difference between syntax and semantics.

Are you talking to me? I've just pointed out how SGML works and didn't say anything about syntax/semantics.

Re: Foolproof HTML

#87
post #84

Earlier quoted context omitted.

You really don't seem to understand the difference between syntax and semantics. Syntax has to do with the rules that govern what strings of characters constitute legal programs. Semantics has to do with what strings of characters which are legal programs mean . For example, the following two documents are both syntactically correct: They just have different semantics. If parsed as HTML, the first produces a DOM with…

> You really don't seem to understand the difference between syntax and semantics. Are you talking to me? I've just pointed out how SGML works and didn't say anything about syntax/semantics.

Yes, I'm talking to you. You're right, you didn't say anything about syntax and semantics. I did. Go back to the beginning of the thread:

> > If you have a good strategy for validating your template files, I'd love to hear it!

> Use S-expression syntax instead of SGML syntax [emphasis added]

Note the use of the word syntax. I'm talking about syntax. All of your responses have been at best irrelevant or at worst wrong because you either don't understand what syntax is, or you chose to ignore it. It's damned annoying, particularly when you start making demonstrably false claims like, "it's nowhere close to the power of SGML as a text format" (https://news.ycombinator.com/item?id=13569991).

Re: Foolproof HTML

#88

Regarding the 'code without syntax' part: I wrote something that basically does this for any language that you have an EBNF grammar for. It turns the grammar into a graph; wherever your cursor is in the document at a given moment corresponds to some node in the graph; the edges going out of that node are the syntactically valid things you can insert from that point. Unfortunately there is no UI for it atm—though ther…

Your editor looks insanely slick! I had no idea there was prior work in this area. It sounds like your editor could trivially support html.

That last paragraph is exactly what I was thinking with foolproof html, except applied to markup/data languages.

Is your editor available to try somewhere?

Re: Foolproof HTML

#89

Earlier quoted context omitted.

That's an interesting point. I've heard other people bring up this issue in a vague way, but your example makes it clear why people would have a concern about this. At the same time, however, I'm not convinced it's a serious issue—it's more important to save work and avoid re-typing the shell of a switch when you have to type it one character at a time. If you're mapping language constructs to single keys (this was t…

I'd say the opposite - in your shoes, I'd just try it, doomed or not! (But then again building an IDE is My Thing atm - check my profile.) Building one of these systems is going to be really fun. If you don't have the time/inclination to just do it cause it's a cool project, one option is to "paper prototype" the feasibility of the transforms you'd need. Next time you're writing any code in the first language you wan…

Thanks for the reply meredydd. That does seem like a good approach.

Actually, I spent 1.5 years building an editor in this style (see link in my original post here) while working at a grocery store :)

Unfortunately, while I can see now that I should have first been super focused on validating the concept—I instead just kind of ran with it, assuming it was going to work, and built this massive, probably over-engineered, framework for generating editors for given grammars (with my starting point being: not even knowing what a grammar was, thinking I'd have to invent some kind of 'linguistic constraint description' format ;) ).

As it stands the editing portion works well enough for a demo, but the program never reached the point where I could write code with it, so a lot of these questions are still un answered for me. I think doing the paper prototype on these edit actions would be a good pre-coding validation step.

I did check out Anvil briefly. My two second, potentially incorrect summary would be VB for web apps. Is that close? Are you guys doing anything special for working with text itself?

Re: Foolproof HTML

#90

Regarding the 'code without syntax' part: I wrote something that basically does this for any language that you have an EBNF grammar for. It turns the grammar into a graph; wherever your cursor is in the document at a given moment corresponds to some node in the graph; the edges going out of that node are the syntactically valid things you can insert from that point. Unfortunately there is no UI for it atm—though ther…

Your editor looks insanely slick! I had no idea there was prior work in this area. It sounds like your editor could trivially support html. That last paragraph is exactly what I was thinking with foolproof html, except applied to markup/data languages. Is your editor available to try somewhere?

Thanks!

Unfortunately it's not available to try. I spent a lot of time building it in my free time and eventually got burnt out :/ It's still not to a point where it's usable (it's edit only). I'd love to revisit the project in some form, but time/money/other projects are obstacles at the moment.

I still think the concept has merit, but the implementation is more difficult than it seems (including lower-level design decisions, e.g., like the discussion in the other comment here). Good luck to you if you do give it a try, though. If nothing else, you'll probably learn a lot ;)

There's a little more info on the project here, btw, if you're curious: http://westoncb.com/projects/tiledtext

Post reply on HN