Skip to content

Commit 50ce946

Browse files
committed
Initial work fixing #201
1 parent 4ef5272 commit 50ce946

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

selectolax/lexbor.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ cdef class LexborHTMLParser:
279279

280280
@staticmethod
281281
cdef LexborHTMLParser from_document(lxb_html_document_t * document, bytes raw_html)
282-
282+
cdef inline lxb_html_document_t* main_document(self)
283283

284284
cdef extern from "lexbor/dom/dom.h" nogil:
285285
ctypedef enum lexbor_action_t:

selectolax/lexbor.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ cdef class LexborHTMLParser:
5555
self._parse_html(bytes_html, html_len)
5656
self.raw_html = bytes_html
5757

58+
cdef inline lxb_html_document_t* main_document(self):
59+
if self._is_fragment:
60+
return self._original_document
61+
else:
62+
return self.document
63+
5864
cdef inline void _new_html_document(self):
5965
"""Initialize a fresh Lexbor HTML document.
6066

selectolax/lexbor/node.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ cdef class LexborNode:
819819
if isinstance(value, (str, bytes, unicode)):
820820
bytes_val = to_bytes(value)
821821
new_node = <lxb_dom_node_t *> lxb_dom_document_create_text_node(
822-
&self.parser.document.dom_document,
822+
&self.parser.main_document().dom_document,
823823
<lxb_char_t *> bytes_val, len(bytes_val)
824824
)
825825
if new_node == NULL:

0 commit comments

Comments
 (0)