HAML-非常奇怪的缩进差异-错误? [英] HAML - a very weird indentation difference - bug?

查看:48
本文介绍了HAML-非常奇怪的缩进差异-错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此HAML

%script{:type => "text/javascript"}
  :plain
    $(document).ready(function() {
      bar();
      var foo = foo_func("#{}");
    });

如预期的那样:

<script type='text/javascript'>
  $(document).ready(function() {
    bar();
    var foo = foo_func("");
  });
</script>

但是此 ALMOST IDENTICAL HAML(仅将bar()更改为prep()):

But this ALMOST IDENTICAL HAML (changed only bar()to prep()):

%script{:type => "text/javascript"}
  :plain
    $(document).ready(function() {
      prep();
      var foo = foo_func("#{}");
    });

给出了这一点:

<script type='text/javascript'>
  $(document).ready(function() {
  prep();
  var foo = foo_func("");
});
</script>

注意第二种情况.

为什么将bar()更改为prep()会引起这种奇怪的差异?

Why would changing bar()to prep() cause this weird difference?

推荐答案

这是由prep()中的字符pre与Haml用于处理空白的正则表达式匹配引起的.

This is being caused by the characters pre in prep() matching a regex that Haml is using to deal with whitespace.

在Haml中,您可以使用空格来指定元素的内容,这通常是可以的,因为在查看HTML时空格被压缩",因此它显示为单个字符.但是,空格在某些HTML元素(precodetextarea)中很重要,并且Haml尝试检测并处理这些元素.在这种情况下,匹配正则表达式,并且不缩进第一行之后的代码段.

In Haml you use whitespace to specify the contents of elements, and normally this is okay since when viewing HTML whitespace is "squashed" so that it appears as a single character. However, whitespace is important in some HTML elements (pre, code and textarea), and Haml tries to detect and deal with these elements. In this case the regex is matched and the block after the first line isn’t indented.

此代码已在最新版本(当前为4.0.1.rc.1)中进行了更改,并且在该版本中未发生.我还创建了一个拉动请求,用于修复3-1分支中的正则表达式.

This code has been changed in the latest version (currently 4.0.1.rc.1) and this doesn’t happen in that version. I’ve also created a pull request that fixes the regex in the 3-1 branch.

这篇关于HAML-非常奇怪的缩进差异-错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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