Class: PointBlank::Parsing::AutolinkInline

Inherits:
NullInline
  • Object
show all
Defined in:
lib/mmmd/blankshell.rb

Overview

Autolink inline parser

Class Method Summary collapse

Methods inherited from NullInline

build, check_contents, check_unescaped, construct_literal, construct_text, find_unescaped, iterate_tokens, reverse_walk

Class Method Details

.forward_walk(parts) ⇒ Object

TODO: optimize, buffer only after walking (see ::PointBlank::Parsing::NullInline#forward_walk



1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
# File 'lib/mmmd/blankshell.rb', line 1196

def self.forward_walk(parts)
  buffer = ""
  cutoff = 0
  parts.each_with_index do |part, idx|
    text = (part.is_a?(Array) ? part.first : part)
    buffer += text
    next unless part.is_a? Array

    break (cutoff = idx) if part.first == ">" && part.last == :close
  end
  return '<', parts[1..] unless buffer.match?(/^<[\w\-_+]+:[^<>\s]+>$/)

  obj = build([buffer[1..-2]])
  obj.properties[:uri] = MMMD::EntityUtils.encode_uri(buffer[1..-2])
  [obj, parts[(cutoff + 1)..]]
end

.tokenize(string, *_lookaround) ⇒ Object



1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File 'lib/mmmd/blankshell.rb', line 1180

def self.tokenize(string, *_lookaround)
  iterate_tokens(string, /[<>]/) do |_before, current_text, matched|
    if matched
      if current_text.start_with?("<")
        ["<", self, :open]
      else
        [">", self, :close]
      end
    else
      current_text[0]
    end
  end
end