-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect whitespace #10
Comments
Hi @mattfysh, Marko will remove unnecessary whitespace based on some builtin rules, by default. These rules are partially based on the rules that browser's use to normalize whitespace and partially based on the goal of allowing nicely indented markup. These rules are as follows:
FYI, the whitespace removal happens in the following code: It's possible to disable whitespace removal on a per-element basis using a special attribute applied to a parent element. It's also possible to disable all whitespace removal by changing an option for the compiler. Unfortunately the docs are currently lacking for both these options so I'll describe them below for now: Option 1) Disable whitespace removal using the <div c-whitespace="preserve">
<my-first-tag>
<my-second-tag>
</div> Option 2) Disable all whitespace removal by changing a compiler option require('marko/compiler').defaultOptions.preserveWhitespace = true; Also, you can avoid whitespace removal by avoiding the new line character. For example, the following whitespace between the elements will be preserved: <my-first-tag> <my-second-tag> I'll work on adding some formal documentation on the whitespace removal rules. Do these options meet your needs or are you looking for a different solution? |
@mattfysh, I added some documentation to clarify how Marko deals with whitespace: Please let me know what you think. Thanks, |
Perhaps we should add a tag that can be used to enable preservation of whitespace. For example, something like this: <preserve-whitespace>
<my-first-tag>
<my-second-tag>
</preserve-whitespace> Sometimes there isn't a convenient parent tag to add the |
I agree regarding introducing a |
Marking issue as closed since additional docs were added clarifying the whitespace rules for Marko. If there are still issues please let us know. Thanks. |
require('marko/compiler').defaultOptions.preserveWhitespace = true; Sorry to reopen an old issue, but how to set this option with marko/express? |
The new line between these two custom tags should be preserved.
The text was updated successfully, but these errors were encountered: