@herb-tools/formatter 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/herb-format.js +623 -145
- package/dist/herb-format.js.map +1 -1
- package/dist/index.cjs +617 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +617 -139
- package/dist/index.esm.js.map +1 -1
- package/dist/types/printer.d.ts +57 -0
- package/package.json +3 -2
- package/src/printer.ts +803 -154
package/dist/types/printer.d.ts
CHANGED
|
@@ -13,11 +13,45 @@ export declare class Printer extends Visitor {
|
|
|
13
13
|
private indentLevel;
|
|
14
14
|
private inlineMode;
|
|
15
15
|
private isInComplexNesting;
|
|
16
|
+
private static readonly INLINE_ELEMENTS;
|
|
16
17
|
constructor(source: string, options: Required<FormatOptions>);
|
|
17
18
|
print(object: Node | Token, indentLevel?: number): string;
|
|
18
19
|
private push;
|
|
19
20
|
private withIndent;
|
|
20
21
|
private indent;
|
|
22
|
+
/**
|
|
23
|
+
* Format ERB content with proper spacing around the inner content.
|
|
24
|
+
* Returns empty string if content is empty, otherwise wraps content with single spaces.
|
|
25
|
+
*/
|
|
26
|
+
private formatERBContent;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a node is an ERB control flow node (if, unless, block, case, while, for)
|
|
29
|
+
*/
|
|
30
|
+
private isERBControlFlow;
|
|
31
|
+
/**
|
|
32
|
+
* Count total attributes including those inside ERB conditionals
|
|
33
|
+
*/
|
|
34
|
+
private getTotalAttributeCount;
|
|
35
|
+
/**
|
|
36
|
+
* Extract HTML attributes from a list of nodes
|
|
37
|
+
*/
|
|
38
|
+
private extractAttributes;
|
|
39
|
+
/**
|
|
40
|
+
* Extract inline nodes (non-attribute, non-whitespace) from a list of nodes
|
|
41
|
+
*/
|
|
42
|
+
private extractInlineNodes;
|
|
43
|
+
/**
|
|
44
|
+
* Render attributes as a space-separated string
|
|
45
|
+
*/
|
|
46
|
+
private renderAttributesString;
|
|
47
|
+
/**
|
|
48
|
+
* Determine if a tag should be rendered inline based on attribute count and other factors
|
|
49
|
+
*/
|
|
50
|
+
private shouldRenderInline;
|
|
51
|
+
/**
|
|
52
|
+
* Render multiline attributes for a tag
|
|
53
|
+
*/
|
|
54
|
+
private renderMultilineAttributes;
|
|
21
55
|
/**
|
|
22
56
|
* Print an ERB tag (<% %> or <%= %>) with single spaces around inner content.
|
|
23
57
|
*/
|
|
@@ -52,13 +86,36 @@ export declare class Printer extends Visitor {
|
|
|
52
86
|
visitERBEnsureNode(node: ERBEnsureNode): void;
|
|
53
87
|
visitERBUnlessNode(node: ERBUnlessNode): void;
|
|
54
88
|
private visitERBGeneric;
|
|
89
|
+
private isNonWhitespaceNode;
|
|
90
|
+
/**
|
|
91
|
+
* Check if an element should be treated as inline based on its tag name
|
|
92
|
+
*/
|
|
93
|
+
private isInlineElement;
|
|
94
|
+
/**
|
|
95
|
+
* Check if we're in a text flow context (parent contains mixed text and inline elements)
|
|
96
|
+
*/
|
|
97
|
+
private visitTextFlowChildren;
|
|
98
|
+
private visitTextFlowChildrenMultiline;
|
|
99
|
+
private isInTextFlowContext;
|
|
55
100
|
private renderInlineOpen;
|
|
56
101
|
renderAttribute(attribute: HTMLAttributeNode): string;
|
|
102
|
+
/**
|
|
103
|
+
* Try to render a complete element inline including opening tag, children, and closing tag
|
|
104
|
+
*/
|
|
105
|
+
private tryRenderInlineFull;
|
|
106
|
+
/**
|
|
107
|
+
* Try to render just the children inline (without tags)
|
|
108
|
+
*/
|
|
109
|
+
private tryRenderChildrenInline;
|
|
57
110
|
/**
|
|
58
111
|
* Try to render children inline if they are simple enough.
|
|
59
112
|
* Returns the inline string if possible, null otherwise.
|
|
60
113
|
*/
|
|
61
114
|
private tryRenderInline;
|
|
115
|
+
/**
|
|
116
|
+
* Estimate the total content length of children nodes for decision making.
|
|
117
|
+
*/
|
|
118
|
+
private estimateContentLength;
|
|
62
119
|
/**
|
|
63
120
|
* Calculate the maximum nesting depth in a subtree of nodes.
|
|
64
121
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/formatter",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "Auto-formatter for HTML+ERB templates with intelligent indentation, line wrapping, and ERB-aware pretty-printing.",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"homepage": "https://herb-tools.dev",
|
|
6
7
|
"bugs": "https://github.com/marcoroth/herb/issues/new?title=Package%20%60@herb-tools/formatter%60:%20",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@herb-tools/core": "0.4.
|
|
38
|
+
"@herb-tools/core": "0.4.3",
|
|
38
39
|
"glob": "^11.0.3"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|