Skip to content

Commit ba034d7

Browse files
committed
docs: fix walker Container imports and stringify spacing docs
1 parent cdeacdd commit ba034d7

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

docs/Container.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ Container nodes have access to all walker methods for traversing their child nod
8585
- `walkType(type, callback)` - Walk through all nodes of a specific type
8686

8787
```js
88-
import { parse, registerWalkers, Container } from 'postcss-values-parser';
88+
import { Container } from 'postcss';
89+
import { parse, registerWalkers } from 'postcss-values-parser';
8990

9091
registerWalkers(Container);
9192

docs/Parser.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ console.log(func.isColor); // true
187187
### Complex Value Parsing
188188

189189
```js
190-
import { Container, parse, registerWalkers } from 'postcss-values-parser';
190+
import { Container } from 'postcss';
191+
import { parse, registerWalkers } from 'postcss-values-parser';
191192

192193
// Walker helpers are not auto-registered in v7
193194
registerWalkers(Container);

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ PostCSS provides a means to walk the entire AST to examine nodes of a particular
5757
Walker methods are not registered by default. Call `registerWalkers(Container)` once before using them. Each walker function has a signature of `walk{Node}s` (plural). For example, to walk all numeric values:
5858
5959
```js
60-
import { Container, parse, registerWalkers } from 'postcss-values-parser';
60+
import { Container } from 'postcss';
61+
import { parse, registerWalkers } from 'postcss-values-parser';
6162
6263
// enable walker helpers
6364
registerWalkers(Container);

docs/Root.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ The Root node has access to all walker methods for traversing the AST. These met
8787
- `walkType(type, callback)` - Walk through all nodes of a specific type
8888

8989
```js
90-
import { parse, registerWalkers, Container } from 'postcss-values-parser';
90+
import { Container } from 'postcss';
91+
import { parse, registerWalkers } from 'postcss-values-parser';
9192

9293
registerWalkers(Container);
9394

docs/Stringify.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,19 @@ console.log(root.toString(upperCaseStringifier));
144144

145145
## Advanced Usage
146146

147-
### Preserving Formatting
147+
### Default Spacing Normalization
148148

149-
The stringify function can preserve original formatting and spacing when nodes maintain source mapping information:
149+
The default stringify behavior normalizes spacing and does not preserve the original whitespace from the input:
150150

151151
```js
152152
import { parse } from 'postcss-values-parser';
153153

154-
const root = parse('calc( 100px + 20% )'); // Note the extra spaces
155-
console.log(root.toString()); // Preserves original spacing
154+
const root = parse('calc( 1 + 2 )'); // Note the extra spaces
155+
console.log(root.toString()); // 'calc(1 + 2)'
156156
```
157157

158+
If you need custom whitespace/formatting output, pass a custom stringifier to `toString()`.
159+
158160
### Handling Source Maps
159161

160162
When nodes have source mapping information, the stringify function can utilize this information to maintain accurate positioning:

docs/Walker.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ The walker helpers provide methods to traverse the AST and find nodes of specifi
77
Walker methods are registered using the `registerWalkers` function:
88

99
```js
10-
import { registerWalkers, Container } from 'postcss-values-parser';
10+
import { Container } from 'postcss';
11+
import { registerWalkers } from 'postcss-values-parser';
1112

1213
// Register all walker methods on the Container prototype
1314
registerWalkers(Container);
@@ -181,6 +182,7 @@ Type: `String`<br>
181182
_Required_
182183

183184
The type of nodes to walk through. This should match the `type` property of the nodes you want to visit. Valid types include:
185+
184186
- `'word'` - Word nodes
185187
- `'numeric'` - Numeric nodes
186188
- `'func'` - Function nodes
@@ -225,20 +227,21 @@ All walker methods accept a callback function with the following signature:
225227
function callback(node, index) {
226228
// node: The current node being visited
227229
// index: The index of this node type (0-based)
228-
230+
229231
// Return false to stop walking
230232
if (someCondition) {
231233
return false;
232234
}
233-
235+
234236
// Continue walking by returning nothing or true
235237
}
236238
```
237239

238240
## Example Usage
239241

240242
```js
241-
import { parse, registerWalkers, Container } from 'postcss-values-parser';
243+
import { Container } from 'postcss';
244+
import { parse, registerWalkers } from 'postcss-values-parser';
242245

243246
registerWalkers(Container);
244247

@@ -255,7 +258,7 @@ console.log(numerics); // Array of numeric nodes
255258
// Find all functions
256259
root.walkFuncs((node) => {
257260
console.log(`Found function: ${node.name}`);
258-
261+
259262
// Walk through function parameters
260263
node.walkWords((word) => {
261264
console.log(` Parameter: ${word.value}`);
@@ -265,7 +268,7 @@ root.walkFuncs((node) => {
265268
// Stop walking early
266269
root.walkWords((node, index) => {
267270
console.log(`Word ${index}: ${node.value}`);
268-
271+
269272
// Stop after finding 3 words
270273
if (index >= 2) {
271274
return false;

0 commit comments

Comments
 (0)