class Qwik::InlineParser
Constants
- INLINE_PATTERNS
- URL
Public Class Methods
make_tree(line_ar)
click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 17 def self.make_tree(line_ar) root = [] stack = [] stack << root in_tag = {} line_ar.each {|t| if t.is_a?(Symbol) if in_tag[t] in_tag[t] = nil if stack.last.length == 1 # bad hack stack.last << '' end stack.pop if 1 < stack.length else in_tag[t] = true ar = [INLINE_PATTERNS[t]] stack.last << ar stack << ar end else if t.is_a? Array elem = t.first case elem when :ref stack.last << parse_ref(t[1]) when :plugin stack.last << parse_plugin(t) when :url stack.last << [:a, {:href=>t[1]}, t[1]] else # do nothing end else stack.last << t end end } # bad hack if stack.last.length == 1 && stack.last.is_a?(Array) && stack.last.first.is_a?(Symbol) stack.last << '' end return root end
parse_plugin(t)
click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 67 def self.parse_plugin(t) method = t[1].to_s param = t[2].to_s data = t[3].to_s return [:br] if method == 'br' # shortcut return [:plugin, {:method=>method, :param=>param}, data] end
parse_ref(uri)
click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 75 def self.parse_ref(uri) text, uri = $1, $2 if /\A([^|]*)\|(.+)\z/ =~ uri if text.nil? or text.empty? text = uri end case uri when /\A#{URL}/o if /\.(?:jpg|jpeg|png|gif)\z/i =~ uri [:img, {:src=>uri, :alt=>text}] else [:a, {:href=>uri}, text] end when /\A(.+?):(.+)\z/ [:plugin, {:method=>'interwiki', :param=>uri}, text] else uri = "#{uri}.html" unless uri.include?('.') [:a, {:href=>uri}, text] end end