[web-devel] [hamlet] implicit spaces with newlines?

Greg Weber greg at gregweber.info
Fri May 20 15:24:09 CEST 2011


# render this:
<p>You are logged in as <i>Michael Snoyman</i>, <a
href="/logout">logout</a>.</p>
<p>Multi
  line
  paragraph.
</p>


# current - explicit
<p>You are logged in as #
  <i>Michael Snoyman
  , #
  <a href="/logout">logout
  .
<p>Multi
  \ line
  \ paragraph.

# alternative #! - implicitly add space, explicitly remove on the next line
<p>You are logged in as
  <i>Michael Snoyman
  ,
  <a href="/logout">logout
  !.
<p>Multi
  line
  paragraph.


# alternative #2 - implicitly add space, explicitly remove on the current
line
<p>You are logged in as
  <i>Michael Snoyman
  ,
  <a href="/logout">logout#
  .
<p>Multi
  line
  paragraph.


# alternative #3 - implicitly add space when there is a new line before tag
contents
# seems bad, just throwing it out there :)
<p>
  You are logged in as
  <i>Michael Snoyman
  ,

  <a href="/logout">logout
  .
<p>
  Multi
  line

  paragraph.


# alternative #4 - implicitly add space. remove space with 'whitespace
alligators'
# somewhat similar to:
http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#whitespace_removal__and_
# > chomps white space *after* the tag
# < chomps white space *within* the tag
# would need more examples to see if this plays out well
<p>You are logged in as
  <i>Michael Snoyman
  ,
  <a href="/logout">logout>
  .
<p>Multi
  line
  paragraph.


On Thu, May 19, 2011 at 8:57 PM, Michael Snoyman <michael at snoyman.com>wrote:

> On Thu, May 19, 2011 at 11:49 PM, Patrick Palka <patrick at parcs.ath.cx>
> wrote:
> > I find it a bit unintuitive that the hamlet code
> >
> > <p>hello
> >    <strong>there
> >
> > or
> >
> > <p>
> >     hello
> >     <strong>there
> >
> > generates the html
> >
> > <p>hello<strong>there</strong></p>
> >
> > I expected there to be a space between "hello" and "there" similar to
> what
> > the html specifications dictate. Is this behavior intentional or an
> > oversight? If it's the former, then what is the recommended way to
> simulate
> > my expected behavior? Appending a space to the end of a line is
> > mentally ugly and syntactically obscure.
>
> I'm not sure what you mean by "what the html specifications dictate."
> HTML is whitespace-sensitive, meaning that:
>
>   <i>foo</i> <b>bar</b>
>
> and
>
>    <i>foo</i><b>bar</b>
>
> Are different. Now, in all likelihood in the above example, you will
> want to have the whitespace surrounding tags. But consider the
> following HTML:
>
>    <p>You are logged in as <i>Michael Snoyman</i>, <a
> href="/logout">logout</a>.</p><p>Another paragraph.</p>
>
> In the case of the <i> and <a> tags, we definitely do *not* want to
> add whitespace after the tag (though we do want it before the tag). In
> the case of <p>, we don't care one way or another, but adding the
> whitespace everywhere will take up (a trivial amount of) extra
> bandwidth. tl;dr: Sometimes you don't want the whitespace.
>
> So when designing Hamlet, I thought up a few possibilities:
>
> 1) What we do now: all whitespace must be explicit.
> 2) Implicitly add whitespace before/after every tag.
> 3) Do something "smart", adding whitespace where it's desired.
>
> (2) isn't really an option because it makes having a tag as the last
> word in a sentence impossible. (3) gives me the creeps: I like smart
> libraries, but I will *never* trust a library to do this kind of stuff
> correctly all the time, even if I'm the one making up the rules for it
> to follow! And I have no doubt that it will quickly devolve into 500
> lines of hairy code to try and cover millions of corner cases. Oh, and
> don't forget that there are other languages than English that might
> approach it differently.
>
> I suppose another possibility is (2) along with some special way of
> forcing the removal of extra whitespace, but this seemed much less
> intuitive than the current approach.
>
> Anyway, that's the reasoning behind this stuff, if people have better
> ideas, I'd like to hear them.
>
> Michael
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110520/8510da82/attachment.htm>


More information about the web-devel mailing list