Skip to content

Conversation

@jlevy
Copy link
Owner

@jlevy jlevy commented Jan 15, 2026

Summary

  • Fixes a bug where smart quotes were incorrectly converting quotes inside template tags
  • Adds TEMPLATE_TAG_PATTERN to tag_handling.py for centralized template tag matching
  • Modifies smart_quotes() to protect content inside template tags from conversion
  • Adds comprehensive test suite with 22 new tests

Bug Details

When arrays or objects spanned multiple lines inside Markdoc/Jinja tags, quotes at the start of continuation lines were being converted to smart quotes. For example:

{% field examples=["red",
"blue"] %}

The "blue" was being converted to "blue" (curly quotes), breaking the template syntax.

Changes

  1. tag_handling.py: Add TEMPLATE_TAG_PATTERN regex to match complete template tags ({% %}, {# #}, {{ }}, <!-- -->) including multiline tags

  2. smartquotes.py: Refactor to split text into protected (inside tags) and unprotected (outside tags) segments, applying smart quote conversion only to prose text

  3. test_tag_formatting.py: New test file with 22 tests covering:

    • 12 edge case scenarios for multiline tags with arrays/objects/various formatting
    • Smart quotes protection for all tag types
    • Prose quotes still being converted correctly
    • Regression tests for the specific bugs found

Test plan

  • All 156 tests pass
  • make lint passes with no warnings
  • Smart quotes in prose text still converted correctly
  • Quotes inside {% %}, {# #}, {{ }}, and <!-- --> tags preserved
  • Multiline tags with arrays/objects handled correctly

🤖 Generated with Claude Code

jlevy and others added 2 commits January 14, 2026 17:16
This fixes a bug where smart quotes were incorrectly converting quotes inside
template tags like {% field kind="string" %} and {{ variable }}. The fix:

1. Add TEMPLATE_TAG_PATTERN to tag_handling.py for matching complete template
   tags (Jinja, Markdoc, HTML comments) that can span multiple lines.

2. Modify smart_quotes() to split text into protected (inside tags) and
   unprotected (outside tags) segments, applying quote conversion only to
   unprotected segments.

3. Add comprehensive test suite in test_tag_formatting.py covering:
   - 12 edge case scenarios for multiline tags with arrays/objects
   - Smart quotes protection for all tag types
   - Prose quotes still being converted correctly
   - Regression tests for the specific bugs found

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jlevy jlevy merged commit 9b30914 into main Jan 15, 2026
5 checks passed
@jlevy jlevy deleted the feature/tag-formatting-edge-cases branch January 15, 2026 01:19
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