jekyll-archives icon indicating copy to clipboard operation
jekyll-archives copied to clipboard

post.content markdown not rendered

Open gdhnz opened this issue 10 years ago • 45 comments

I'm displaying full posts in my archives but the post is displaying the raw markdown and not being rendered.

gdhnz avatar Dec 18 '14 19:12 gdhnz

Using {{ content }} also doesn't show the content at all.

gdhnz avatar Dec 18 '14 19:12 gdhnz

Ah, I see. Generators are called before the render process is complete. That said, this should work nevertheless. Can you post a link to your site? What does your archive template look like? What version of Jekyll are you using?

parkr avatar Dec 18 '14 20:12 parkr

I haven't got the site live yet as there's still a lot of other things I need to first.

Here's the archive layout I'm using with the Jekyll 2.5.2.

---
layout: default
---

<h2 class="archive-title">Archives: {{ page.title | date: '%B %Y' }}</h2>
{% for post in page.posts %}
<article> 
    <header class="entry-header">
        <h2 class="entry-title">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
        </h2>
        <time class="published" datetime="{{ post.date }}" pubdate="">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date_to_string }}</a>
        </time>
    </header>

    <div class="entry-content">
        {{ content }}
    </div>
</article>
{% endfor %}

Using {{ content }} instead of {{ page.content }} doesn't return anything.

gdhnz avatar Dec 18 '14 21:12 gdhnz

Yeah it has to be post.content instead of content or page.content.

parkr avatar Dec 18 '14 22:12 parkr

and we're back to my original statement. When I use post.content, none of the markdown or liquid tags are rendered.

gdhnz avatar Dec 18 '14 23:12 gdhnz

and we're back to my original statement. When I use post.content, none of the markdown or liquid tags are rendered.

What does that mean? Plain text? Or a code block? Can you paste a screenshot?

parkr avatar Dec 18 '14 23:12 parkr

Here's the screenshot.

screen shot 2014-12-19 at 1 01 49 pm

gdhnz avatar Dec 19 '14 00:12 gdhnz

Is this not the case for any post/page listing? post.content contains the raw input, not the processed output.

alfredxing avatar Jan 07 '15 06:01 alfredxing

Here's the snippet for my index.html file that displays everything correctly.

<div class="listing">
    {% for post in paginator.posts %}
    <article> 
        <header class="entry-header">
            <h2 class="entry-title">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
            </h2>
            <time class="published" datetime="{{ post.date }}" pubdate="">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date: '%B %d, %Y' }}</a>
            </time>
        </header>
        <div class="entry-content">
            {{ post.content }}
        </div>
    </article>
    {% endfor %}
</div>

gdhnz avatar Jan 07 '15 06:01 gdhnz

I'm running into this bug too -- {{post.content}} in an archive page loop does not process through markdown -- so you end up getting the raw markdown text instead of intended HTML.

davepeck avatar Jan 13 '15 00:01 davepeck

I'm running into this bug too -- {{post.content}} in an archive page loop does not process through markdown -- so you end up getting the raw markdown text instead of intended HTML.

Generators are run before the render step. https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb#L51-L58

parkr avatar Jan 13 '15 00:01 parkr

Understood, thanks!

I'm wondering where the solution lies. It feels like the current behavior is undesirable. Is this something that needs to be filed against Jekyll itself -- an improvement for Generators for future consideration? Or is there a way to improve jekyll-archives here? Thanks.

davepeck avatar Jan 13 '15 00:01 davepeck

The solution is to allow Jekyll to do the rendering itself. The jekyll-paginate process does this by appending a Page to site.pages and letting Jekyll do its thing. From a cursory glance at the source code here, the render process is taken care of here, which would yield this error. /cc @alfredxing

parkr avatar Jan 13 '15 02:01 parkr

@parkr Nice catch! I'll see about fixing that up and just adding it as a Page.

alfredxing avatar Jan 13 '15 04:01 alfredxing

I’m not sure if I’m misunderstanding the status of this issue, but is there a workaround for this currently, or does the jekyll-archives plugin need to be fixed?

matthewmcvickar avatar Apr 02 '15 04:04 matthewmcvickar

@matthewmcvickar Sorry for the wait; I've been quite busy recently with school. I'll get around to this as soon as I have some time!

alfredxing avatar Apr 02 '15 05:04 alfredxing

Just looked into this again, and now I remember why I didn't append the archives to site.pages: if this was done, anyone iterating over site.pages (in the nav, for example) would see archive pages as well... @parkr Any suggestions?

alfredxing avatar Apr 02 '15 05:04 alfredxing

The only way to enforce this would be to render every item...

parkr avatar Apr 02 '15 17:04 parkr

You mean render every page as necessary?

alfredxing avatar Apr 03 '15 16:04 alfredxing

The markdownify filter might be useful for this.

{{post.content | markdownify}} or {{ content | markdownify}}, whatever fits.

DylanVann avatar Apr 20 '15 17:04 DylanVann

While using markdownify does appear to render the markdown, it doesn't render {% highlight bash %}

gdhnz avatar Apr 21 '15 03:04 gdhnz

I had this same issue. I have an _include file for all my posts. For the archive layout, I just did the following:

{% for post in page.posts %}
  {% include post.html item=post markdown=true %}
{% endfor %}

and within my post include:

  {% if include.markdown %}
    {{ include.item.content | markdownify }}
  {% else %}  
    {{ include.item.content }}
  {% endif %}

Since generators are run before renders, this might be the only solution (unless you do the markdown step in the generation in jekyll-archives itself... haven't looked at the code to see how possible that is)

sumdog avatar May 12 '15 13:05 sumdog

While the previous suggestion of an include works for markdown, it still doesn't render {% highlight bash %} blocks.

Is there a similar method like markdownify that does render code highlights? hilightify?

{{post.content | markdownify | hilightify }}

gdhnz avatar Jun 05 '15 02:06 gdhnz

Not to my knowledge. I've been able to get rid of the problem by downgrading from jekyll-3.0.0.pre.beta8 to jekyll-2.5.3 for the time being... (though that means going back to dealing with issue #2607 which was fixed in the beta :disappointed_relieved:).

MaximeKjaer avatar Jul 09 '15 21:07 MaximeKjaer

This still happens with jekyll-2.5.3 and jekyll-archives 2.0.0. @MaximeKjaer, what is your setup where you can get post.content rendered from a jekyll-archives layout?

nbolten avatar Aug 14 '15 20:08 nbolten

I have been getting the same issue as this. It was strange because some of the .content was coming through after the markdown had been applied... and then stopped on a few others...

My solution was

{% for post in site.categories.solutions reversed %}
    {{ post.content | markdownify }}
{% endfor %}

AaronLayton avatar Oct 02 '15 13:10 AaronLayton

Getting the same issue with this when using {{post.excerpt}}

{{post.exceprt | markdownify}} works, but doesn't render highlight blocks {% highlight ruby %}

is there any fix for this?

insipx avatar Oct 21 '15 22:10 insipx

@nbolten I'm having some real trouble replicating this. It happened without jekyll-archive (I somehow overlooked that this was a jekyll/jekyll-archives, and not jekyll/jekyll issue page, so I don't know if my initial comment still is relevant -- sorry!).

I'll try to look into it some more, and will post if I find anything of interest.

MaximeKjaer avatar Oct 21 '15 23:10 MaximeKjaer

This problem also happens with collections. I guess this means you should really provide a way to render the content of an element like markdownify (which by the way doesn't render tables and such things provided by redcarpet if you specify it in _config.yml).

Thanks!

EDIT: Maybe this is a different issue though. Collections documents supposedly have an output property which does exactly what we want, but for me, it does nothing. http://jekyllrb.com/docs/collections/#documents

TheoWinterhalter avatar Nov 09 '15 12:11 TheoWinterhalter

I am having the same problem running on Debian Jessie using the following gems.

bigdecimal (1.2.6) bundler-unload (1.0.2) executable-hooks (1.3.2) gem-wrappers (1.2.7) io-console (0.4.3) json (1.8.1) minitest (5.4.3) power_assert (0.2.2) psych (2.0.8) rake (10.4.2) rdoc (4.2.0) rubygems-bundler (1.4.4) rvm (1.11.3.9) test-unit (3.0.8)

I believe I'm running Jekyll version 3, but I don't know how to get the current version of Jekyll that I'm using.

The solution that worked for me was: {{ page.content | markdownify }}

I was using Kramdown for my markdown.

nexocentric avatar Mar 02 '16 22:03 nexocentric