Created
October 9, 2009 16:09
-
-
Save spp/206138 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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