probably proper compatibility
This commit is contained in:
parent
af93de6f4d
commit
7b8590b9c6
|
@ -114,7 +114,6 @@ module PointBlank
|
||||||
def read_properties(text)
|
def read_properties(text)
|
||||||
properties = {}
|
properties = {}
|
||||||
remaining = text
|
remaining = text
|
||||||
warn text.inspect
|
|
||||||
if text.start_with? '[' # link label
|
if text.start_with? '[' # link label
|
||||||
properties[:label], remaining = read_return_label(remaining)
|
properties[:label], remaining = read_return_label(remaining)
|
||||||
close_bracket = false
|
close_bracket = false
|
||||||
|
@ -258,6 +257,7 @@ module PointBlank
|
||||||
newblock = switchclass.new
|
newblock = switchclass.new
|
||||||
newblock.content = block.content
|
newblock.content = block.content
|
||||||
newblock.parser = nil
|
newblock.parser = nil
|
||||||
|
newblock.parent = block.parent
|
||||||
block.parent[block.position] = newblock
|
block.parent[block.position] = newblock
|
||||||
newblock
|
newblock
|
||||||
end
|
end
|
||||||
|
@ -342,8 +342,8 @@ module PointBlank
|
||||||
def consume(line, parent = nil, lazy: false)
|
def consume(line, parent = nil, lazy: false)
|
||||||
@lazy_triggered = lazy || @lazy_triggered
|
@lazy_triggered = lazy || @lazy_triggered
|
||||||
return [nil, nil] if line.match?(/\A {0,3}\Z/)
|
return [nil, nil] if line.match?(/\A {0,3}\Z/)
|
||||||
return [nil, nil] if check_candidates(line, parent)
|
|
||||||
return [nil, nil] if @closed
|
return [nil, nil] if @closed
|
||||||
|
return [nil, nil] if check_candidates(line, parent)
|
||||||
|
|
||||||
push(line)
|
push(line)
|
||||||
["", nil]
|
["", nil]
|
||||||
|
@ -365,6 +365,13 @@ module PointBlank
|
||||||
other = classes.filter do |cls|
|
other = classes.filter do |cls|
|
||||||
!(once ||= (cls == ::PointBlank::DOM::Paragraph))
|
!(once ||= (cls == ::PointBlank::DOM::Paragraph))
|
||||||
end
|
end
|
||||||
|
underlines_match = ::PointBlank::DOM::Paragraph.valid_children.any? do |x|
|
||||||
|
x.parser.begin?(line)
|
||||||
|
end
|
||||||
|
if underlines_match && !@lazy_triggered
|
||||||
|
@closed = true
|
||||||
|
return false
|
||||||
|
end
|
||||||
other.any? do |x|
|
other.any? do |x|
|
||||||
x.parser.begin? line
|
x.parser.begin? line
|
||||||
end
|
end
|
||||||
|
@ -879,7 +886,8 @@ module PointBlank
|
||||||
obj = ::PointBlank::DOM::Text.new
|
obj = ::PointBlank::DOM::Text.new
|
||||||
string = string.gsub(/\\([!"\#$%&'()*+,\-.\/:;<=>?@\[\\\]\^_`{|}~])/,
|
string = string.gsub(/\\([!"\#$%&'()*+,\-.\/:;<=>?@\[\\\]\^_`{|}~])/,
|
||||||
'\\1')
|
'\\1')
|
||||||
obj.content = string.strip
|
string = string.gsub("\n", " ")
|
||||||
|
obj.content = string
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -924,7 +932,7 @@ module PointBlank
|
||||||
next unless part.last == :close
|
next unless part.last == :close
|
||||||
next unless part[1].respond_to?(:reverse_walk)
|
next unless part[1].respond_to?(:reverse_walk)
|
||||||
|
|
||||||
backlog = part[1].reverse_walk(backlog)
|
backlog = part[1].reverse_walk(backlog, doc: @doc)
|
||||||
end
|
end
|
||||||
backlog
|
backlog
|
||||||
end
|
end
|
||||||
|
@ -1041,6 +1049,7 @@ module PointBlank
|
||||||
obj = ::PointBlank::DOM::Text.new
|
obj = ::PointBlank::DOM::Text.new
|
||||||
string = string.gsub(/\\([!"\#$%&'()*+,\-.\/:;<=>?@\[\\\]\^_`{|}~])/,
|
string = string.gsub(/\\([!"\#$%&'()*+,\-.\/:;<=>?@\[\\\]\^_`{|}~])/,
|
||||||
'\\1')
|
'\\1')
|
||||||
|
string = string.gsub("\n", " ")
|
||||||
obj.content = string
|
obj.content = string
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
@ -1159,17 +1168,25 @@ module PointBlank
|
||||||
|
|
||||||
# Build object and apply link info to it
|
# Build object and apply link info to it
|
||||||
# @param capture [Array<String, Array(String, Class, Symbol)>]
|
# @param capture [Array<String, Array(String, Class, Symbol)>]
|
||||||
|
# @param doc [::PointBlank::DOM::DOMObject]
|
||||||
# @return [::PointBlank::DOM::DOMObject]
|
# @return [::PointBlank::DOM::DOMObject]
|
||||||
def self.build_w_linkinfo(capture)
|
def self.build_w_linkinfo(capture, doc)
|
||||||
linkinfo = capture[-1][2]
|
linkinfo = capture[-1][2]
|
||||||
obj = build(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.properties = linkinfo
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: optimize, increase index instead of building buffers
|
# TODO: optimize, increase index instead of building buffers
|
||||||
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
||||||
def self.reverse_walk(backlog)
|
def self.reverse_walk(backlog, doc:)
|
||||||
before = []
|
before = []
|
||||||
capture = []
|
capture = []
|
||||||
open = true
|
open = true
|
||||||
|
@ -1184,7 +1201,8 @@ module PointBlank
|
||||||
end
|
end
|
||||||
return backlog if open
|
return backlog if open
|
||||||
|
|
||||||
before + [cls.build_w_linkinfo(capture)]
|
block = cls.build_w_linkinfo(capture, doc)
|
||||||
|
block ? before + [block] : backlog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1289,7 +1307,7 @@ module PointBlank
|
||||||
end
|
end
|
||||||
|
|
||||||
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
||||||
def self.reverse_walk(backlog)
|
def self.reverse_walk(backlog, **_doc)
|
||||||
until backlog.last.first.empty?
|
until backlog.last.first.empty?
|
||||||
capture = []
|
capture = []
|
||||||
before = []
|
before = []
|
||||||
|
@ -1351,7 +1369,7 @@ module PointBlank
|
||||||
# (see ::PointBlank::Parsing::NullInline#tokenize)
|
# (see ::PointBlank::Parsing::NullInline#tokenize)
|
||||||
def self.tokenize(string)
|
def self.tokenize(string)
|
||||||
iterate_tokens(string, /(?: \n|\\\n)/) do |_before, token, matched|
|
iterate_tokens(string, /(?: \n|\\\n)/) do |_before, token, matched|
|
||||||
next ["\n", self, :close] if token == " \\n"
|
next ["\n", self, :close] if token.start_with?(" \n")
|
||||||
next ["\n", self, :close] if matched
|
next ["\n", self, :close] if matched
|
||||||
|
|
||||||
" "
|
" "
|
||||||
|
@ -1359,7 +1377,7 @@ module PointBlank
|
||||||
end
|
end
|
||||||
|
|
||||||
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
# (see ::PointBlank::Parsing::NullInline#reverse_walk)
|
||||||
def self.reverse_walk(backlog)
|
def self.reverse_walk(backlog, **_doc)
|
||||||
backlog[-1] = build([])
|
backlog[-1] = build([])
|
||||||
backlog
|
backlog
|
||||||
end
|
end
|
||||||
|
@ -1507,6 +1525,14 @@ module PointBlank
|
||||||
@children.dup
|
@children.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get root element containing this child
|
||||||
|
# @return [::PointBlank::DOM::DOMObject]
|
||||||
|
def root
|
||||||
|
current_root = self
|
||||||
|
current_root = current_root.parent while current_root.parent
|
||||||
|
current_root
|
||||||
|
end
|
||||||
|
|
||||||
# Append child
|
# Append child
|
||||||
# @param child [DOMObject]
|
# @param child [DOMObject]
|
||||||
def append_child(child)
|
def append_child(child)
|
||||||
|
@ -1519,14 +1545,9 @@ module PointBlank
|
||||||
@children.append(child)
|
@children.append(child)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Append temp. child
|
# Append temp child
|
||||||
# @param child [DOMObject, String]
|
# @param child [DOMObject]
|
||||||
def append_temp(child)
|
def append_temp_child(child)
|
||||||
unless child.is_a?(::PointBlank::DOM::DOMObject) ||
|
|
||||||
child.is_a?(String)
|
|
||||||
raise DOMError, "invlaid temp class #{child.class}"
|
|
||||||
end
|
|
||||||
|
|
||||||
@temp_children.append(child)
|
@temp_children.append(child)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1547,7 +1568,7 @@ module PointBlank
|
||||||
define_parser ::PointBlank::Parsing::CodeInline
|
define_parser ::PointBlank::Parsing::CodeInline
|
||||||
end
|
end
|
||||||
|
|
||||||
# Linebreak
|
# Hard Linebreak
|
||||||
class InlineBreak < DOMObject
|
class InlineBreak < DOMObject
|
||||||
define_parser ::PointBlank::Parsing::HardBreakInline
|
define_parser ::PointBlank::Parsing::HardBreakInline
|
||||||
end
|
end
|
||||||
|
@ -1628,14 +1649,10 @@ module PointBlank
|
||||||
|
|
||||||
# Leaf block (virtual)
|
# Leaf block (virtual)
|
||||||
class LeafBlock < DOMObject
|
class LeafBlock < DOMObject
|
||||||
# Virtual hook to push inlines in place of leaf blocks
|
# Virtual hook to delay inline processing
|
||||||
def parse_inner
|
def parse_inner
|
||||||
child = ::PointBlank::DOM::InlineRoot.new
|
self.content = content.strip if content
|
||||||
child.content = content
|
root.append_temp_child(self)
|
||||||
scanner = ::PointBlank::Parsing::StackScanner.new(child)
|
|
||||||
scanner.scan
|
|
||||||
self.content = ""
|
|
||||||
child.each { |c| append_child(c) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1651,6 +1668,24 @@ module PointBlank
|
||||||
|
|
||||||
# Document root
|
# Document root
|
||||||
class Document < Block
|
class Document < Block
|
||||||
|
# (see ::PointBlank::DOM::DOMObject#parse)
|
||||||
|
def self.parse(doc)
|
||||||
|
output = super(doc)
|
||||||
|
# This has to be done after the document gets processed due to the way link
|
||||||
|
# definitions have to be handled.
|
||||||
|
parse_inner = lambda do |block|
|
||||||
|
child = ::PointBlank::DOM::InlineRoot.new
|
||||||
|
child.parent = block.parent
|
||||||
|
child.content = block.content
|
||||||
|
scanner = ::PointBlank::Parsing::StackScanner.new(child)
|
||||||
|
scanner.scan
|
||||||
|
block.content = ""
|
||||||
|
child.each { |c| block.append_child(c) }
|
||||||
|
end
|
||||||
|
output.temp_children.each { |block| parse_inner.call(block) }
|
||||||
|
output.temp_children.clear
|
||||||
|
output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Paragraph in a document (separated by 2 newlines)
|
# Paragraph in a document (separated by 2 newlines)
|
||||||
|
@ -1659,14 +1694,10 @@ module PointBlank
|
||||||
define_overlay ::PointBlank::Parsing::ParagraphUnderlineOverlay, 0
|
define_overlay ::PointBlank::Parsing::ParagraphUnderlineOverlay, 0
|
||||||
define_overlay ::PointBlank::Parsing::LinkReferenceOverlay
|
define_overlay ::PointBlank::Parsing::LinkReferenceOverlay
|
||||||
|
|
||||||
# Virtual hook to parse inline contents of a finished paragraph
|
# Virtual hook to delay inline processing
|
||||||
def parse_inner
|
def parse_inner
|
||||||
child = ::PointBlank::DOM::InlineRoot.new
|
self.content = content.strip if content
|
||||||
child.content = content
|
root.append_temp_child(self)
|
||||||
scanner = ::PointBlank::Parsing::StackScanner.new(child)
|
|
||||||
scanner.scan
|
|
||||||
self.content = ""
|
|
||||||
child.each { |c| append_child(c) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue