11"""Handle the <li>, <ol>, <ul> tags."""
2- from typing import Dict
32
43from inscriptis .model .html_document_state import HtmlDocumentState
54
@@ -12,16 +11,14 @@ def get_bullet(state: HtmlDocumentState) -> str:
1211 return UL_COUNTER [len (state .li_counter ) % UL_COUNTER_LEN ]
1312
1413
15- def li_start_handler (state : HtmlDocumentState , tag : Dict ) -> None :
14+ def li_start_handler (state : HtmlDocumentState , tag : dict ) -> None :
1615 """Handle the <li> tag."""
1716 bullet = state .li_counter [- 1 ] if state .li_counter else "* "
18- if tag .get ('value' ):
19- if tag .get ('value' ).isdigit ():
20- bullet = int (tag .get ('value' ))
21- if not state .li_counter :
22- state .li_counter .append (bullet )
23- else :
24- bullet = tag .get ('value' )
17+ # Value can only used for numerical bullets.
18+ if "value" in tag and tag ["value" ].isdigit () and isinstance (bullet , int ):
19+ bullet = int (tag ["value" ])
20+ state .li_counter [- 1 ] = bullet
21+
2522 if isinstance (bullet , int ):
2623 state .li_counter [- 1 ] += 1
2724 state .tags [- 1 ].list_bullet = f"{ bullet } . "
@@ -31,7 +28,7 @@ def li_start_handler(state: HtmlDocumentState, tag: Dict) -> None:
3128 state .tags [- 1 ].write ("" )
3229
3330
34- def ul_start_handler (state : HtmlDocumentState , _ : Dict ) -> None :
31+ def ul_start_handler (state : HtmlDocumentState , _ : dict ) -> None :
3532 """Handle the <ul> tag."""
3633 state .li_counter .append (get_bullet (state ))
3734
@@ -41,7 +38,7 @@ def ul_end_handler(state: HtmlDocumentState) -> None:
4138 state .li_counter .pop ()
4239
4340
44- def ol_start_handler (state : HtmlDocumentState , _ : Dict ) -> None :
41+ def ol_start_handler (state : HtmlDocumentState , _ : dict ) -> None :
4542 """Handle the <ol> tag."""
4643 state .li_counter .append (1 )
4744
0 commit comments