Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here is a simple idea:

  html(
    head(
      title('This is the title')),
    body(
      div(id='header', body=...)))
We could also create a shortcut for div ID and classes.. for instance a keyword capitalized is an ID, or something starting with _ could be a class.

It could then be possible to make "custom" fields:

html( headers(), left_side(), content(), footer())



I'm pretty sure this has been done. I remember seeing something extremely similar while going through several of the umpteen python web frameworks and thinking "well, it's just html with parentheses rather than angled bracket and an additional leaky abstraction on top".


the gist contains example using lxml:

  E.html(
    E.head(...),
    E.body(...))


I've been playing with a similar syntax: https://github.com/maplambda/py-htmlout/blob/master/htmlgen.... I need to provide better examples, tests and form handling. I'm finding it nice to work with.


Looks good. My own module of this sort auto-escapes HTML special characters in strings fed to it, by default -- it looks like yours doesn't do this, at least at first glance. Is that right?

OTOH I think I like your syntax better.


Thanks, that would be a good approach, mine is currently very barebones! just trying to get the syntax right and get a feel for using it in actual projects - hope to put up a real sample soon.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: