Live data from Hacker News

Foolproof HTML

pumpula.net

31–40 of 110 posts

Re: Foolproof HTML

#31

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…

As you mention, a decent text editor solves large parts of this.

I have had occasions where I needed something more. When that's the case, tidy-html5[1] + running a diff afterwards has been sufficient.

[1]http://www.html-tidy.org/documentation/

Re: Foolproof HTML

#32

I found my foolproof HTML in slim-lang. It produces standards-compliant HTML and prevents me from writing code that is not well-formed. The above is a nice side effect of its incredibly clean and terse syntax. Now I feel cheated any time I need to write regular HTML. https://github.com/slim-template/slim/blob/master/README.md I used emmet for a while but slim improves on writing and reading code.

Seems similar to HTML generation libs in Lisp, except with indentation instead of parenthesis.

Yes, and here at least, I think indentation is a BIG win over parenthesis.

Re: Foolproof HTML

#36
post #17

> 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, i.e. instead of: content write ((tag attr value ...) content) and use Lisp to process it. It's actually quite straightforward. You can apply it to XML as well. Everything actually ends up looking a lot prettier this way. See http://weitz.de/cl-who/ for an example of an implemented sys…

While I also like Lisp syntax, it's nowhere close to the power of SGML as a text format. SGML gives you regular type checking and inference of omitted tags, injection-free content transclusion, user-defined Wiki syntax, parametric template expansion, and pipelined, automaton-based processing/styling. I've just published my slides/paper on this topic at http://sgmljs.net/blog.html .

Re: Foolproof HTML

#37
post #17

> 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, i.e. instead of: content write ((tag attr value ...) content) and use Lisp to process it. It's actually quite straightforward. You can apply it to XML as well. Everything actually ends up looking a lot prettier this way. See http://weitz.de/cl-who/ for an example of an implemented sys…

Yes! This is what I like about JSX/React - you're actually writing the markup as function calls/data structure so invalid syntax is immediately obvious as missing a closing parentheses for a function call.

Re: Foolproof HTML

#38
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 there is UI for the editing portion (which almost exactly matches the author's .gif at the end of the document): https://www.youtube.com/watch?v=tztmgCcZaM4&feature=youtu.be...

It's a concept that a lot of people have explored. My understanding is that some academics were interested in it a while ago but never produced anything that worked well and kind of wrote it off. Now some people are revisiting it (e.g. Unison[1] and Jetbrains MPS[2]).

I think the core idea involved is a shift away from using text as a model for representing programs; instead, interact with more abstract representations of code, and render those abstractions as text. This allows your editor to have better understanding of the language you're using, so syntax becomes a property of a language's visualization rather than something totally central to it (and now you don't have to memorize it!).

[1] http://unisonweb.org/2015-05-07/about.html [2] https://www.jetbrains.com/mps/

Re: Foolproof HTML

#39
post #17

> 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, i.e. instead of: content write ((tag attr value ...) content) and use Lisp to process it. It's actually quite straightforward. You can apply it to XML as well. Everything actually ends up looking a lot prettier this way. See http://weitz.de/cl-who/ for an example of an implemented sys…

While I also like Lisp syntax, it's nowhere close to the power of SGML as a text format. SGML gives you regular type checking and inference of omitted tags, injection-free content transclusion, user-defined Wiki syntax, parametric template expansion, and pipelined, automaton-based processing/styling. I've just published my slides/paper on this topic at http://sgmljs.net/blog.html .

There is a one-to-one correspondence between (correct) SGML and S-expressions so your claim that S-expressions are "nowhere close to the power of SGML" cannot possibly be true. It might be true that the tools available for processing S-expressions as markup are not as powerful as the tools for processing SGML, but that is not a limitation of the syntax.

BTW, when you say "inference of omitted tags" did you mean "inference of omitted close tags"? Because if so, this is not a feature. It's a patch to cover up a design flaw in SGML, namely, that close tags are required to match and so it is possible to make the mistake of omitting or mismatching them. This is one of the reasons S-expressions are superior to SGML: S-expressions are DRY. SGML isn't.

Re: Foolproof HTML

#40
post #17

> 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, i.e. instead of: content write ((tag attr value ...) content) and use Lisp to process it. It's actually quite straightforward. You can apply it to XML as well. Everything actually ends up looking a lot prettier this way. See http://weitz.de/cl-who/ for an example of an implemented sys…

While I also like Lisp syntax, it's nowhere close to the power of SGML as a text format. SGML gives you regular type checking and inference of omitted tags, injection-free content transclusion, user-defined Wiki syntax, parametric template expansion, and pipelined, automaton-based processing/styling. I've just published my slides/paper on this topic at http://sgmljs.net/blog.html .

The fact that you can do HTML in Lisp is because there is code behind that doing the semantics. What makes you think that those SGML requirements couldn't be done? Sounds to me like about one week's worth of evening hacking.
Post reply on HN