whitespace

Whitespace operators

Template::HAML supports HAML's whitespace-removal modifiers and whitespace-preservation behaviors so you can control how generated HTML is laid out.

Outer trim >

A trailing > on a tag strips whitespace immediately around the tag, both before its open tag and after its close tag.

%p first
%p> middle
%p last
<p>first</p><p>middle</p><p>last</p>

This works for any tag, including void elements:

%img
%img>
%img
<img><img><img>

Inner trim <

A trailing < on a tag strips whitespace immediately inside the tag, both after the open tag and before the close tag.

%blockquote<
  %div
    Foo!
<blockquote><div>
  Foo!
</div></blockquote>

When combined with content on the same line plus a single child, the child renders inline:

%p< hello
  %strong world
<p>hello<strong>world</strong></p>

Combined <> / ><

Both modifiers can be combined in either order:

%p<>
  %a hi
<p><a>hi</a></p>

Preserved tags

The pre and textarea elements automatically preserve their inner whitespace by replacing newlines with the &#x000A; HTML entity. This keeps the rendered display intact while still allowing HAML to indent the source.

%pre
  Line 1
  Line 2
<pre>&#x000A;  Line 1&#x000A;  Line 2&#x000A;</pre>

The list of preserved elements is configurable via the preserve option on Template::HAML::Config:

my $cfg = Template::HAML::Config.new(:preserve('pre', 'textarea', 'code'));
HAML.render(:src($haml), :config($cfg));

Global whitespace removal

To apply > and < to every tag at once, set remove-whitespace: True on the config. See Configuration for details. Preserved tags keep their inner whitespace but still have outer whitespace stripped.

Forced preserve ~

The ~ operator works like = (eval and emit), but additionally replaces newlines in the result with &#x000A;. This is useful when an interpolated string contains newlines you want to keep literal in the rendered output.

~ "line1\nline2"
line1&#x000A;line2

Like =, the result is HTML-escaped by default. Disable escaping globally with escape_html => False on the config.

Template::HAML v0.9.5

HAML template engine

Authors

  • Greg Donald

License

Artistic-2.0

Dependencies

Provides

  • Template::HAML
  • Template::HAML::Actions
  • Template::HAML::CLI
  • Template::HAML::Cache
  • Template::HAML::Codegen
  • Template::HAML::Comment
  • Template::HAML::Config
  • Template::HAML::Context
  • Template::HAML::DirectCodegen
  • Template::HAML::DirectEmit
  • Template::HAML::Doctype
  • Template::HAML::Eval
  • Template::HAML::Filter
  • Template::HAML::Filters
  • Template::HAML::Format
  • Template::HAML::Grammar
  • Template::HAML::Helpers
  • Template::HAML::HelpersRole
  • Template::HAML::Interpolation
  • Template::HAML::Lint
  • Template::HAML::Multiline
  • Template::HAML::Node
  • Template::HAML::Plain
  • Template::HAML::Plugin
  • Template::HAML::Renderer
  • Template::HAML::Statement
  • Template::HAML::Tag
  • Template::HAML::TagTransformers
  • Template::HAML::ViewContext
  • Template::HAML::Visitor
  • Template::HAML::Watch
  • Template::HAML::X

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.