forked from publify/publify
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a text filter to turn @mention and #hashtags into links to Twitt…
…er inside short statuses. This is done using the html_postprocess method included in the content model. html_postprocess is applied when views call @content.html(:field) (usually :body). In article / pages it just returns the html, but is used in the feedback model to sanitize user posted HTML. On a more or less related thing, I've just dug into the text filter code for the first time since I took over the project. I've been willing to add Wordpress like pre and post hooks to allow user defined plugins to change the text on the fly. This was actually already implemented into Typo with the preprocess and post process text filters. Currently, the simplest way to do is to add filters params to the existing 4 text filters (none, markdown, textile and markdown + smartypants). I'll come with an elegant way to do it, already have 2-3 ideas about that.
- Loading branch information
Frédéric de Villamil
committed
Aug 2, 2013
1 parent
a3adb8d
commit f60a644
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class PublifyApp | ||
class Textfilter | ||
class Twitterfilter < TextFilterPlugin::PostProcess | ||
plugin_display_name "HTML Filter" | ||
plugin_description 'Strip HTML tags' | ||
|
||
def self.filtertext(blog,content,text,params) | ||
text.to_s.split.grep(/^#\w+/) do |item| | ||
# strip_html because Ruby considers "#prouddad</p>" as a word | ||
uri = URI.escape("https://twitter.com/search?q=#{item.strip_html}&src=tren&mode=realtime") | ||
text = text.to_s.gsub(item, "<a href='#{uri}'>#{item.strip_html}</a>") | ||
end | ||
|
||
text.to_s.split.grep(/@\w+/) do |item| | ||
uri = URI.escape("https://twitter.com/#{item.strip_html.gsub('@', '')}") | ||
text = text.to_s.gsub(item, "<a href='#{uri}'>#{item.strip_html}</a>") | ||
end | ||
return text | ||
end | ||
end | ||
end | ||
end |
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
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