how to preserve quoted chars in sass

126 views Asked by At

How can i preserve or escape paths in sass. We have strings like "Page\Footer\CustomBar\Logo" which are (wrongly) transformed internally to "Page\footer\customBarLogo" How can we preserve the ascii format? We tried with dart sass and ruby sass.

Page\Footer\CustomBar\Logo would be expected result.

1

There are 1 answers

2
Arkellys On

I searched a bit I didn't found any built-in way to do what you need. It seems that backslashes are hard to manipulate with SASS. However, here is how I managed to get your path:

@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}\"");
}

Calling createPath('Page', 'Footer', 'CustomBar', 'Logo'); will return "Page\Footer\CustomBar\Logo".

Honestly, I can't explain how the unquote works, I found the solution thanks to this answer.