@@ -93,6 +93,8 @@ def __init__(self, md: Markdown, *args, **kwargs):
9393
9494 self .lineno_start_cache = [0 ]
9595
96+ self .override_comment_update = False
97+
9698 # This calls self.reset
9799 super ().__init__ (* args , ** kwargs )
98100 self .md = md
@@ -253,8 +255,22 @@ def handle_entityref(self, name: str):
253255 self .handle_empty_tag ('&{};' .format (name ), is_block = False )
254256
255257 def handle_comment (self , data : str ):
258+ # Check if the comment is unclosed, if so, we need to override position
259+ # update
260+ i = self .line_offset + self .offset + len (data ) + 4
261+ if self .rawdata [i :i + 3 ] != '-->' :
262+ self .handle_data ('<!--' )
263+ self .override_comment_update = True
264+ return
256265 self .handle_empty_tag ('<!--{}-->' .format (data ), is_block = True )
257266
267+ def updatepos (self , i : int , j : int ) -> int :
268+ if self .override_comment_update :
269+ self .override_comment_update = False
270+ i = 0
271+ j = 4
272+ return super ().updatepos (i , j )
273+
258274 def handle_decl (self , data : str ):
259275 self .handle_empty_tag ('<!{}>' .format (data ), is_block = True )
260276
0 commit comments