From a1caec25a97bfd5e8750dfc2b40aa6469b0769ba Mon Sep 17 00:00:00 2001 From: Bhavishya <69957211+Bhavishya2912@users.noreply.github.com> Date: Thu, 16 Oct 2025 07:44:18 +0530 Subject: [PATCH] Fix: scripts- Incorrect
Tag Handling logic (#12429) * Fix: scripts- Incorrect
Tag Handling logic * added comments for
tags handling logic Co-authored-by: Gabriele Ciccotelli --------- Co-authored-by: Gabriele Ciccotelli --- scripts/rtl_ltr_linter.py | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/scripts/rtl_ltr_linter.py b/scripts/rtl_ltr_linter.py index 70e52a798..8c990c971 100644 --- a/scripts/rtl_ltr_linter.py +++ b/scripts/rtl_ltr_linter.py @@ -247,21 +247,23 @@ def lint_file(path, cfg): # Skip lines that start a code block (```) if CODE_FENCE_START.match(line): continue - # Check for block-level directionality changes (e.g.,
) - m_div_open = HTML_DIR_ATTR_RE.search(line) - - # If an opening
tag is found - if m_div_open and 'markdown="1"' in line: - new_div_ctx = m_div_open.group(2).lower() # Extract the new directionality context from the opening div tag - block_context_stack.append(new_div_ctx) # Push the new directionality context onto the stack - continue # Continue to the next line of the file - - # If a closing
tag is found and we are inside a div context - # (i.e., the stack has more than just the base file_direction_ctx) - if '
' in line and len(block_context_stack) > 1: - block_context_stack.pop() # Pop the last directionality context from the stack - continue # Continue to the next line of the file - + # Find all opening and closing
tags on the line to handle cases + # where there can be multiple
opening and closing on the same line + div_tags = re.findall(r"(]*dir=['\"](rtl|ltr)['\"][^>]*>|
)", line, re.IGNORECASE) + + # Process each found tag in order to correctly update the context stack + for tag_tuple in div_tags: + # re.findall with multiple capture groups returns a list of tuples: + # tag: The full matched tag (e.g., '' or '
') + # direction: The captured direction ('rtl' or 'ltr'), or empty for a closing tag + tag, direction = tag_tuple + + # If it's an opening tag with 'markdown="1"', push the new context + if tag.startswith('' and len(block_context_stack) > 1: + block_context_stack.pop() # Check if the line is a Markdown list item list_item = LIST_ITEM_RE.match(line) @@ -388,11 +390,17 @@ def lint_file(path, cfg): issues.append( f"::{sev['pure_ltr'].lower()} file={path},line={idx}::Pure LTR text '{s}' in {part} of RTL context may need trailing '‏' marker." ) + + # Check for unclosed div tags at the end of the file + if len(block_context_stack) > 1: + issues.append( + f"::error file={path},line={len(lines)}::Found unclosed
tag. " + f"The final block context is '{block_context_stack[-1]}', not the file's base '{file_direction_ctx}'." + ) # Return the list of found issues return issues - def get_changed_lines_for_file(filepath): """ Returns a set of line numbers (1-based) that were changed in the given file in the current PR.