GithubHelp home page GithubHelp logo

Comments (16)

jeromegn avatar jeromegn commented on June 18, 2024

That's currently not implemented, the equivalent from slim would be: http://www.rubydoc.info/gems/slim/frames#Trailing_and_leading_whitespace_______

Something like:

    a href="#"
      span
      > Contacts

from slang.

infernalmaster avatar infernalmaster commented on June 18, 2024

Looks like slim trims all whitespaces between tags by default. So >, <, ' for adding spaces not for deleting:

You can force Slim to add a trailing whitespace after a tag by adding a >.
You can add a leading whitespace by adding <.

The single quote tells Slim to copy the line (similar to |), but makes sure that a single trailing white space is appended.

So looks like that it's HAML removes spaces with that characters http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace-removal--and-

I have time and need to help you with that but we should decide what we should to do with this

from slang.

jeromegn avatar jeromegn commented on June 18, 2024

from slang.

infernalmaster avatar infernalmaster commented on June 18, 2024

I found good workaround. I'm using ECR partials for that critical places.

from slang.

mig-hub avatar mig-hub commented on June 18, 2024

Trimming all whitespace by default would be great.
It is also better for inline-block elements.

from slang.

robacarp avatar robacarp commented on June 18, 2024

Indeed, Slim does trim all whitespace by default. Haml injects it by default, like slang does, but haml also provides a way to prevent it from being added.

from slang.

robacarp avatar robacarp commented on June 18, 2024

I think this is a more obvious example. <span> tags are display: inline, so spacing around them matters more than around most html elements.

| un
span.red forget
| able

which renders

un
<span class="red">forget</span>
able

and therefore the rendered html looks like un forget able.

The only way I've been able to get around this extra spacing is:

    == %(un<span class="red">forget</span>able)

from slang.

jeromegn avatar jeromegn commented on June 18, 2024

I agree. I've had this problem before with inline elements with slim.

I'm wondering what's the best way to do this. Basically trim all whitespace everywhere between "nodes" (text and elements)? Unless text uses ' (iirc, we don't support < or > yet.)

There are exceptions like special blocks for javascript or css.

from slang.

donovanglover avatar donovanglover commented on June 18, 2024

How about using parentheses (or something similar) for inline Slang instead?

Input:

p Slang is a (span.color (em Slim)-inspired) templating language.

Output:

<p>Slang is a <span class="color"><em>Slim</em>-inspired</span> templating language.</p>

from slang.

robacarp avatar robacarp commented on June 18, 2024

@jeromegn it's hard to say for sure, but given that HTML is mostly ignorant of whitespace, it might be a safe first pass to just trim all whitespace. It would solve this problem, but I suspect it'd generate other problems.

Adding support for > and other whitespace manipulation, if possible, is probably a smart choice before making such a big change to the output every slang file generates. That would also bring Slang into closer parity with Slang, right?

from slang.

rperce avatar rperce commented on June 18, 2024

@infernalmaster why did you close this? It seems like this is still a problem.

FWIW, since this is mostly a problem with spans, for a personal workaround I've committed the cardinal sin of Parsing HTML With Regex and

private macro view(filename, title argtitle = nil)
    title = {{argtitle}} || "{{filename.id}}"
    render("src/views/{{filename.id}}.slang", "src/views/Layout.slang")
        .gsub(/(<span[^>]*>)\n\s*/, "\\1") # newline after opening span
        .gsub(/<\/span>\n\s*<span/, "</span><span") # newline between spans
        .gsub(/\n\s*(<\/span>)/, "\\1") # newline before closing span
end

If there's a better way - if this has been solved properly and I just haven't noticed, or if I should be approaching the problem different, etc - I'd love to know!

from slang.

robacarp avatar robacarp commented on June 18, 2024

The reason this is more obvious with spans is that spans aren't block level elements. Added spacing into/around a block element is often not noticeable because it doesn't change flow in the document. For inline elements like span, link, strong, em, etc, the extra space matters more. For example, <strong>this</strong>text will show up as thistext (no space) whereas <div>this</div>text will show up with a newline because the vanilla div styling forces it.

from slang.

infernalmaster avatar infernalmaster commented on June 18, 2024

Hey @rperce Apologies for the confusion, I closed it because I didn't see any activity in this thread for a long time, so I thought maybe it was fixed or no one cares

from slang.

rperce avatar rperce commented on June 18, 2024

@robacarp yeah, totally understand why it's more relevant for spans, just wanted to share my workaround for anyone else running into this.

@infernalmaster reasonable! Thanks for the re-open - I would love to see this revisited.

from slang.

jeromegn avatar jeromegn commented on June 18, 2024

Chiming in here: I don't think this is a huge change.

I've been out of touch with Crystal, so I'd rather somebody else contribute a PR :)

I do think this is a useful feature!

from slang.

infernalmaster avatar infernalmaster commented on June 18, 2024

I did my best, but there are some limitations with embedded JS code. Some of problems present in inside master branch.

from slang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.