GitHub publishes the github-markup
gem, which can convert markup to HTML. You can either install it as a gem:
$ gem install github-markup
Or, if you are running Ubuntu, install it using apt
:
$ sudo apt install ruby-github-markup
Github-markup
can be used in a Ruby program and from the command line.
Ruby Program Usage
Unfortunately, the code examples of how to use github-markup
that are shown in the README
are under-documented.
However, the command line source code is a complete working example of how to use github-markup
in a Ruby program.
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.dirname(File.realpath(__FILE__)) + "/../lib"
require 'github/markup'
if ARGV.size < 1
print "usage: #{File.basename($0)} FILE [ FILES ... ]\n"
exit 1
end
sources = []
ARGV.each { |s|
begin
file = File.open( s, "r" )
sources.push [ s, file ]
rescue Exception => e
$stderr.print "error: #{e.message}\n"
exit 1
ensure
end
}
sources.each { |name, file|
print GitHub::Markup.render( name, file.read )
file.close
}
Command Line Usage
Here is an example of using github-markup
in a command line:
$ github-markup README.md
Copying HTML Output to the System Clipboard
I normally work in WSL. Here is a convenient way to copy the generated HTML to the clipboard:
$ github-markup README.md | clip.exe
On a generic X11 terminal, you could accomplish the same thing using xclip
:
$ alias xclip='xclip -selection clipboard'
$ github-markup README.md | xclip
Many other Linux clipboard utilities are available, for example cb.
Shelling Out From Ruby
You could also run the command-line executable in a Ruby program:
puts `github-markup README.md`.chomp
Shelling Out From Python
You could also run the command-line executable in a Python program:
import os
print(os.system('github-markup README.md'))