Skip to content

Instantly share code, notes, and snippets.

@yalab
Created October 18, 2012 01:14
Show Gist options
  • Save yalab/3909318 to your computer and use it in GitHub Desktop.
Save yalab/3909318 to your computer and use it in GitHub Desktop.
require 'kramdown'
require 'uri'
require 'pathname'
body =<<EOS
> [link](test)
>> [google](http://www.google.com)
EOS
kramdown = Kramdown::Document.new(body)
nodes = [kramdown.root]
while(node = nodes.shift)
nodes += node.children
case(node.type)
when :a
href = node.attr['href']
if URI.parse(href).scheme.nil? && Pathname.new(href).relative?
node.attr['href'] = '/pages/' + href
end
node.attr['href'] = node.attr['href']
end
end
p kramdown.to_html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment