module Infoboxer::Parser::Inline

Public Instance Methods

inline(until_pattern = nil) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 8
def inline(until_pattern = nil)
  start = @context.lineno
  nodes = Nodes[]
  guarded_loop do
    chunk = @context.scan_until(re.inline_until_cache[until_pattern])
    nodes << chunk

    break if @context.matched_inline?(until_pattern)

    nodes << inline_formatting(@context.matched) unless @context.matched.empty?

    if @context.eof?
      break unless until_pattern

      @context.fail!("#{until_pattern.source} not found, starting from #{start}")
    end

    if @context.eol?
      nodes << "\n"
      @context.next!
    end
  end

  nodes
end
long_inline(until_pattern = nil) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 58
def long_inline(until_pattern = nil)
  nodes = Nodes[]
  guarded_loop do
    chunk = @context.scan_until(re.inline_until_cache[until_pattern])
    nodes << chunk

    break if @context.matched?(until_pattern)

    nodes << inline_formatting(@context.matched) unless @context.matched.empty?

    if @context.eof?
      break unless until_pattern

      @context.fail!("#{until_pattern.source} not found")
    end

    if @context.eol?
      @context.next!
      paragraphs(until_pattern).each do |p|
        nodes << p
      end
      break
    end
  end

  nodes
end
short_inline(until_pattern = nil) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 34
def short_inline(until_pattern = nil)
  nodes = Nodes[]
  guarded_loop do
    # FIXME: quick and UGLY IS HELL JUST TRYING TO MAKE THE SHIT WORK
    chunk =
      if @context.inline_eol_sign == /^\]/ # rubocop:disable Style/CaseLikeIf
        @context.scan_until(re.short_inline_until_cache_brackets[until_pattern])
      elsif @context.inline_eol_sign == /^\]\]/
        @context.scan_until(re.short_inline_until_cache_brackets2[until_pattern])
      else
        @context.scan_until(re.short_inline_until_cache[until_pattern])
      end
    nodes << chunk

    break if @context.matched_inline?(until_pattern)

    nodes << inline_formatting(@context.matched)

    break if @context.inline_eol?(until_pattern)
  end

  nodes
end

Private Instance Methods

inline_formatting(match) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 88
def inline_formatting(match) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
  case match
  when "'''''"
    BoldItalic.new(short_inline(/'''''/))
  when "'''"
    Bold.new(short_inline(/'''/))
  when "''"
    Italic.new(short_inline(/''/))
  when '[['
    if @context.check(re.file_namespace)
      image
    else
      wikilink
    end
  when /\[(.+)/
    external_link(Regexp.last_match(1))
  when '{{'
    template
  when /<nowiki([^>]*)>/
    nowiki(Regexp.last_match(1))
  when %r{<ref([^>]*)/>}
    reference(Regexp.last_match(1), true)
  when /<ref([^>]*)>/
    reference(Regexp.last_match(1))
  when /<math>/
    math
  when /<gallery([^>]*)>/
    gallery(Regexp.last_match(1))
  when '<'
    html || Text.new(match) # it was not HTML, just accidental <
  else
    match # FIXME: TEMP
  end
end
math() click to toggle source
# File lib/infoboxer/parser/inline.rb, line 165
def math
  Math.new(@context.scan_continued_until(%r{</math>}))
end
nowiki(tag_rest) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 169
def nowiki(tag_rest)
  if tag_rest.end_with?('/')
    Text.new('')
  else
    Text.new(@context.scan_continued_until(%r{</nowiki>}))
  end
end
reference(param_str, closed = false) click to toggle source
# File lib/infoboxer/parser/inline.rb, line 160
def reference(param_str, closed = false)
  children = closed ? Nodes[] : long_inline(%r{</ref>})
  Ref.new(children, **parse_params(param_str))
end