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

Michael Snoyman michael at snoyman.com
Wed May 25 06:20:33 CEST 2011


I'm concerned with introducing a new special character. Currently, #,
@ and ^ all have special meaning wherever they are used, and \ has
special meaning either at the beginning of the line or immediately
following one of #@^. And I'm particularly concerned with using a
common punctuation character to have a special meaning at the end of a
line. How would we allow people to actually use an exclamation point?

Michael

On Wed, May 25, 2011 at 2:59 AM, Francisco José CHAVES ALONSO
<pachopepe at gmail.com> wrote:
> I think the same as Michael, for me implicit spaces could be confusing,
> complex and unclear.
>
> In the other hand, I think that could be nice to unify the character for the
> explicit space at beginning and end of line.
> Maybe the '!' could be an interesting option, because the \ at the end of
> line for some people could means to ignore the end of line or add an extra
> line, and the # could be confusing with the interpolation at begining of
> line, but, if followed (or preceded) with space, the ! will represent an
> imperative space. Anyway if it is necesary one ! at the begining (or end of
> line) preceded (or followed) by space could be escaped with !!.
>
> By example
>
> <p #my-id .my-class
>     This paragraph has an ID and a class. It also has !
>     <b>bold
>     ! and !
>     <i>italic
>     , and shows you how to control whitespace!
>
> The ! in the last line is not an explicit space.
>
> Francisco
>
>
>
> Le 24/05/11 12:53, Michael Snoyman a écrit :
>
> If people really want this, I'll consider it. But it looks to me like
> a like of confusion and complexity for very little gain.
>
> Michael
>
> On Tue, May 24, 2011 at 5:05 PM, Greg Weber <greg at gregweber.info> wrote:
>
> Yes, that is the idea- all the inner content or descendant nodes will now
> have implicit spacing- adding a '>' to get the "huge win" scenario from the
> examples given. I do think it adds confusion for new users- it isn't
> something we would want to use in a tutorial. It would be a feature for
> users already comfortable with Hamlet. Perhaps '<p>>' is actually too
> subtle. Some alternatives:
> <p>spaced>
> <p>S>
> <p>#>
> <p>< >
> There is also a possibility of adding an indicator inside the tag.
> <p=>
> <p=spaced>
> <p=#>
>
>
> On Mon, May 23, 2011 at 11:22 PM, Mark Bradley <barkmadley at gmail.com> wrote:
>
> On Tue, May 24, 2011 at 4:13 PM, Michael Snoyman <michael at snoyman.com>
> wrote:
>
> On Tue, May 24, 2011 at 7:00 AM, Greg Weber <greg at gregweber.info> wrote:
>
> The Yesod homepage looks like this:
>         <p>
>             If you are new to Yesod, you should start off with #
>             <a href=@{FiveMinutesR}>the five minute start instructions
>             . The #
>             <a href=@{ScreencastsR}>screencasts
>             \ give a nice introduction to some of the advanced
> concepts, and
> #
>             <a href=@{BookR}>the book
>             \ is the recommended approach to learning Yesod. Ask the #
>             <a href=@{CommunityR}>commnunity
>             \ for help.
> Allowing one-line tags in positions other than the very beginning
> allows for
> the removal of the '#' character:
>         <p>
>             If you are new to Yesod, you should start off with
>             \ <a href=@{FiveMinutesR}>the five minute start
> instructions
>             . The <a href=@{ScreencastsR}>screencasts
>             \ give a nice introduction to some of the advanced
> concepts, and
>             \ <a href=@{BookR}>the book
>             \ is the recommended approach to learning Yesod. Ask the
>             \ <a href=@{CommunityR}>commnunity
>             \ for help.
> Having implicit spaces is actually a huge win here:
>         <p>
>             If you are new to Yesod, you should start off with
>             <a href=@{FiveMinutesR}>the five minute start instructions
>             The
>             <a href=@{ScreencastsR}>screencasts
>             give a nice introduction to some of the advanced concepts,
> and
>             <a href=@{BookR}>the book
>             is the recommended approach to learning Yesod. Ask the
>             <a href=@{CommunityR}>commnunity
>             for help.
> But I am wondering if it is best to keep things the way they are but
> just
> indicate when there should be implicit spaces. My thought is to somehow
> use
> angle brackets. Changing <p> to <p>> would indicate implicit spaces.
>
> What's the advantage of adding a new syntax for "implicit" space
> versus just explicitly adding the space?
>
> I think he means that the child nodes of <p>> would be affected by
> some implicit spacing rules.
>
> Personally I prefer one consistent behaviour (explicit spacing every
> time).  Trying to get too smart will get confusing and inaccurate
> quickly.
>
> Michael
>
> Greg Weber
> On Fri, May 20, 2011 at 8:22 AM, Patrick Brisbin <pbrisbin at gmail.com>
> wrote:
>
> On 05/20/11 at 11:12am, Daniel Patterson wrote:
>
> I think what the original author was saying was that when you make a
> new
> line with html, whitespace is inserted, not whether hamlet should
> automatically insert space after every tag.
>
> So yes, writing <p>hello<strong>there</strong></p> should not put
> white
> spacing.
>
> But when you write, in html:
> <p>hello
>     <strong>there</strong></p>
>
> It is equivalent to <p>hello <strong>there</strong></p> (note the
> space).
>
> Isn't that simply due to the fact that HTML compresses whitespace
> across
> the board? (turning that "\n\t" or "\n    " into just " ")
>
> Leading spaces in hamlet are used to define nesting, so also
> compressing
> this whitespace (rather than stripping it) would produce odd effects:
>
>  <div>
>      <p>Hey
>          <strong>there
>
> Would turn into
>
>  <div> <p>Hey <strong>there</strong></p></div>
>
> Which has an unneeded space after the parent <div>
>
> Right?
>
>
> On May 19, 2011, at 11:57 PM, Michael Snoyman 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
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
> --
> patrick brisbin
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
>
> --
> -barkmadley
> sent from an internet enabled device
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
>



More information about the web-devel mailing list