Skip to content

Instantly share code, notes, and snippets.

@manuels
Created October 31, 2011 20:41
Show Gist options
  • Save manuels/1328842 to your computer and use it in GitHub Desktop.
Save manuels/1328842 to your computer and use it in GitHub Desktop.
require 'erb'
module Diaspora
module Markdownify
class HTML < Redcarpet::Render::HTML
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
def initialize(options={})
@options = options
super(options)
end
def autolink(link, type)
link = localize_diaspora_url(link) if @options[:localize_diaspora_urls] and @options[:remote_pod_url]
auto_link(link, :link => :urls, :html => { :target => "_blank" })
end
def link(link, title, content)
super(localize_diaspora_url(link), title, content)
end
def localize_diaspora_url(link)
base_url = "https://#{@options[:remote_pod_url]}/posts/"
if(/^#{base_url}([0-9a-z]*)/.match(link))
guid = $1
return "https://#{AppConfig[:pod_url]}/posts/"+guid if guid.length>8 and Post.exists?(:guid => guid)
end
return link
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment