Linebreak and Anchors Template Filters
Two new Pipits have been released today. Both Pipits are template filters.
The linebreak Template Filter
The linebreak template filter inserts HTML line breaks <br> before new lines in a textarea field type.
When using a Markdown editor like SimpleMDE you have to press Enter twice to add a new line and this results in the following markup:
<p>First line</p>
<p>Second line</p>
This is fine in many cases, but in some cases you may want the following markup instead:
<p>
First line
<br>
Second line
</p>
For instance, this is useful for addresses. You may want to provide a single field for Editors to add the address. Instead of using a text editor or adding multiple fields (address_line_1, address_line_2, etc), you can using this filter to inset the line breaks:
<p>
<perch:content id="address" type="textarea" label="Company Address" filter="linebreak">
</p>
So the editor enters the following:
P. Sherman,
42 Wallaby Way,
NSW 2000, Australia
And the field outputs (with the help of the filter):
P. Sherman,
<br>
42 Wallaby Way,
<br>
NSW 2000, Australia
You can download the linebreak filter from here.
The anchors Template Filter
The anchors template filter adds IDs to HTML headings h1-h6 (based on their content) in a textarea field.
You may enter a heading like so in a textarea field with a Markdown editor:
# This is a heading
Regular output is:
<h1>This is a heading</h1>
With the anchors template filter:
<h1 id="this-is-a-heading">This is a heading</h1>
This is useful for long blog posts and documentation as you can share links to particular section /docs/#how-to-configure.
You can download the anchors filter from here.