Ruby / Slim:从YAML文件解析Markdown

时间:2023-01-15 09:13:56

Been struggling for a while with some YAML parsing inside a Slim template.

在Slim模板中进行了一些YAML解析,一直在苦苦挣扎。

my YAML file contain

我的YAML文件包含

shortdesc: >
 markdown:
  if you want to up the feelgood factor Cuban style, then this Monday night at The Buffalo    Bar is for you...

But when I output the shortdesc node in my template it's displayed as a string and not interpreted. ("markdown: if you....")

但是当我在模板中输出shortdesc节点时,它显示为字符串而不是解释。 (“降价:如果你......”)

Is there a way to parse the YAML output string to interpret the markdown code? If I try

有没有办法解析YAML输出字符串来解释降价代码?如果我试试

p
  markdown:
    = shortdesc

the template doesn't understand the call to the variable containing the YAML node.

模板不理解对包含YAML节点的变量的调用。

Is that even possible?

这有可能吗?

2 个解决方案

#1


2  

It depends on the Markdown Library that you are using.

这取决于您正在使用的Markdown库。

In BlueCloth, it would be something like this:

在BlueCloth中,它将是这样的:

= BlueCloth.new(shortdesc).to_html

#2


1  

Yes it's possible. Just need to use interpolation:

是的,这是可能的。只需要使用插值:

p
  markdown:
    #{shortdesc}

#1


2  

It depends on the Markdown Library that you are using.

这取决于您正在使用的Markdown库。

In BlueCloth, it would be something like this:

在BlueCloth中,它将是这样的:

= BlueCloth.new(shortdesc).to_html

#2


1  

Yes it's possible. Just need to use interpolation:

是的,这是可能的。只需要使用插值:

p
  markdown:
    #{shortdesc}