Publican v0.6.0 update

By Craig Buckler

387 words, 2-minute read

books
Image courtesy of Charlota Blunarova

Publican v0.6.0 was released on .

There are no breaking changes, but you should encounter fewer issues when using complex template literal expressions in markdown content.

Markdown conversion complexities #

Publican uses the excellent markdown-it parser to convert markdown to HTML. This is done once shortly after the content is loaded.

Markdown parsers usually leave simpler template literal expressions as-is:

<!-- this should work -->
## ${ data.title }

but more complex code can have characters replaced and it breaks literal parsing:

<!-- this fails -->
${ toArray( tacs.all ).map(i => i.title && '<li>' + i.title + '</li>') }

<!-- because it's converted to -->
${ toArray( tacs.all ).map(i =&gt; i.title &amp;&amp; ‘<li>’ + i.title + ‘</li>’) }

Expressions inside or between code blocks may also fail to execute.

Publican v0.5.0 and below provided some workarounds such as using double-bracket ${{ expressions }} to denote real expressions, adopting HTML snippets in markdown, simplifying expressions using custom jsTACS functions, or switching to HTML files.

Publican v0.6.0 improvements #

Publican v0.6.0 comments out template literal expressions before markdown is converted to HTML. Comments are then removed before the expressions are parsed. The code above will render as expected.

Previous versions could also add additional HTML where you may not have wanted it. For example, the single line:

${ '<h1>' + data.title + '</h1>' }

rendered as:

<p><h1>A title</h1></p>

In version 0.6.0, it’s rendered as:

<h1>A title</h1>

Double-bracket ${{ expressions }} #

Double-bracket ${{ expressions }} may still be necessary in situations where you have nested expressions:

${{ toArray( tacs.all ).map(i => i.title && `<li>${ i.title }</li>`) }}

or you want to execute an expression inside a code block:

```js
console.log( '${{ data.title }}' );
```

Get started #

The Publican documentation provides a quick start guide, a detailed set-up guide, API references, and common recipes you can use and adapt for your own projects.