docpad / docpad-plugin-marked

Markdown rendering for DocPad, using Marked

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Marked not converting line breaks to `<p>` tags or rendering HTML when fetched as collection in eco template

tinacious opened this issue · comments

I am having issues with the Marked plugin not rendering line breaks as paragraph tags when content is fetched as a collection. I see the line breaks being added in Chrome dev tools.

I am also having issues with some HTML tags not being rendered, e.g. lists. Some tags (i.e. <i>) appear to render fine.

I've created a collection as so:

services: ->
  @getCollection('html').findAllLive(
      relativeOutDirPath: 'services'
      omitFromCollection: {$ne: true}
      [{weight:1}]
  )

In my Eco template, I am fetching the collection as so:

<% for service in @getCollection("services").findAll().toJSON(): %>

The following code will render some HTML (like <i> tags) but it will not convert \n to <p>:

<%- service.content %>

When it's rendered on its own page, it works perfectly. Am I creating the collection wrong or is this a bug?

I added some hacky JS for the meantime to fix the line breaks, and thankfully I don't need to use lists at this time, but it would be nice if the Marked plugin supported this out-of-the-box for fetching as collections as well.

For others who have the same problem, here's my quick fix for the paragraphs until the Marked plugin converts line breaks to paragraphs:

<p>
<% @serviceContent = service.content.replace(/\n/g, '</p><p>') %>
<%- @serviceContent %>
</p>

Thanks for your help!