Module: Moxml::Adapter::Leptris::Markers
- Included in:
- Moxml::Adapter::Leptris
- Defined in:
- lib/moxml/adapter/leptris/markers.rb
Instance Method Summary collapse
-
#entity_bearing?(native) ⇒ Boolean
Marker presence is a document-level fact: parse records it, the ER builder path flips it, and the split/restore scans consult it.
-
#split_entity_markers(natives, parent) ⇒ Object
Expand marker-bearing text nodes into the child sequence the moxml contract exposes: text, EntityReference, text, ...
Instance Method Details
#entity_bearing?(native) ⇒ Boolean
Marker presence is a document-level fact: parse records it, the ER builder path flips it, and the split/restore scans consult it. Customized natives only exist as split products of marker-bearing text, so they always report true.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/moxml/adapter/leptris/markers.rb', line 11 def entity_bearing?(native) case native when CustomizedLeptris::Declaration, CustomizedLeptris::Doctype, CustomizedLeptris::EntityReference, CustomizedLeptris::TextSegment, CustomizedLeptris::DocumentPI true else doc = native.document doc.nil? || .get(doc, :entity_markers) != false end end |
#split_entity_markers(natives, parent) ⇒ Object
Expand marker-bearing text nodes into the child sequence the moxml contract exposes: text, EntityReference, text, ...
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/moxml/adapter/leptris/markers.rb', line 25 def split_entity_markers(natives, parent) result = [] natives.each do |child| # FFI Text#content returns a fresh unfrozen BINARY string: # retag in place (dup would be a throwaway allocation), but # before include? — BINARY.include? with the UTF-8 marker raises if child.is_a?(::Leptris::XML::Text) content = child.content content.force_encoding("UTF-8") end if content&.include?(Entity::MARKER) content.scan(/([^#{Entity::MARKER}]*)(?:#{Entity::MARKER}([\w.:-]+);)?/o) do text_part = Regexp.last_match(1) name = Regexp.last_match(2) result << CustomizedLeptris::TextSegment.new(text_part, parent) unless text_part.empty? result << CustomizedLeptris::EntityReference.new(name) if name end else result << child end end result end |