Mojo-PrettyTidy
view release on metacpan or search on metacpan
Attribute continuation lines are indented more deeply than nested child
content so that attributes do not visually collide with child elements.
Quoted attribute values containing HTML-like fragments are protected from
early tag-splitting rules. For example, tooltip content such as:
data-bs-title="<b>Regex:</b><code><%= $regex %></code>"
is treated as an attribute value, not as real template structure.
=head1 COLUMN-AWARE FORMATTING
C<--columns>, also available as C<--cols> or C<-c>, sets a target width for
conservative width-aware formatting. The default is C<80>. Use
C<--no-columns> or C<--no-cols> to disable column-aware formatting.
Column-aware formatting is not a generic hard-wrap engine.
The first supported behavior is conservative formatting of long
C<style="..."> attributes. Style declarations are split only on CSS
declaration boundaries, using semicolons as legal break points. The formatter
packs declarations into lines near the configured column target while
preserving declaration order.
The formatter intentionally does not wrap arbitrary quoted values such as:
=over 4
=item * SVG path C<d="..."> data
=item * C<href="...">
=item * C<src="...">
=item * C<srcset="...">
=item * C<data-*="..."> payloads
=item * event handlers such as C<onclick="...">
=item * Embedded Perl expressions
=item * prose or text payloads
=back
=head1 TEXT PAYLOADS
Text payloads are treated carefully because source whitespace can affect
rendered output.
Paragraph-like text payload blocks should preserve their inline content,
including inline tags such as C<a>, C<b>, C<i>, and inline C<code>, unless a
specific structural rule applies.
The formatter avoids treating prose as a generic wrapping target. Editor or
terminal line wrapping is preferred for long prose until an explicit safe rule
is added.
=head1 EMBEDDED PERL FORMATTING
C<Mojo::PrettyTidy> uses C<perltidy> for Embedded Perl/code regions where
possible. If C<$HOME/.perltidyrc> exists, it is passed to C<perltidy>, so
your normal Perl indentation preferences are inherited.
PrettyTidy still overrides a small number of C<perltidy> settings where needed
for template formatting. In particular, it sets a very large line length
(C<-l=9999>) so C<perltidy> does not make wrapping decisions. Width-aware
template expansion is handled by PrettyTidy itself, for example through
C<--cols>.
PrettyTidy also runs C<perltidy> through standard input/output in quiet mode
and currently uses C<-nbbc> to avoid introducing blank lines before comments.
=head1 JAVASCRIPT HANDLING
C<Mojo::PrettyTidy> contains a conservative JavaScript handler for inline
C<script> blocks in Mojolicious C<.html.ep> templates.
The goal is not for C<Mojo::PrettyTidy> itself to become a JavaScript
formatter. Instead, JavaScript is treated as a language island inside the
template.
The handler attempts to:
=over 4
=item 1
detect inline C<script> ... C</script> blocks
=item 2
separate the script block cleanly from surrounding EP/HTML
=item 3
format the JavaScript body with C<JavaScript::Beautifier>
=item 4
repair a small set of known modern-JavaScript token splits
=item 5
verify that known dangerous munges did not survive
=item 6
reinsert the script body into the template
=back
External scripts such as:
<script src="/app.js"></script>
are not JavaScript-formatted because there is no inline body to format.
=head2 JavaScript::Beautifier
( run in 2.828 seconds using v1.01-cache-2.11-cpan-0b58ddf2af1 )