Class: PointBlank::Parsing::NullInline Abstract
- Inherits:
-
Object
- Object
- PointBlank::Parsing::NullInline
- Defined in:
- lib/mmmd/blankshell.rb
Overview
Null inline scanner element
Direct Known Subclasses
AutolinkInline, CodeInline, EmphInline, HardBreakInline, HyperlinkInline
Class Attribute Summary collapse
-
.parser_for ⇒ Object
Returns the value of attribute parser_for.
Class Method Summary collapse
-
.build(children) ⇒ ::PointBlank::DOM::DOMObject
Build child.
-
.check_contents(elements) ⇒ Boolean
Check that contents can be contained within this element.
-
.check_unescaped(index, string) ⇒ nil, Integer
Check that the symbol at this index is not escaped.
-
.construct_literal(string) ⇒ ::PointBlank::DOM::Text
Construct text literal for a string.
-
.construct_text(string) ⇒ ::PointBlank::DOM::Text
Construct text object for a string.
-
.find_unescaped(string, pattern) ⇒ Integer?
Find the first occurence of an unescaped pattern.
-
.forward_walk(backlog) ⇒ Array<Array(String, Class, Symbol), String>
Forward-walk the backlog starting from the current valid element.
-
.iterate_tokens(string, pattern, &filter) ⇒ Array<String, Array(String, Class, Symbol)>
Iterate over every string/unescaped token part.
-
.reverse_walk(backlog) ⇒ Array<Array(String, Class, Symbol), String>
Reverse-walk the backlog and construct a valid element from it.
-
.tokenize(string, _before, _after) ⇒ Array<Array(String, Class, Symbol), String>
Tokenize a string.
Class Attribute Details
.parser_for ⇒ Object
Returns the value of attribute parser_for.
1011 1012 1013 |
# File 'lib/mmmd/blankshell.rb', line 1011 def parser_for @parser_for end |
Class Method Details
.build(children) ⇒ ::PointBlank::DOM::DOMObject
Build child
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/mmmd/blankshell.rb', line 1090 def self.build(children) obj = parser_for.new if parser_for.valid_children.empty? children.each do |child| child = child.first if child.is_a? Array child = construct_text(child) if child.is_a? String obj.append_child(child) end else tokens = children.map do |child| child.is_a?(Array) ? child.first : child end scanner = StackScanner.new(obj, init_tokens: tokens) scanner.scan end obj end |
.check_contents(elements) ⇒ Boolean
Check that contents can be contained within this element
1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/mmmd/blankshell.rb', line 1133 def self.check_contents(elements) elements.each do |element| next unless element.is_a? ::PointBlank::DOM::DOMObject next if parser_for.valid_children.include? element.class return false end true end |
.check_unescaped(index, string) ⇒ nil, Integer
Check that the symbol at this index is not escaped
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
# File 'lib/mmmd/blankshell.rb', line 1037 def self.check_unescaped(index, string) return index if index.zero? count = 0 index -= 1 while index >= 0 && string[index] == "\\" count += 1 index -= 1 end (count % 2).zero? end |
.construct_literal(string) ⇒ ::PointBlank::DOM::Text
Construct text literal for a string
1124 1125 1126 1127 1128 |
# File 'lib/mmmd/blankshell.rb', line 1124 def self.construct_literal(string) obj = ::PointBlank::DOM::Text.new obj.content = string obj end |
.construct_text(string) ⇒ ::PointBlank::DOM::Text
Construct text object for a string
1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'lib/mmmd/blankshell.rb', line 1111 def self.construct_text(string) obj = ::PointBlank::DOM::Text.new string = string.gsub(/\\([!"\#$%&'()*+,\-.\/:;<=>?@\[\\\]\^_`{|}~])/, '\\1') string = string.gsub("\n", " ") string = MMMD::EntityUtils.decode_entities(string) obj.content = string obj end |
.find_unescaped(string, pattern) ⇒ Integer?
Find the first occurence of an unescaped pattern
1053 1054 1055 1056 1057 1058 1059 1060 1061 |
# File 'lib/mmmd/blankshell.rb', line 1053 def self.find_unescaped(string, pattern) initial = 0 while (index = string.index(pattern, initial)) return index if check_unescaped(index, string) initial = index + 1 end nil end |
.forward_walk(backlog) ⇒ Array<Array(String, Class, Symbol), String>
Forward-walk the backlog starting from the current valid element
|
# File 'lib/mmmd/blankshell.rb', line 1028
|
.iterate_tokens(string, pattern, &filter) ⇒ Array<String, Array(String, Class, Symbol)>
Iterate over every string/unescaped token part
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/mmmd/blankshell.rb', line 1068 def self.iterate_tokens(string, pattern, &filter) tokens = [] initial = 0 while (index = string.index(pattern, initial)) prefix = (index.zero? ? nil : string[initial..(index - 1)]) tokens.append(prefix) if prefix unescaped = check_unescaped(index, string) match = filter.call(index.positive? ? string[..(index - 1)] : "", string[index..], unescaped) tokens.append(match) match = match.first if match.is_a? Array initial = index + match.length end remaining = string[initial..] || "" tokens.append(remaining) unless remaining.empty? tokens end |
.reverse_walk(backlog) ⇒ Array<Array(String, Class, Symbol), String>
Reverse-walk the backlog and construct a valid element from it
|
# File 'lib/mmmd/blankshell.rb', line 1023
|
.tokenize(string, _before, _after) ⇒ Array<Array(String, Class, Symbol), String>
Tokenize a string
1019 1020 1021 |
# File 'lib/mmmd/blankshell.rb', line 1019 def self.tokenize(string, _before, _after) [string] end |