Skip to content

Improve repo: fix code block ignoring and div tag parsing in rtl linter with tests - #13487

Open
vansh917917 wants to merge 1 commit into
EbookFoundation:mainfrom
vansh917917:fix-rtl-linter-parsing
Open

vansh917917 wants to merge 1 commit into
EbookFoundation:mainfrom
vansh917917:fix-rtl-linter-parsing

Conversation

@vansh917917

Copy link
Copy Markdown

What does this PR do?

Improve repo

IMPORTANT

  • Read our contributing guidelines.
  • Is this a revision of a previously submitted PR? If so, STOP! Go back, reopen the PR, and add commit(s) the branch you previously submitted. Please don't make the job of reviewing more difficult by hiding previous work.

Description

Fixes two issues in scripts/rtl_ltr_linter.py and adds an automated test suite:

  1. Code Fence State Parsing: Previously, the script only matched and skipped the code fence line itself (if CODE_FENCE_START.match(line): continue). Lines inside fenced blocks (``` or ~~~) were still evaluated as markdown list items, producing false-positive warnings on documentation files with code examples (e.g. docs/CONTRIBUTING-it.md). The linter now tracks in_code_block state and skips lines inside code fences.
  2. <div> Stack Synchronization: The previous tag matching could pop direction context prematurely when encountering non-directional divs (such as <div align="center">) or fail to match tags with uppercase characters or single-quoted attributes (markdown='1'). Directional context tracking is now robust against nested plain and directional tags.
  3. Resource Management: Uses a context manager (with open(...)) for file reads.
  4. Unit Tests: Added 12 unit tests in scripts/test_rtl_ltr_linter.py covering filename checks, span splitting, config overrides, code block ignoring, and div handling.

Verification

  • Ran python -m unittest discover -s scripts -v (12/12 passed).
  • Verified against docs/CONTRIBUTING-it.md: false positives reduced from 5 to 0.
  • Ran against the full repository without regressions.

Checklist:

  • Used an informative name for this pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant