Comments (16)
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.
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.
from slang.
I found good workaround. I'm using ECR partials for that critical places.
from slang.
Trimming all whitespace by default would be great.
It is also better for inline-block elements.
from slang.
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.
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.
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.
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.
@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.
@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.
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.
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.
@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.
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.
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)
- Windows end of line can give issues HOT 2
- slang with strings? HOT 2
- Can't find file "secure_random" HOT 1
- Incorrect parse of attribute value causes error HOT 1
- Can we see Slang adding JSON building (feature suggestion). HOT 5
- Add HTML entity support to Slang HOT 2
- Allow unescaped interpolation HOT 2
- Minify HTML output
- Multiline attributes inside an attribute wrapper
- Embedded HTML with double quoted attributes breaks interpreter
- Question: HTML HOT 1
- Backslash handling HOT 1
- What about HTML Boolean Attributes? HOT 1
- How to do ternary conditional statement? HOT 1
- Convert .html file to .slang file HOT 1
- Use of conditionals HOT 3
- Kilt dependency and Kemal HOT 3
- Compile Time or Runtime? HOT 1
- Render variable content as unescaped HTML HOT 1
- Cannot build docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.