Class: HParser::Inline::Url
- Inherits:
-
Object
- Object
- HParser::Inline::Url
- Includes:
- Html, Collectable
- Defined in:
- lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/hatena.rb,
lib/hparser/inline/url.rb
Constant Summary collapse
- @@url_re =
%r!https?://[A-Za-z0-9~\/._\?\&=\-%#\+:;,\@\'\$\*\!]+!
- @@bracket_url_with_title_re =
%r!\[(#{@@url_re}):title(?:=(.*?))?(:bookmark)?\]!
- @@bracket_url_re =
%r!\[(#{@@url_re})\]!
Constants included from Html
Instance Attribute Summary collapse
-
#bookmark ⇒ Object
readonly
Returns the value of attribute bookmark.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
(also: #to_text, #to_hatena)
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#initialize(url, title = nil, bookmark = false) ⇒ Url
constructor
A new instance of Url.
- #to_html ⇒ Object
- #to_latex ⇒ Object
Methods included from Html
Constructor Details
#initialize(url, title = nil, bookmark = false) ⇒ Url
Returns a new instance of Url.
28 29 30 31 32 |
# File 'lib/hparser/inline/url.rb', line 28 def initialize(url, title=nil, bookmark=false) @url = url @title = title.nil? ? url : title.empty? ? "(undefined)" : title @bookmark = bookmark end |
Instance Attribute Details
#bookmark ⇒ Object (readonly)
Returns the value of attribute bookmark.
14 15 16 |
# File 'lib/hparser/inline/url.rb', line 14 def bookmark @bookmark end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/hparser/inline/url.rb', line 14 def title @title end |
#url ⇒ Object (readonly) Also known as: to_text, to_hatena
Returns the value of attribute url.
14 15 16 |
# File 'lib/hparser/inline/url.rb', line 14 def url @url end |
Class Method Details
.parse(scanner, context = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hparser/inline/url.rb', line 15 def self.parse(scanner, context=nil) if scanner.scan(@@url_re) then Url.new scanner.matched, scanner.matched elsif scanner.scan(@@bracket_url_with_title_re) then title = "" title = scanner[2] if scanner[2] and scanner[2] != ":bookmark" bookmark = (scanner[2] == ":bookmark" || scanner[3] == ":bookmark") Url.new scanner[1], title, bookmark elsif scanner.scan(@@bracket_url_re) Url.new scanner[1] end end |
Instance Method Details
#==(o) ⇒ Object
34 35 36 37 |
# File 'lib/hparser/inline/url.rb', line 34 def ==(o) o and self.class and o.class and @url == o.url and @title == o.title and @bookmark == o.bookmark end |
#to_html ⇒ Object
295 296 297 298 299 300 301 302 303 |
# File 'lib/hparser/html.rb', line 295 def to_html if @bookmark then require 'uri' enc_url = URI.encode(url) bookmark = %( <a href="http://b.hatena.ne.jp/entry/#{enc_url}" class="http-bookmark">) + %(<img src="http://b.hatena.ne.jp/entry/image/#{enc_url}" alt="" class="http-bookmark"></a>) end %(<a href="#{self.url}">#{CGI.escapeHTML(self.title)}</a>#{bookmark}) end |
#to_latex ⇒ Object
236 237 238 |
# File 'lib/hparser/latex.rb', line 236 def to_latex "\\href{#{self.url}/}{#{self.url}}" end |