Aptana Studio 3 - 如何更改此命令(正则表达式替换)
我想要做什么:
编辑 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
What i want to do:
edit the CSS command tidier to include a space/tab after the selctor: #myid{...}
to be #myid {...}
the file I want to edit:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命令> CSS>编辑此捆绑包。它将获取原始 CSS 包的 git 克隆,然后在应用程序内生成一个项目供您自定义。您可以在那里自定义该命令的文件。然后您可能需要编辑以下行:
code.gsub!(/\s*{\s*/im, "{")
为code.gsub!(/\s*{\s*/im, " { “)
。该行将
{
前后的所有空间折叠为无空间。修改后会在其前面留一个空格。Commands > CSS > Edit this Bundle. It will grab down a git clone of the original CSS bundle, then generate a project inside the app for you to customize. There you can customize that command's file. Then you'll probably want to edit the following line:
code.gsub!(/\s*{\s*/im, "{")
to becode.gsub!(/\s*{\s*/im, " {")
.That line is collapsing all space before and after
{
down to no space. The modification will leave a space ahead of it.