【问题标题】:how to preserve quoted chars in sass如何在 sass 中保留引用的字符
【发布时间】:2019-02-18 17:50:33
【问题描述】:

如何在 sass 中保留或转义路径。我们有像 "Page\Footer\CustomBar\Logo" 这样的字符串(错误地)在内部转换为 "Page\footer\customBarLogo" 我们如何保留 ascii 格式?我们尝试了 dart sass 和 ruby​​ sass。

Page\Footer\CustomBar\Logo 是预期的结果。

【问题讨论】:

    标签: sass node-sass gulp-ruby-sass


    【解决方案1】:

    我搜索了一下,没有找到任何内置的方法来做你需要的事情。似乎用 SASS 很难操纵反斜杠。但是,这是我设法获得您的路径的方法:

    @function createPath($path...) {
       $finalPath: null;
    
       @each $el in $path {
          @if($finalPath) {
             // Do not add the slashes at the beginning of the string
             $finalPath: $finalPath + "\\";
          };
    
          $finalPath: $finalPath + $el;
       }
    
       // At this point, $finalPath = "Page\\Footer\\CustomBar\\Logo"
       @return unquote("\"#{$finalPath}\"");
    }
    

    调用createPath('Page', 'Footer', 'CustomBar', 'Logo'); 将返回"Page\Footer\CustomBar\Logo"

    老实说,我无法解释unquote 的工作原理,感谢this answer,我找到了解决方案。

    【讨论】:

    • 感谢 Arkellys 的帮助,但这并不能真正解决我们的问题,因为我们使用字符串将数据结构注入到 sass 代码中。当然,我们可以为该属性设置一个数组,但我想拥有两个可以正常工作的反斜杠更有意义。我会看看在接下来的几天里我是否能找到更多关于这个问题的意见。谢谢。
    • @Rob 哦,好吧,我认为您应该编辑您的问题并提供更多详细信息。 :)
    猜你喜欢
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    相关资源
    最近更新 更多