end
class UrlPlugin < Plugin
- TITLE_RE = /<\s*?title\s*?>(.+?)<\s*?\/title\s*?>/im
LINK_INFO = "[Link Info]"
OUR_UNSAFE = Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}%# ]", false, 'N')
end
def get_title_from_html(pagedata)
- return unless TITLE_RE.match(pagedata)
- $1.ircify_html
+ return pagedata.ircify_html_title
end
def get_title_for_url(uri_str, opts = {})
def riphtml
self.gsub(/<[^>]+>/, '').gsub(/&/,'&').gsub(/"/,'"').gsub(/</,'<').gsub(/>/,'>').gsub(/&ellip;/,'...').gsub(/'/, "'").gsub("\n",'')
end
+
+ # This method tries to find an HTML title in the string,
+ # and returns it if found
+ def get_html_title
+ return unless Irc::Utils::TITLE_REGEX.match(self)
+ $1
+ end
+
+ # This method returns the IRC-formatted version of an
+ # HTML title found in the string
+ def ircify_html_title
+ return unless Irc::Utils::TITLE_REGEX.match(self)
+ $1.ircify_html
+ end
end
else
module ::Irc
module Utils
- # Define some regular expressions to be used by first_html_par
+ # Some regular expressions to manage HTML data
+
+ # Title
+ TITLE_REGEX = /<\s*?title\s*?>(.+?)<\s*?\/title\s*?>/im
# H1, H2, etc
HX_REGEX = /<h(\d)(?:\s+[^>]*)?>(.*?)<\/h\1>/im