Skip to content

Conversation

@jlevy
Copy link
Owner

@jlevy jlevy commented Jan 15, 2026

Summary

  • Add --tags CLI option to control how template tags (Markdoc/Jinja/HTML comments) are handled during line wrapping
  • atomic (default): Tags are never broken across lines
  • wrap: Tags can wrap like normal text (legacy behavior)

Key Changes

Implementation Notes

The implementation uses coalescing-based word splitting for both modes, allowing long tags to wrap at internal whitespace boundaries while keeping tag contents together where possible. Closing tags are placed on their own line when the opening tag spans multiple lines.

Specs:

Test Plan

Automated Testing (Completed)

  • 160 tests pass (make test)
  • Lint passes with 0 errors, 0 warnings (make lint)
  • 26 tag formatting tests in test_tag_formatting.py cover:
    • Quote preservation in tag attributes
    • Multi-line tag handling
    • Paired tag adjacency
    • Closing tag placement
    • Various tag types (Jinja, HTML comments, etc.)
  • Reference doc tests verify full formatting pipeline against comprehensive test document

Manual Validation

  1. CLI Option Verification

    • Check flowmark --help | grep -A2 tags shows new option
    • Test atomic mode (default) with a long tag
    • Test wrap mode explicitly with --tags=wrap
  2. Verify Testdoc Output

    • Spot-check tag formatting around line 1700 in testdoc output
    • Long tags should wrap at internal whitespace
    • Closing tags should be on their own line
  3. Backward Compatibility - Format existing Markdown files with Markdoc tags and verify they format correctly

🤖 Generated with Claude Code

jlevy and others added 4 commits January 14, 2026 20:17
Add a `--tags` CLI option to control how template tags (Markdoc/Jinja/HTML
comments) are handled during line wrapping:

- `atomic` (default): Tags are never broken across lines
- `wrap`: Tags can wrap like normal text (legacy behavior)

Key changes:
- Add `TagWrapping` enum with `atomic` and `wrap` values
- Add `--tags` CLI argument to flowmark command
- Thread `tags` parameter through fill_markdown() and related functions
- Apply multiline tag fix in both modes (Markdoc parser bug workaround)
- Update test_multiline_tag_through_pipeline for correct expectations

The implementation uses coalescing-based word splitting for both modes,
allowing long tags to wrap at internal whitespace boundaries while keeping
tag contents together where possible. Closing tags are placed on their own
line when the opening tag spans multiple lines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
StrEnum was added in Python 3.11. Use the equivalent (str, Enum) base
classes for backward compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add ATOMIC_MAX_TAG_WORDS=128 limit for atomic mode (vs MAX_TAG_WORDS=12 for wrap)
- Add max_words parameter to get_tag_coalescing_patterns()
- Add _merge_paired_tags() to keep opening+closing pairs together after coalescing
- Update test_multiline_tag_through_pipeline to verify atomic vs wrap modes
- Update testdoc expected files to reflect atomic mode as default

With atomic mode (default), template tags virtually never break internally and
paired tags like {% field %}{% /field %} stay on a single line together.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Resolved conflicts in cli.py and reformat_api.py to include both:
- --tags option (atomic/wrap) for tag wrapping control
- --list-spacing option (preserve/loose/tight) for list formatting

Both features are now available and orthogonal.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jlevy
Copy link
Owner Author

jlevy commented Jan 15, 2026

Addresses #13

@jlevy jlevy merged commit 99d5bc1 into main Jan 15, 2026
5 checks passed
@jlevy jlevy deleted the feature/atomic-tag-wrapping branch January 15, 2026 05:21
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.

2 participants