Skip to content

Instantly share code, notes, and snippets.

@beakr
Created January 4, 2014 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beakr/8261294 to your computer and use it in GitHub Desktop.
Save beakr/8261294 to your computer and use it in GitHub Desktop.
Simple Ruby code for parsing markdown in a directory (Github flavoured Markdown, that is).
# Run 'bundle' in the command line afterward
source 'https://rubygems.org'
gem 'guard'
gem 'guard-rake'
gem 'rake'
gem 'rainbow'
gem 'github-markdown'
guard :rake, task: 'doc' do
watch(/docs\/formal\/(.+)\.md/)
end
require 'github/markdown'
module Dendrite
class Markdown
def self.generate
Dir.glob('docs/formal/*.md').each do |f|
file = File.open(f);
contents = ''
file.each { |line| contents << line }
parsed_markdown = GitHub::Markdown.render_gfm(contents)
new_file_name = f.gsub(/docs\/formal\//, '').gsub(/\.md/, '') + '.html'
new_file = "docs/output/#{new_file_name}"
File.open("./#{new_file}", 'w') { |html| html.write(parsed_markdown) }
end
end
end
end
require 'rake'
require 'rainbow'
require './markdown.rb'
task :doc do
begin
Dendrite::Markdown.generate
puts Rainbow("Generated documentation.").green
rescue
puts Rainbow("Failed to generate documentation!").red
raise
end
end
namespace :doc do
task :clean do
Dir.glob('docs/output/*.html').each { |f| FileUtils.rm(f) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment