阻止HAML在生成的HTML文件中呈现换行符

时间:2018-02-09 11:12:34

标签: html ruby haml

我有这个HAML代码:

%p
    This page is for our staff. If you came here by mistake,
    %a(href="index.html") you can go back
    \.

孤立的\.就在那里,因为我不希望句号(。)成为链接的一部分。

这几乎可行,但back.之间有一个空格;当然,HAML将新行插入HTML呈现文件中的HAML源代码中。

换句话说,这是HTML产生的:

<p>
    This page is for our staff. If you came here by mistake,
    <a href="index.html">you can go back</a>
    . <!-- I want the period to be on the previous line -->
</p>

由于<p>标记内的字词由空格分隔,因此back.之间有一个空格。如何删除此空间?

我找到了一种方法来做到这一点,但它很难看(或者我不会问这个问题):

%p
    This page is for our staff. If you came here by mistake,
    %a(href="index.html") you can go back
    %span>\.

有更好的方法吗?

2 个答案:

答案 0 :(得分:2)

HAML接受普通的html,所以你可以写:

%p
    This page is for our staff. If you came here by mistake,
    <a href="index.html">you can go back</a>.

这将为您提供所需的输出。

答案 1 :(得分:0)

你也可以使用succeed帮助器,虽然它看起来有点滑稽:

= succeed '.' do 
  %a(href="index.html") you can go back

将产生:

<a href="index.html">you can go back</a>.\n

如此完整的例子就像:

%p
  This page is for our staff. If you came here by mistake,
  = succeed "." do 
    %a(href="index.html") you can go back

渲染输出:

<p>
This page is for our staff. If you came here by mistake,
<a href='index.html'>you can go back</a>.
</p>