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, doc = nil) ⇒ 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, doc = nil) ⇒ 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. doc is the binding document when the wrapper could resolve it through its parent chain; the C climb is the fallback.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moxml/adapter/leptris/markers.rb', line 13 def entity_bearing?(native, doc = nil) if NATIVE_READ_LAYER && native.is_a?(::Leptris::XML::NativeNode) doc ||= doc_for(native) return false if doc.nil? return .get(doc, :entity_markers) != false end case native when CustomizedLeptris::Declaration, CustomizedLeptris::Doctype, CustomizedLeptris::EntityReference, CustomizedLeptris::TextSegment, CustomizedLeptris::DocumentPI true else # Parentless elements come only from Iterparse — # engine parsed, outside the marker pipeline: never # bearing. doc = native.document doc.nil? ? false : .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, ...
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/moxml/adapter/leptris/markers.rb', line 37 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 |