【发布时间】:2011-08-17 10:04:31
【问题描述】:
我想做什么:
编辑 CSS 命令 tidier 以在选择符后包含一个空格/制表符:#myid{...} 为 #myid {...}
我要编辑的文件:
format_css_singleline.rb
command "Format CSS Single-line" do |cmd|
cmd.key_binding = "M1+M2+F"
cmd.output = :replace_selection
cmd.input = :selection
cmd.scope = "source.css"
cmd.invoke do |context|
code = $stdin.read
code.gsub!(/\n{3,}/im, "\n\n")
code.gsub!(/[ \t]+/im, " ")
code.gsub!(/(?m)([;:])\s+/im) {|match| "#{$1}" } //i've tried adding a space after the {$1} here
code.gsub!(/\s*}/im, "}")
code.gsub!(/\s*{\s*/im, "{")
code.gsub!(/[ \t]*,[ \t]*/im, ", ")
code.gsub!(/@import(.*?);/im) {|match| "@import#{$1};\n\n" }
code
end
end
【问题讨论】: