Skip to content

Commit 6773f75

Browse files
authored
Added is_fragment parameter to the LexborHTMLParser constructor
1 parent aebe505 commit 6773f75

File tree

5 files changed

+530
-59
lines changed

5 files changed

+530
-59
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ clean-test: ## remove test and coverage artifacts
4949
lint: ## check style with ruff
5050
ruff format selectolax tests
5151
ruff check --fix selectolax tests
52+
cython-lint selectolax/
5253
mypy selectolax tests
5354

5455
test: ## run tests quickly with the default Python

selectolax/lexbor.pxd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ cdef extern from "lexbor/html/html.h" nogil:
219219

220220
# Functions
221221
lxb_html_document_t * lxb_html_document_create()
222-
lxb_status_t lxb_html_document_parse(lxb_html_document_t *document, const lxb_char_t *html, size_t size)
222+
lxb_html_element_t * lxb_html_document_create_element(lxb_html_document_t *document,
223+
const lxb_char_t *local_name, size_t lname_len,
224+
void *reserved_for_opt)
225+
lxb_status_t lxb_html_document_parse(lxb_html_document_t *document, const lxb_char_t *html, size_t size)
226+
lxb_dom_node_t * lxb_html_document_parse_fragment(lxb_html_document_t *document,
227+
lxb_dom_element_t *element,
228+
const lxb_char_t *html,
229+
size_t size)
223230
lxb_html_body_element_t * lxb_html_document_body_element_noi(lxb_html_document_t *document)
224231
lxb_html_head_element_t * lxb_html_document_head_element_noi(lxb_html_document_t *document)
225232
lxb_dom_element_t * lxb_dom_document_element(lxb_dom_document_t *document)
@@ -254,9 +261,13 @@ cdef class LexborCSSSelector:
254261

255262
cdef class LexborHTMLParser:
256263
cdef lxb_html_document_t *document
264+
cdef bint _is_fragment
257265
cdef public bytes raw_html
258266
cdef LexborCSSSelector _selector
259-
cdef int _parse_html(self, char* html, size_t html_len) except -1
267+
cdef inline void _new_html_document(self)
268+
cdef inline lxb_status_t _parse_html_document(self, char *html, size_t html_len) nogil
269+
cdef inline lxb_status_t _parse_html_fragment(self, char *html, size_t html_len) nogil
270+
cdef int _parse_html(self, char *html, size_t html_len) except -1
260271
cdef object cached_script_texts
261272
cdef object cached_script_srcs
262273

@@ -304,6 +315,7 @@ cdef extern from "lexbor/dom/dom.h" nogil:
304315
void lxb_dom_node_remove(lxb_dom_node_t *node)
305316
void * lxb_dom_document_destroy_text_noi(lxb_dom_document_t *document, lxb_char_t *text)
306317
lxb_dom_node_t * lxb_dom_document_root(lxb_dom_document_t *document)
318+
lxb_dom_element_t * lxb_dom_interface_element(lxb_dom_node_t *node)
307319
lxb_char_t * lxb_dom_element_qualified_name(lxb_dom_element_t *element, size_t *len)
308320
lxb_dom_node_t * lxb_dom_node_destroy(lxb_dom_node_t *node)
309321
lxb_dom_node_t * lxb_dom_node_destroy_deep(lxb_dom_node_t *root)

0 commit comments

Comments
 (0)