CSS 2 Sass:如何更改生成的SCSS的输出格式?

时间:2010-07-07 03:48:49

标签: css ruby sass

我想将CSS转换为SCSS,如下所示:

.top {
  margin-top: 1em;
  margin-bottom: 1em;
  nav {
    background: #333;
  }
  ul {
    padding: 0;
    display: table-row;
  }
  li {
    display: table-cell;
  }
}

相反,我得到了这个:

.top {
  margin-top: 1em;
  margin-bottom: 1em;
  nav {
    background: #333; }
  ul {
    padding: 0;
    display: table-row; }
  li {
    display: table-cell; } }

如何更改命令中的输出缩进:

sass-convert public/stylesheets/application.css public/stylesheets/application.scss

谢谢!

3 个答案:

答案 0 :(得分:1)

根据文档(并在命令行上检查'sass-convert -h'),从css转到scss(或sass)时无法改变输出样式。

答案 1 :(得分:1)

我遇到了同样的问题,因此我使用以下Python进行了一些后期处理,并将生成的输出修复为:expanded output style

import sys
    import re

path = sys.argv[1]

scss = open(path).read()

# Fix up the indentation of closing braces to use a :expanded rather than :nested style.
scss = re.sub(r'\t(\t*)([^\}\n]*;) (\}.*)', r'\t\1\2\n\1\3', scss)
for i in range(0, 10):
    # This line is executed multiple times to fix up multiple closing braces on a single line.
    scss = re.sub(r'\t(\t*)\};? \}', r'\t\1}\n\1}', scss)

open(path, 'w').write(scss)

答案 2 :(得分:0)

您可以使用此工具http://css2sass.heroku.com/

执行此操作

我用它将CSS转换为SCSS