Skip to main content

String filters

govukMarkdown

Convert a Markdown formatted string into HTML decorated with typography classes from the GOV.UK Design System.

Input

{{ "Visit [GOV.UK](https://gov.uk)." | govukMarkdown }}

Output

<p class="govuk-body">Visit <a class="govuk-link" href="https://www.gov.uk">GOV.UK</a>.</p>

headingsStartWith

By default, headings start using the class govuk-heading-xl.

Input

{% set headings %}
# Heading level 1
## Heading level 2
### Heading level 3
#### Heading level 4
{% endset %}

{{ headings | govukMarkdown }}

Output

<h1 class="govuk-heading-xl">Heading level 1</h1>
<h2 class="govuk-heading-l">Heading level 2</h2>
<h3 class="govuk-heading-m">Heading level 3</h3>
<h4 class="govuk-heading-s">Heading level 4</h4>

The GOV.UK Design System recommends changing this if a page feels unbalanced (heading classes don’t always need to correspond to the heading level).

Start headings using the smaller size by setting the headingsStartWith option:

Input

{{ headings | govukMarkdown(headingsStartWith="l") }}

Output

<h1 class="govuk-heading-l">Heading level 1</h1>
<h2 class="govuk-heading-m">Heading level 2</h2>
<h3 class="govuk-heading-s">Heading level 3</h3>
<h4 class="govuk-heading-s">Heading level 4</h4>

includes

Tests whether a string includes the string given, and returns true or false.

Input

{{ "Department for Transport" | includes(" for ") }}
{{ "Department of Health & Social Care" | includes(" for ") }}

Output

true
false

isString

Check a value is classified as a String primitive or object.

Input

{{ "Number 10" | isString }}
{{ 10 | isString }}

Output

true
false

noOrphans

Add a non-breaking space between the last two words of a string.

This prevents an orphaned word appearing by itself at the end of a paragraph. This can be useful for improving the appearance of headings and titles.

Input

{{ "Department for Business, Energy & Industrial Strategy" | noOrphans }}

Output

Department for Business, Energy & Industrial&amp;nbsp;Strategy

slugify

Convert a string into kebab-case.

This can be useful to slugify titles for use in URLs or fragment identifiers.

Input

{{ "Department for Education" | slugify }}

Output

department-for-education

startsWith

Check a string starts with a value.

Input

{{ "Department for Transport" | startsWith("Department") }}

Output

true