【问题标题】:CSS 2 Sass: How do I change the output format of the generated SCSS?CSS 2 Sass:如何更改生成的 SCSS 的输出格式?
【发布时间】:2011-03-12 15:07:45
【问题描述】:

我想将 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

谢谢!

【问题讨论】:

    标签: css ruby sass


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,所以我使用以下 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)
      

      【讨论】:

        【解决方案3】:

        你可以使用这个工具http://css2sass.heroku.com/

        我用它把 CSS 转换成 SCSS

        【讨论】:

          猜你喜欢
          • 2011-05-01
          • 2019-03-02
          • 2012-02-25
          • 1970-01-01
          • 2021-06-21
          • 1970-01-01
          • 1970-01-01
          • 2022-01-21
          • 2019-08-19
          相关资源
          最近更新 更多