Class: PointBlank::Parsing::HyperlinkInline Abstract

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

Overview

This class is abstract.

Hyperreference inline superclass

Direct Known Subclasses

ImageInline, LinkInline

Class Method Summary collapse

Methods inherited from NullInline

build, check_contents, check_unescaped, construct_literal, construct_text, find_unescaped, forward_walk, iterate_tokens, tokenize

Class Method Details

.build_w_linkinfo(capture, doc) ⇒ ::PointBlank::DOM::DOMObject

Build object and apply link info to it

Parameters:

Returns:



1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/mmmd/blankshell.rb', line 1236

def self.build_w_linkinfo(capture, doc)
  linkinfo = capture[-1][2]
  obj = build(capture[1..-2])
  if linkinfo[:label]
    if (props = doc.root.properties[:linkdefs][linkinfo[:label]])
      linkinfo = props
    else
      return nil
    end
  end
  obj.properties = linkinfo
  obj
end

.parse_linkinfo(input) ⇒ Array(<Hash, String, nil>, String)

Parse link properties according to given link suffix

Parameters:

  • input (String)

Returns:

  • (Array(<Hash, String, nil>, String))


1224
1225
1226
1227
1228
1229
1230
# File 'lib/mmmd/blankshell.rb', line 1224

def self.parse_linkinfo(input)
  props, remainder = read_properties(input)
  return nil, "" unless props

  capture = input[..(input.length - remainder.length - 1)]
  [props, capture]
end

.reverse_walk(backlog, doc:) ⇒ Object

TODO: optimize, increase index instead of building buffers (see ::PointBlank::Parsing::NullInline#reverse_walk)



1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
# File 'lib/mmmd/blankshell.rb', line 1252

def self.reverse_walk(backlog, doc:)
  before = []
  capture = []
  open = true
  cls = nil
  backlog.reverse_each do |block|
    (open ? capture : before).prepend(block)
    next unless block.is_a?(Array) && block[1] < self

    open = false
    cls = block[1]
    return backlog unless block[1].check_contents(capture)
  end
  return backlog if open

  block = cls.build_w_linkinfo(capture, doc)
  block ? before + [block] : backlog
end