Jade:段落中的链接

mah*_*off 115 markup node.js pug

我正在尝试用Jade创作几段,但是当段落中有链接时发现很难.

我能想出的最好的,我想知道是否有办法用更少的标记来做到这一点:

p
  span.
   this is the start
   of the para.
  a(href="http://example.com") a link
  span.
    and this is the rest of
    the paragraph.
Run Code Online (Sandbox Code Playgroud)

Cla*_*ick 113

从jade 1.0开始,有一种更简单的方法可以解决这个问题,遗憾的是我无法在官方文档中的任何地方找到它.

您可以使用以下语法添加内联元素:

#[a.someClass A Link!]
Run Code Online (Sandbox Code Playgroud)

因此,在ap中不进入多行的示例将是:

p: #[span this is the start of the para] #[a(href="http://example.com") a link] #[span and this is the rest of the paragraph]
Run Code Online (Sandbox Code Playgroud)

您还可以执行嵌套的内联元素:

p: This is a #[a(href="#") link with a nested #[span element]]
Run Code Online (Sandbox Code Playgroud)

  • 这在此处记录:http://jade-lang.com/reference/interpolation/在"Tag Interpolation"下. (6认同)

Dan*_*lig 93

您可以使用降价过滤器并使用markdown(和允许的HTML)来编写段落.

:markdown
  this is the start of the para.
  [a link](http://example.com)
  and this is the rest of the paragraph.
Run Code Online (Sandbox Code Playgroud)

或者,您似乎可以简单地输出HTML而不会出现任何问题:

p
  | this is the start of the para.
  | <a href="http://example.com">a link</a>
  | and this is he rest of the paragraph
Run Code Online (Sandbox Code Playgroud)

我自己并没有意识到这一点,只是使用jade命令行工具对其进行了测试.它似乎工作得很好.

编辑: 看来它实际上可以完全在Jade中完成,如下所示:

p
  | this is the start of the para  
  a(href='http://example.com;) a link
  |  and this is the rest of the paragraph
Run Code Online (Sandbox Code Playgroud)

不要忘记para末尾有一个额外的空间(虽然你看不到它.之间| and.否则看起来para.a linkand不会这样para a link and

  • 看起来这可能会在不久的将来用插值来解决,所以你可以做`这是一个段落#[a(href ="#"),里面有一个链接].请参阅https://github.com/visionmedia/jade/issues/936 (9认同)
  • 如果您使用第三个选项,请注意您正在使用哪个编辑器,我使用的是Sublime,默认情况下它将删除段落末尾的空格.最终,我选择了上面的选项2,因为它是最不痛苦的. (3认同)

per*_*era 45

另一种方法:

p
  | this is the start of the para
  a(href="http://example.com") a link
  | this is he rest of the paragraph.
Run Code Online (Sandbox Code Playgroud)

  • 这是最优雅的解决方案. (4认同)