Skip to content

Instantly share code, notes, and snippets.

@vquaiato
Created December 30, 2011 21:35
Show Gist options
  • Select an option

  • Save vquaiato/1541577 to your computer and use it in GitHub Desktop.

Select an option

Save vquaiato/1541577 to your computer and use it in GitHub Desktop.
Limpando conteúdo dos arquivos markdown importados do wordpress
#encoding: UTF-8
Dir.foreach("./") do |file|
begin
p "started #{file}"
content = File.read(file)
#quebra de linha para headings
replace = content.gsub /###/, "\n\n###"
replace = content.gsub /##/, "\n\n##"
#code format
replace.gsub! /}/, "}\n"
replace.gsub! /{[^\s?\.]/, "{\n"
replace.gsub! /;(\s*)/, ";\n "
replace.gsub! /(\s\s+)(var|double|string|decimal|int|bool|void|List<.*>|IEnumerable<.*>)\s/, "\n\\2\s"
replace.gsub! /^(public|private|protected|internal|static)\s/, "\n\\1\s"
replace.gsub! /\s+(if|for|foreach|do|while)\s?({|\()/, "\n\\1\\2"
replace.gsub! /\s+(return)(\s.*);/, "\n\\1\\2;"
replace.gsub! /({\s*)(public|private|protected|internal|static)\s/, "\\1\n\\2\s"
replace.gsub! /(\w*)(public|private|protected|internal|static)\s/, "\\1\n\\2\s"
#syntax highlight
replace.gsub! /<\/pre>/, "\n{% endhighlight %}\n"
replace.gsub! /<pre (.*)">/, "\n{% highlight csharp %}\n"
#assinatura
replace.gsub! /(\.|\?|\!|\\)(Abraços|Att),/, "\\1\n\n\\2,\n"
File.open(file, "w") {|f| f.puts replace}
p "ended #{file}"
rescue
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment