You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add print-width-aware wrapping and re-flow for inline text content, bump v0.0.32
Use fill() IR instead of concat() for inline content so long lines wrap at word
boundaries respecting print width. Text node source newlines are treated as word
boundaries (re-flow), letting the fill algorithm handle all wrapping. Punctuation
attaches to preceding content.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
// This content exceeds 80 chars so the group breaks
75
+
// This content exceeds 80 chars so the group breaks, and fill wraps at print width
68
76
constresult=format('<p>The answer must be a <i>double-precision</i> {{#complex}}or complex{{/complex}} number.</p>');
69
-
expect(result).toBe('<p>\n The answer must be a <i>double-precision</i> {{#complex}}or complex{{/complex}} number.\n</p>\n');
77
+
expect(result).toBe('<p>\n The answer must be a <i>double-precision</i>\n {{#complex}}or complex{{/complex}} number.\n</p>\n');
70
78
});
71
79
72
-
it('preserves multi-line text content',()=>{
73
-
// Content on multiple lines should stay on multiple lines
80
+
it('reflows multi-line text content',()=>{
81
+
// Source newlines in text are treated as word boundaries; short content stays on one line
74
82
constinput='<p>First line of text.\nSecond line of text.</p>';
75
83
constresult=format(input);
76
-
expect(result).toBe('<p>\n First line of text.\n Second line of text.\n</p>\n');
84
+
expect(result).toBe('<p>First line of text.Second line of text.</p>\n');
77
85
});
78
86
79
87
it('keeps short element with attributes flat',()=>{
@@ -287,15 +295,89 @@ is the number of false options that you select, and <code>n</code> is the total
287
295
At minimum, you will receive a score of 0%.
288
296
{{/net-correct}}`;
289
297
constresult=format(input);
290
-
// Comma stays with </code>, "where" stays with <code>t</code>, etc.
298
+
// Fill wraps at 80 chars; comma stays with </code>, inline elements stay atomic
291
299
expect(result).toBe(
292
300
'{{#net-correct}}\n'+
293
-
' You must select {{{insert_text}}} You will receive a score of <code>100% * (t - f) / n</code>,\n'+
294
-
' where <code>t</code> is the number of true options that you select, <code>f</code> is the number of false options that you select, and <code>n</code> is the total number of true options.\n'+
295
-
' At minimum, you will receive a score of 0%.\n'+
301
+
' You must select {{{insert_text}}} You will receive a score of\n'+
302
+
' <code>100% * (t - f) / n</code>, where <code>t</code> is the number of true\n'+
303
+
' options that you select, <code>f</code> is the number of false options that\n'+
304
+
' you select, and <code>n</code> is the total number of true options. At\n'+
305
+
' minimum, you will receive a score of 0%.\n'+
296
306
'{{/net-correct}}\n'
297
307
);
298
308
});
309
+
310
+
it('wraps at print width 100 with 4-space indent',()=>{
311
+
constinput=`{{#net-correct}}
312
+
You must select {{{insert_text}}} You will receive a score of <code>100% * (t - f) / n</code>,
313
+
where <code>t</code> is the number of true options that you select, <code>f</code>
314
+
is the number of false options that you select, and <code>n</code> is the total number of true options.
' You must select {{{insert_text}}} You will receive a score of <code>100% * (t - f) / n</code>,\n'+
321
+
' where <code>t</code> is the number of true options that you select, <code>f</code> is the number\n'+
322
+
' of false options that you select, and <code>n</code> is the total number of true options. At\n'+
323
+
' minimum, you will receive a score of 0%.\n'+
324
+
'{{/net-correct}}\n'
325
+
);
326
+
});
327
+
328
+
it('keeps short inline content on one line',()=>{
329
+
constinput='<p>Hello <code>world</code> and more.</p>';
330
+
constresult=format(input);
331
+
expect(result).toBe('<p>Hello <code>world</code> and more.</p>\n');
332
+
});
333
+
334
+
it('wraps long inline text at word boundaries respecting print width',()=>{
335
+
constinput='<p>This is a very long sentence that contains <code>inline code</code> and should wrap at word boundaries when it exceeds the print width limit.</p>';
336
+
constresult=format(input);
337
+
// The group breaks because content exceeds 80 chars, then fill wraps at word boundaries
338
+
expect(result).toBe(
339
+
'<p>\n'+
340
+
' This is a very long sentence that contains <code>inline code</code> and should\n'+
341
+
' wrap at word boundaries when it exceeds the print width limit.\n'+
342
+
'</p>\n'
343
+
);
344
+
});
345
+
346
+
it('wraps at print width 100 with 8-space indent',()=>{
347
+
// 8-space indent comes from nesting: e.g. tabSize=4 at depth 2
348
+
constinput=`<div>
349
+
<div>
350
+
{{#net-correct}}
351
+
You must select {{{insert_text}}} You will receive a score of <code>100% * (t - f) / n</code>,
352
+
where <code>t</code> is the number of true options that you select, <code>f</code>
353
+
is the number of false options that you select, and <code>n</code> is the total number of true options.
0 commit comments