Skip to content

Instantly share code, notes, and snippets.

@ggarnier
Created June 3, 2014 18:09
Show Gist options
  • Save ggarnier/67ba17583168133abfe5 to your computer and use it in GitHub Desktop.
Save ggarnier/67ba17583168133abfe5 to your computer and use it in GitHub Desktop.
Textile to Markdown
def process_file oldfilename
markdown_content = textile_to_markdown(File.read(oldfilename))
filename = oldfilename.split("/").last.split(".").first.gsub("-", "_")
File.open("doc_src/content/#{filename}.md", "w") do |f|
f.write <<-CONTENT
---
title: #{filename.capitalize}
group: Base
---
CONTENT
f.write(markdown_content)
end
end
def textile_to_markdown textile_content
textile_content.
gsub(/h(\d)\./) {|s| '#' * $1.to_i }.
gsub(/@([^@\n]+)@/, '`\1`').
gsub(/"([^"]+)":([^ \.]+(\.html)?)/, '[\1](\2)').
gsub(/<xml>/, '~~~html').
gsub(/<\/xml>/, '~~~')
end
Dir.glob("doc_src_old/*.textile") do |oldfilename|
process_file oldfilename
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment