5 ms·
> 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: <tag a
by lisper 10y ago
> 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:
<tag attr=value ...>content</attr>
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/ http://weitz.de/cl-who/ for an example of an implemented system that works this way. I've been using it in production for years. It works like a charm.
- sdegutis 10y agoCan confirm: Hiccup is really great.
- escherize 10y agoYes! Check out a site I made to show the world: http://hiccup.space http://hiccup.space Also if you're interested in a more interactive (i.e. can process data into html), check out http://cljsfiddle.com http://cljsfiddle.com
- maxwelljoslyn 10y agoWow, that's a neat library and demonstration. Thank you.
- jrapdx3 10y agoVery interesting! Thanks for the ref. I wrote about my own efforts along these lines, using Lisp lists is certainly a natural, logical starting point. There are a number of parallel systems in Scheme which I used in prior applications. I fully agree sexpr syntax is both beautiful and efficient. The fly in the ointment is that doing anything substantial quickly becomes complex and requires dealing with a complex programming model to accomplish the task. That can be a daunting hurdle even for experienced users to surmount. It speaks to appeal of simplified interfaces, which may help but I'm pretty sure won't mitigate the problem altogether. Of course every bit helps, having more tools can be a very good thing if we know how to apply the right tool for the task at hand.
- lisper 10y ago> The fly in the ointment is that doing anything substantial quickly becomes complex and requires dealing with a complex programming model to accomplish the task. Some problems are inherently complex, but whatever it is you want to do it will almost certainly be simpler in Lisp than any other language. What sort of "substantial" thing did you have in mind?
- tannhaeuser 10y agoWhile 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 http://sgmljs.net/blog.html .
- lisper 10y agoThere 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.
- kazinator 10y agoIn fact, inferring missing close tags is criminally stupid; when such a situation is diagnosed in any of the *ML languages, it should be loudly diagnosed. Early in the web history, browsers tried to out-do each other in guessing what broken HTML means and render it. That led to a nasty situation of everyone having to emulate everyone else's bugs and hacks.
- recursive 10y agoLike it or not, it's enshrined in the specification of HTML5.
- JimDabell 10y agoIt's actually been a standard part of HTML from the very start. It's got nothing to do with browser guessing and it's not new to HTML 5. To give a concrete example for tannhaeuser's point, consider this document: <!DOCTYPE html> <title>…</title> <p>… This is a completely correct, valid HTML document. The first thing to notice is that it's not a tree made up of elements. That first line is not a tag, and isn't part of the DOM tree. Then we get to the DOM tree. It's got several implied start and end tags, so the tree itself looks like this: html head title … body p … Again, this is a completely correct, valid document and this is the correct way to parse it. While you may be able to represent the parsed DOM as an S-expression, you can't represent all valid HTML documents as S-expressions, at least not in the convenient way people assume – and it's not "broken HTML" to blame.
- madeofpalk 10y agoYes! 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.
- veneficia 10y agoI'm not sure how React/JSX highlights the markup issues. The clarity that Jade/YAML syntax provides is hard to achieve with the clumsy looking React/JSX spaghetti code that facebook has sold to frontend devs.
- tyingq 10y agoInteresting, but you would still have to account for the inconsistencies of html, like: - Standalone, non-closed tags <!doctype>, <hr>, <br>, <link>, <meta>, <img> etc. - Proper encoding or quoting of [< > " ' &] in html attributes - <script> tags and CDATA Probably lots more as well. Not rocket science of course, but you would want a tool where you have some confidence they've covered all of these things.
- recursive 10y agoLast time I looked <textarea> and <pre> also worked kind of like <script>.
- minitech 10y ago<pre> doesn’t at all. At a stretch, maybe you’re thinking of <xmp>?
- lisper 10y ago> Not rocket science of course And it depends on whether you're parsing or rendering. Rendering is much easier than parsing. But even parsing is nonetheless a solved problem :-)
- dqv 10y agoFor anyone interested, things are close, they just need to be glued: In guile, (htmlprag) addresses the import[1]. It handles "weird html". The SXML modules[2] can handle encoding and rendering. CDATA is the only thing (that seems to be) missing. I'll have to look into that. Someone also made a module to render html[3]. [1]http://www.nongnu.org/guile-lib/doc/ref/htmlprag/ http://www.nongnu.org/guile-lib/doc/ref/htmlprag/ [2]https://www.gnu.org/software/guile/manual/guile.html#SXML https://www.gnu.org/software/guile/manual/guile.html#SXML [3]https://dthompson.us/rendering-html-with-sxml-and-gnu-guile.html https://dthompson.us/rendering-html-with-sxml-and-gnu-guile....
- draegtun 10y agoI've also done this for years using similar tools in Perl - https://metacpan.org/pod/HTML::AsSubs https://metacpan.org/pod/HTML::AsSubs | https://metacpan.org/pod/Markapl https://metacpan.org/pod/Markapl | https://metacpan.org/pod/Builder https://metacpan.org/pod/Builder Here's an example of something I'm currently using/building in Rebol: [<tag> attr: value "content"] Of course nothing new here because there have been other Rebol HTML dialects (for eg: http://www.hmkdesign.dk/project.rsp?id=html-dialect http://www.hmkdesign.dk/project.rsp?id=html-dialect) And there are plenty of CL-WHO related tools out there too - http://stackoverflow.com/questions/671572/cl-who-like-html-templating-for-other-languages http://stackoverflow.com/questions/671572/cl-who-like-html-t...