Skip to content
Start free

Markdown Templates

Open in ClaudeOpen in ChatGPT

An HTML template’s body can be written in Markdown instead of HTML: headings, lists and tables, with HTML where you need it. DocSpring renders the body’s Liquid, then converts the Markdown to HTML. The header and footer are always HTML, and the template’s SCSS styles the HTML the Markdown makes.

# Invoice {{ invoice_number }}
Dear {{ customer.name }},
| Item | Price |
| --- | --- |
{% for item in items %}
| {{ item.name }} | {{ item.price | currency }} |
{% endfor %}
**Total: {{ total | currency }}**
  • In the app: choose Markdown and CSS when you create a template. It starts with a heading and a stylesheet for Markdown documents: a readable font, headings, tables with borders, code and quotes.
  • With the API: create an HTML template with markdown: true. Without html, it starts with the same heading. Without scss, it gets the same stylesheet.
  • From an HTML template: turn on Write in Markdown in the template’s settings, which converts its body (see Switching between Markdown and HTML).

A new Markdown template renders on the Standard engine, so the editor shows its preview straight after each save, unless your account’s Template defaults page chose Chromium for new Markdown templates. You can switch it to Chromium in its settings.

The body is GitHub Flavored Markdown: headings, paragraphs, **bold**, *italic*, ~~strikethrough~~, links, images, lists, task lists (- [x] Done), tables, quotes, code and horizontal rules. A web address or email address becomes a link.

A line break inside a paragraph doesn’t start a new line in the PDF. Leave a blank line to start a new paragraph, or end a line with a backslash (\) to break it there.

The body can hold HTML. A line that starts with a block tag such as <div> or <table> starts HTML, which goes on until a blank line, and Markdown inside it isn’t converted. Leave blank lines around the Markdown inside an element:

<div class="terms">
## Terms
Payment is due in **30 days**.
</div>

Use HTML for what Markdown can’t write, such as a class for a page break or a table with merged cells.

Liquid works as it does in any HTML template: {{ }} prints a value, and {% if %} and {% for %} show or repeat the lines between their tags.

A value prints as text and is never read as Markdown: a *, _ or | in a name prints as it is, in a paragraph or a table cell. The template’s Escape HTML in Data setting works as it does in HTML: when it’s on, a < in a value prints as that character.

A value between < and >, as in <{{ website }}>, becomes a link when it’s a web address (https:// or http://), a mailto: address or an email address. Any other value prints with its < and >.

To convert a value’s Markdown, use the markdown filter:

## Notes
{{ notes | markdown }}

A line that holds only Liquid tags that print nothing, such as {% for %}, {% if %}, {% else %} or {% assign %}, is left out of the document with its line break. Put those tags on lines of their own, above and below the rows or items they repeat or hide:

| Item | Price |
| --- | --- |
{% for item in items %}
{% if item.price > 0 %}
| {{ item.name }} | {{ item.price | currency }} |
{% endif %}
{% endfor %}
| **Total** | {{ total | currency }} |
{% for step in steps %}
- {{ step }}
{% endfor %}

Each item’s row is in the same table, and each step is an item of the same list. Without this, the empty lines the tags left would end the table (its rows would print as text) and space out the list.

  • A block inside one line works as it’s written: | {% if paid %}Yes{% else %}No{% endif %} |.
  • A line with a tag that prints, such as {% signature %}, stays, as does a line with a value or any other text.
  • You don’t need Liquid’s whitespace control ({%- and -%}) in Markdown. A tag written with it keeps it: -%} removes every space and line break after the tag, which joins the next line to the tag’s line.

A {% capture %} block’s text prints like a value, as text. Add | markdown to convert its Markdown.

The Write in Markdown setting, in the template editor’s settings, converts the body when you change it. Undo puts the body back as it was.

  • Turning it on converts the body’s HTML to Markdown. What Markdown can’t write, such as an element with a class or a style, stays as HTML in the Markdown. The Liquid stays as you wrote it, and tags between a table’s rows or a list’s items go on lines of their own, without whitespace control ({%- becomes {%), which would join those lines again. A body with Liquid between an HTML tag’s attributes, as in <div {% if wide %}hidden{% endif %}>, isn’t converted: move the Liquid into an attribute’s value first.
  • Turning it off converts the body’s Markdown to the HTML it makes, with the Liquid as you wrote it. Tags on lines of their own go around the elements they repeat or hide: a loop around each table row or list item, an {% if %} around the whole list.

A block whose tags are inside the Markdown’s lines can’t always say the same thing in HTML, such as one that starts in one list item and ends in the next. When you turn Markdown off, the editor lists those blocks with their lines in the HTML, so you can check them.

A submission that sends its own html replaces the template’s body with HTML, even in a Markdown template.