Class: PointBlank::Parsing::AutolinkInline
- Inherits:
-
NullInline
- Object
- NullInline
- PointBlank::Parsing::AutolinkInline
- Defined in:
- lib/mmmd/blankshell.rb
Overview
Autolink inline parser
Class Method Summary collapse
-
.forward_walk(parts) ⇒ Object
TODO: optimize, buffer only after walking (see ::PointBlank::Parsing::NullInline#forward_walk.
- .tokenize(string) ⇒ Object
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
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 |
# File 'lib/mmmd/blankshell.rb', line 1200 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) ⇒ Object
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 |
# File 'lib/mmmd/blankshell.rb', line 1184 def self.tokenize(string) 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 |