Is it possible to include external files when using Jade’s :markdown filter?

孤者浪人 提交于 2019-12-20 10:35:39

问题


I'm building an Express.js Node app and using Jade templates. Jade provides a :markdown filter which enables embedding Markdown code inside Jade:

h1 This is Jade
:markdown
  ## And this is Markdown
h3 Back in Jade

(Note: In order to use this filter you have to npm install a Markdown engine, e.g. npm install marked --save. You don't have to require() this module within your Express app, but it has to be installed.)

So, embedding Markdown within Jade works fine. However, I would like to keep my Markdown in separate files and include them in Jade templates dynamically. I've tried this and it does not work:

:markdown
  include ../path/to/markdown/file.md

The include command is treated as source code instead of being interpreted as a command. Is it possible to inject Markdown from external files within the :markdown filter?

Please don't provide workarounds! I know how to work around this issue. I want to know if the :markdown filter is compatible with external Markdown files.


回答1:


You can include markdown files using the :md filter modifier.

eg.

html
  body
    include:md ../path/to/markdown/file.md

Language Reference: https://pugjs.org/language/includes.html#including-filtered-text




回答2:


the :md modifier does not work for me either, but this works:

html
  body

    // works:

    include file.md

    //- does not work:

    include:markdown file.md
    include:md file.md

I am using docpad with the HTML5 Boilerplate template.

You also should consider the problem of no auto-generation of including *.html.jade files of such includes:

How to auto-generate html from jade file when only included markdown file has changed in livereload development environment?




回答3:


First, run this command:

npm install marked --save

Then, do this:

include:md ../path/to/markdown/file.md


来源:https://stackoverflow.com/questions/20828119/is-it-possible-to-include-external-files-when-using-jade-s-markdown-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!