Skip to content

Conversation

@tjbracegirdle
Copy link

Description of the Change

This PR adds comprehensive ExpressionEngine code formatting capabilities to the VS Code extension. The formatter handles EE tags within HTML documents with proper indentation, attribute wrapping, and nested structure support.

Key Features Added:

  • EE tag detection: Brace counting algorithm to identify EE tags including complex nested ones
  • Attribute parsing: State machine to preserve complete attribute assignments like url_override = "homepage"
  • HTML structure parsing: Stack-based approach to maintain proper indentation for HTML within EE tags
  • Context-aware indentation: Calculates appropriate indentation based on surrounding HTML and EE blocks
  • Support for all EE tag types: Handles exp:, if, layout:set, and other EE tag patterns

The formatter integrates with VS Code's document formatting system and respects user configuration for attribute wrapping behavior.

Alternate Designs

  • For EE tag detection: Could have used regex patterns, but brace counting was chosen for reliability with nested braces
  • For attribute parsing: Simple splitting would break quoted values, so state machine tracking was implemented
  • For HTML indentation: Fixed levels were too rigid, so dynamic stack-based parsing was used

Benefits

  • New functionality: Users can now format EE tags into long expanded format
  • Consistent indentation: Maintains proper code structure around EE tags
  • VS Code integration: Works with standard formatting commands
  • Configurable: Respects user preferences for attribute wrapping

Possible Drawbacks

New code to maintain: Additional complexity
Potential edge cases: Complex EE/HTML combinations might be buggy

Applicable Issues

@Opaismoe
Copy link

Awesome, looks promising! thanks @tjbracegirdle

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