使用Jade时可能包含外部文件:markdown filter? [英] Is it possible to include external files when using Jade’s :markdown filter?

查看:143
本文介绍了使用Jade时可能包含外部文件:markdown filter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Express.js Node应用程序并使用Jade模板。 Jade提供了一个:markdown 过滤器,可以在Jade中嵌入Markdown代码:

  h1这是Jade 
:markdown
##这是Markdown
h3回到Jade

(注意:为了使用此过滤器,您必须安装Markdown引擎,例如 npm安装标记为--save 您的Express应用程序中必须具有 require()此模块,但必须安装。)



所以在玉石嵌入Markdown工作正常。但是,我想将我的Markdown保存在单独的文件中,并将它们包含在动态的Jade模板中。我已经尝试过了,它不起作用:

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

include 命令是被视为源代码,而不是被解释为一个命令。可以从中的外部文件注入Markdown:markdown 过滤器?



请不要提供解决方法!我知道如何解决这个问题。我想知道:markdown 过滤器是否与外部Markdown文件兼容。

解决方案

您可以使用:md过滤器修饰符包含标记文件。



例如。

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

语言参考: https:// pugjs .org / language / includes.html#includes-filtered-text


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.

解决方案

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

这篇关于使用Jade时可能包含外部文件:markdown filter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆