Skip to content

Implement rule P1 in bidi.py as split_into_paragraphs - #13

Merged
isaranga merged 1 commit into
mainfrom
implement-p1
Nov 24, 2026
Merged

isaranga merged 1 commit into
mainfrom
implement-p1

Conversation

@isaranga

@isaranga isaranga commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Moves the paragraph splitter from demo.py into the P rules section of bidi.py as split_into_paragraphs, the function for UAX #9 rule P1. It replaces the comment that said P1 was not implemented.
  • apply_bidi_algorithm still handles one paragraph and returns the same four values; its docstring now says to split longer text with P1 first.
  • The demo runs P1 on every text, built-in examples included, so demo.py again holds no algorithm logic.
  • New built-in example 7, "Two paragraphs (P1)" ("שלום\nHello"): the first paragraph resolves to RTL (level 1) and the second to LTR (level 0).
  • README.md and CLAUDE.md updated to match.

Testing

  • tests/run_bidi_tests.py: 91,707 passed, 0 failed
  • tests/run_bidi_type_tests.py: 770,241 passed, 0 failed
  • python bidi.py --all --brief runs every example
  • The conformance files never put a paragraph separator mid-text, so they don't test P1. Checked by hand: CR LF, lone CR, U+2029, a trailing separator, and empty text.

Move the paragraph splitter from demo.py into the P rules section of
bidi.py, where it sits next to P2-P3. apply_bidi_algorithm still handles
one paragraph. The demo now splits built-in examples as well as user
text, and a new example shows two paragraphs getting different
directions. README.md and CLAUDE.md are updated to match.
@isaranga
isaranga merged commit 2a7fc20 into main Nov 24, 2026
6 checks passed
@isaranga
isaranga deleted the implement-p1 branch November 24, 2026 09:33
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