helpers / helper-markdown

Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.
MIT License
40 stars 23 forks source link

Using YAML front matter with markdown helper renders first line as code #3

Closed DanielaValero closed 8 years ago

DanielaValero commented 8 years ago

description

I am running assemble with gulp, and in my settings, no matter what I write in the first line, it will always be interpreted as if I was writing code.

Expected behaviour

Renders the first line of the content of the markdown as a headline, or whatever syntax was used in there.

Actual behaviour

It renders the first line of the .md file as a code block

<pre><code>    # In progress
</code></pre>

version

0.2.1

Markdown file


---
title: Roadmap

---

# In progress

Layout

  {{#markdown}}
      {% body %}
  {{/markdown}}
DanielaValero commented 8 years ago

The issue was that the spaces between the {% body %} tag was telling the parser that it was a code block. Removing the spaces fixed the issue.

Related issue closed also: https://github.com/assemble/assemble/issues/876

jonschlinkert commented 8 years ago

glad we got this figured out!

you could try using strip-indent in a helper. I've done that in the past but can't remember if there were any drawbacks.

var stripIndent = require('strip-indent');
app.helper('stripIndent', function(options) {
  return stripIndent(options.fn(this));
});

You might need to play with the context passed to options.fn(), but you should be able to use it like this:

{{#markdown}}
{{#stripIndent}}
    {% body %}
{{/stripIndent}}
{{/markdown}}

You could also create another "intermediary" layout that only exists for stripping indentation using this helper. just thinking out loud...