簡體   English   中英

防止HAML在生成的HTML文件中呈現換行符

[英]Prevent HAML from rendering newline in produced HTML file

我有此HAML代碼:

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

孤立的\\. 之所以在這里,是因為我不希望句號(。)成為鏈接的一部分。

這幾乎可以用,但是backback之間有一個空格. ; 自然,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>\.

有一個更好的方法嗎?

HAML接受純HTML,因此您可以編寫:

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

這將為您提供所需的輸出。

您也可以使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM