Last active
December 18, 2015 02:49
-
-
Save timabell/5714231 to your computer and use it in GitHub Desktop.
Markdown (md) to html script. One-off.
This file contains hidden or 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 | |
| # https://gist.github.com/timabell/5714231 | |
| require 'redcarpet' | |
| require 'rb-inotify' | |
| @filename=ARGV[0] | |
| if !@filename | |
| puts 'specify filename' | |
| exit 1 | |
| end | |
| def htmlify() | |
| print "Creating/updating #{@html_filename}..." | |
| md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, | |
| extensions = {:autolink => true}) | |
| File.open(@html_filename, 'w') do |filehandle| | |
| filehandle.write(' | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <style type="text/css"> | |
| body | |
| { | |
| font-size: 80%; | |
| } | |
| h1 { border-bottom: 1px solid #666; } | |
| h2 { border-bottom: 1px solid #999; } | |
| body > ul { -webkit-column-count: 2; column-count: 2; } | |
| li { margin-left: 2em; } | |
| h1, h2 { clear: both; margin: 1em 0 0 0; } | |
| </style> | |
| </head> | |
| <body>') | |
| filehandle.write(md.render(File.read(@filename))) | |
| filehandle.write(' | |
| </body> | |
| </html>') | |
| end | |
| puts 'done' | |
| end | |
| @html_filename = @filename + '.html' | |
| htmlify() | |
| system("xdg-open", @html_filename) | |
| notifier = INotify::Notifier.new | |
| while true | |
| notifier.watch(@filename, :create) { htmlify() } | |
| puts 'Watching file for changes...' | |
| notifier.process | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment