@@ -11,6 +11,10 @@ ctypedef fused str_or_LexborNode:
1111 bytes
1212 LexborNode
1313
14+ ctypedef fused str_or_bytes:
15+ str
16+ bytes
17+
1418cdef inline bytes to_bytes(str_or_LexborNode value):
1519 cdef bytes bytes_val
1620 if isinstance (value, unicode ):
@@ -889,6 +893,48 @@ cdef class LexborNode:
889893 container.append(py_text)
890894 return container.text
891895
896+ @property
897+ def inner_html (self ):
898+ """ Return HTML representation of the child nodes.
899+
900+ Works similar to innerHTML in JavaScript.
901+ Unlike `.html` propery, does not inlcude current node.
902+ Can be used to set HTML as well. See the setter docstring.
903+
904+ Returns
905+ -------
906+ text : str
907+ """
908+
909+ cdef lexbor_str_t * lxb_str
910+ cdef lxb_status_t status
911+
912+ lxb_str = lexbor_str_create()
913+ status = lxb_html_serialize_deep_str(self .node, lxb_str)
914+ if status == 0 and lxb_str.data:
915+ html = lxb_str.data.decode(_ENCODING).replace(' <-undef>' , ' ' )
916+ lexbor_str_destroy(lxb_str, self .node.owner_document.text, True )
917+ return html
918+
919+ @inner_html.setter
920+ def inner_html (self , str html ):
921+ """ Set inner HTML to the specified HTML.
922+
923+ Replaces existing data inside the node.
924+ Works similar to innerHTML in JavaScript.
925+
926+ Parameters
927+ ----------
928+ html : str
929+
930+ """
931+ cdef bytes bytes_val
932+ bytes_val = < bytes> html.encode(" utf-8" )
933+ lxb_html_element_inner_html_set(
934+ < lxb_html_element_t * > self .node,
935+ < lxb_char_t * > bytes_val, len (bytes_val)
936+ )
937+
892938
893939@cython.internal
894940@cython.final
0 commit comments