Created
June 29, 2011 16:04
-
-
Save timblair/1054177 to your computer and use it in GitHub Desktop.
Uses the `markdown` command-line tool to build an HTML doc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# A simple wrapper to the command-line `markdown` tool which wraps | |
# HTML header and footer, including any style references you choose. | |
require 'open3' | |
require 'erb' | |
# Define the ERB template to wrap the HTML content in. | |
template = ERB.new <<-EOS | |
<html> | |
<head> | |
<title><%= title %></title> | |
<link rel="stylesheet" href="https://gist.github.com/raw/516763/632b066c7c18edc91485ba13b37ba50a9b2caac7/screen.css" /> | |
</head> | |
<body> | |
<%= content %> | |
</body> | |
</html> | |
EOS | |
# Run the given file through the markdown command-line tool. | |
content = Open3.popen3('markdown') do | stdin, stdout, stderr | | |
stdin.puts File.read(ARGV.first) | |
stdin.close | |
stdout.read | |
end | |
# Find the first `<h1>` tag to use as a document title. | |
title = content.match(/<h1[^>]*>(.*)<\/h1>/)[1] || "Unknown" | |
# Output the rendered HTML to STDOUT. | |
puts template.result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment