Created
April 21, 2014 14:28
-
-
Save benbasson/11144340 to your computer and use it in GitHub Desktop.
Monkey patch for Kramdown to rewrite relative URLs to absolute URLs
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
require 'uri' | |
# Simple Monkey Patch to convert URLs from relative to absolute | |
# if the option to do so is enabled | |
class Kramdown::Parser::Kramdown | |
alias old_add_link add_link | |
def base_url_as_uri | |
@base_url_as_uri ||= URI.parse(@options[:base_url]) | |
end | |
def add_link(el, href, title, alt_text = nil) | |
if @options[:absolute_urls] and URI.parse(href).relative? | |
href = base_url_as_uri.merge(href).to_s | |
end | |
old_add_link(el, href, title, alt_text) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment