This Python program formats Mojolicious template files to make their structure easily understandable by humans. It properly indents HTML tags, Mojolicious commands, helper commands, and Perl constructs.
The formatter processes Mojolicious template files in several passes:
1.**Embedded Perl Processing**: Extracts and formats embedded Perl code using perltidy
2.**Line-by-Line Processing**: Processes each line based on its type (HTML or Mojolicious command)
3.**Post-Processing**: Handles special cases like multiple closing tags on a single line
4.**Duplicate Tag Cleanup**: Normalizes and removes duplicate closing tags
## Special Features
### Smart HTML Tag Handling
- Non-indenting tags like `<br>`, `<hr>`, `<img>`, etc. don't cause indentation changes
- Minimal indentation for `<span>` and `<p>` tags (half the normal indentation)
- Special handling for lines with multiple closing tags
### Embedded Perl Formatting
The formatter uses perltidy to format embedded Perl code blocks (enclosed in `<%` and `%>` tags). This ensures that your Perl code follows consistent formatting rules.
### Perltidy Output Files
When using the `--perltidy-output-dir` option, the formatter saves both the original and formatted Perl code for each embedded Perl block to separate files:
-`perl_block_N_original.pl`: The original Perl code before formatting
-`perl_block_N_formatted.pl`: The formatted Perl code after perltidy processing
## Example
### Input
```perl
<div>
<%
# This is a test of pure Perl code with minimal indentation
If you encounter issues with perltidy, the formatter will fall back to a simple indentation-based formatter for Perl code. Enable debug logging with the `--debug` flag to see detailed information about the formatting process.