Skip to content

Instantly share code, notes, and snippets.

@spp
Created October 9, 2009 16:09
Show Gist options
  • Save spp/206138 to your computer and use it in GitHub Desktop.
Save spp/206138 to your computer and use it in GitHub Desktop.
def self.auto_link_content(content)
# Splits all HTML tags, except <a></a> tags. Keeps <a></a> tags as whole
# so that we don't accidentally link already linked Keywords
word_groups = content.split(/(<a[^>]*>.+?<\/a>|<\/?[^>]*>|[.]|,|['"]+)/i)
word_groups.collect! do |words|
(!words.match(/<\/?[^>]*>|[.]+|,+/) && words.match(/([a-zA-Z]+)/)) ? link_it(words) : words
end
word_groups.join
end
def link_it(words)
# ..
# Write your linker here
# ..
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment