zephraph / nunjucks-markdown

Markdown extension for Nunjucks. Use your own renderer!
MIT License
49 stars 12 forks source link

Add the ability to include markdown from a separate file. #2

Closed zephraph closed 9 years ago

zephraph commented 10 years ago

Should be able to include markdown files.

{% markdown "content.md" %}

As suggested by @tedw

zephraph commented 9 years ago

@tedw I've got an experimental implementation of this in the include branch if you'd like to test it out. I'd love some feedback.

jbmoelker commented 9 years ago

I'd like this functionality as well. The experimental implementation uses fs.readFileSync(url) however I believe this doesn't take into account the root directories which can be set in the Nunjucks environment. The built-in include, extends, import and call do take care of this, but couldn't find directly how.

Could you simply use {% markdown %}{% include "path/to/content.md" %}{% endmarkdown %} or is content with the markdown blog not parsed (in time)?

zephraph commented 9 years ago

It doesn't actually work that way. Everything inside the markdown blocks is treated as raw markdown code. I'll look into using the import functionality in the markdown include block though, that's actually a pretty exciting idea.

tedw commented 9 years ago

@zephraph Finally got around to testing this out—works great! Only issue is that it seems to fail with relative file paths, which I think is the issue @jbmoelker was raising.

zephraph commented 9 years ago

I'll try to work on this tomorrow if I have time. I'd really like to have this functionality as well.

zephraph commented 9 years ago

Okay, so I just added a test in to verify, but adding and include tag inside the markdown tag now works. I still fully intent to add argument support but I need to figure out where the relative path variable is saved. I should have that tonight or tomorrow if all goes well.

Again, sorry for being absent guys! Hope the update works well for you, if you have any issues let me know.

zephraph commented 9 years ago

The implementation was easier than expected.

Includes can be done with {% markdown "content.md" %} and it will respect nunjuck's configured relative path.

tedw commented 9 years ago

Happy New Year! Thanks for making the update. I just tested it out, but it's still looking in the root directory. I'm using 'gulp-nunjucks-render' instead of 'nunjucks' which might have something to do with it.

zephraph commented 9 years ago

Strange. If you have time could you try to write a test that replicates your failure? If not I can try to do it soon, but it'll probably be next week at the earliest because I'm slammed at work right now.

zephraph commented 9 years ago

I'm going to close this again and open up a new issue for this problem.

tedw commented 9 years ago

So sorry for not getting back to you sooner! Work got very busy for me and I lost track of this.

I was finally able to test again and can confirm the issue has been resolved! I think the issue I had previously was because I was using an older syntax for 'marked' settings. Once I switched to the marked.setOptions() method everything worked great.

zephraph commented 9 years ago

Good! I'm glad it works for you.

I updated it again after that. The latest version doesn't even require marked. You just provide your own rendering function.