Module: RbbCode::URLTagNode

Includes:
Attributes
Defined in:
lib/rbbcode/node_extensions.rb

Overview

You won’t find this module in the .treetop file. Instead, it’s effectively a specialization of TagNode, which calls to ImgTagNode when processing an img tag. (However, one of the child nodes used here, :url, is indeed defined in the .treetop file.)

Instance Method Summary collapse

Methods included from Attributes

#strip_quotes

Instance Method Details

#url_to_htmlObject



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rbbcode/node_extensions.rb', line 153

def url_to_html
  # The :url child node (defined in the .treetop file) may or may not exist,
  # depending on how the link is formatted in the BBCode source.
  if respond_to?(:url) and respond_to?(:text)
    # This is a URL tag formatted like [url=http://example.com]Example[/url].
    '<a href="' + strip_quotes(url.text_value) + '">' + text.text_value + '</a>'
  else
    # This is a URL tag formatted like [url]http://example.com[/url].
    '<a href="' + inner_bbcode + '">' + inner_bbcode + '</a>'
  end
end

#url_to_markdownObject



165
166
167
168
169
170
171
172
173
# File 'lib/rbbcode/node_extensions.rb', line 165

def url_to_markdown
  if respond_to?(:url) and respond_to?(:text)
    # This is a URL tag formatted like [url=http://example.com]Example[/url].
    '[' + text.text_value + '](' + strip_quotes(url.text_value) + ')'
  else
    # This is a URL tag formatted like [url]http://example.com[/url].
    '[' + inner_bbcode + '](' + inner_bbcode + ')'
  end
end