在LESS中输入长转义的属性值时,如何将其拆分为换行符 [英] On input of long escaped property value in LESS, how to split it to a newline

查看:152
本文介绍了在LESS中输入长转义的属性值时,如何将其拆分为换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要在LESS中输入一个非常长的 转义属性值.我可以通过设置变量来添加 final格式的css 中的换行符来输出,例如添加@nl: `"\n"`;这样的换行符,并在转义的字符串中使用它来输出 output 在属性值中.因此:

Suppose I have a really long escaped property value to input in LESS. I can get it to output with newlines in the final formatted css by setting a variable to add a newline like so @nl: `"\n"`; and use that in my escaped string to output newlines in the property value. So this:

@nl: `"\n"`;

.test {
  property: ~"one,@{nl}            two";
}

将输出以下内容:

.test {
  property: one,
            two;
}

问题是,是否可以使用换行符输入,例如:

The question is whether there is any way to input it with newlines, something like:

.test {
  property: ~"one,
              two";
}

这会在LESS中抛出Parse error: Unrecognised input.像 progid:DXImageTransform.Microsoft.Matrix 将从能够以换行符开始的代码中受益.

This throws a Parse error: Unrecognised input in LESS. A long set of property values like one might have with a progid:DXImageTransform.Microsoft.Matrix would benefit from being able to code it with newlines to begin with.

尽管我发布了自己发现的问题的答案,但如果存在的话,我也愿意提出一个更简单的答案.

推荐答案

好吧,我发现的一种解决方案是将每行放在自己的转义字符串中.因此,这对于输入和输出似乎都相当有效(取决于选项卡设置是什么):

Well, one solution I have found is to put each line in its own escaped string. So this seems to work reasonably well for both input and output (depending on what the tab setting is):

输入较少

@nl: `"\n\t\t\t"`;

.test {
  property: ~"@{nl}"
    ~"one,@{nl}"
    ~"two";
}

输出CSS

.test {
  property: 
      one,
      two;
}

这篇关于在LESS中输入长转义的属性值时,如何将其拆分为换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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