Repository navigation
fix(format): don't split hyphenated words when wrapping cooklang - #735
Conversation
LeMyst
left a comment
There was a problem hiding this comment.
Thanks. This fixes the reported case: the test fails without the change (extra- virgin olive oil) and passes with it, and both wrap sites (cooklang_source.rs:179, :193) are covered. The same corruption still happens in a few nearby cases:
- Other break points.
WordSeparator::new()(:215) follows the Unicode line-break rules, so it still breaks after/, em dash and en dash. A sweep over wrap positions reproduced all three:stir—gently→stir—/gently,foo/bar→foo//bar,1–2 minute→1–/2 minute.WordSeparator::AsciiSpacefor the text between components would only break where the source had a space. - A note detaches from its component. The component regex (
:210) ends at}, and a break is allowed between}and(. So@salt{1%g}(a pinch or two or more)can be written as@salt{1%g}+ newline +(a pinch or two or more), which parses back with the note as plain step text. Adding an optional(\([^)]*\))?to the regex keeps them together. - Long words are cut mid-word.
break_wordsis still on, so a word wider than the wrap width is split at an arbitrary character. The width istermwidth().min(80), so on a narrow terminal ordinary component names hit this..break_words(false)fixes it.
None of these is tested yet, and the > text block path has no test either.
This conflicts with #736 and #737 only where the tests are inserted.
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
9eb3f14 to
5d34035
Compare
|
All three points addressed:
New tests: |
|
Thanks, the behaviour is right now. I checked 5d34035 by sliding each risky token through every column from 0 to 81 and running
1. None of the four new tests fails without its fixI reverted each fix on its own: all 13 tests in the module still passed every time. As a control, putting the hyphen splitter back does make
Moving the token through every column with a prefix ( Optional, the same on
|
The cooklang writer wrapped steps with textwrap's default HyphenSplitter, which breaks "extra-virgin" at the dash — inside a component that reparses as a different ingredient name, and in plain text it adds a space the source never had. Switch both wrap sites to WordSplitter::NoHyphenation. Closes #700
5d34035 to
b4724c2
Compare
|
Good catch — all four tests were checking assertions that held either way. On b4724c2 (rebased on main with #736/#737 in):
Verified by reverting the fix: all five wrap tests now fail (only the hyphen one did before), and all pass again with it. Noted on the component-glue follow-up ( |
|
Thanks, the tests hold up now. I reverted each fix on its own, and each one now makes its test fail:
I also swept This looks good to merge, and the glued-text case can go in its own PR, as you said. Only one nit is left, if you want it: the block's 🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
|
Thanks — I'll take the >78-char word in a |
Closes #700
--format cooklangwrapped steps with textwrap's defaultHyphenSplitter, so@extra-virgin olive oil{1%tbsp}could be emitted as@extra-\nvirgin olive oil{1%tbsp}— reparsing yields the ingredientextra- virgin olive oil, silently changing the name (and plain text likewell-knowngot a space it never had). Both wrap sites now useWordSplitter::NoHyphenation.Test plan
cargo test -p cooklang-formatgreen@extra-virgin olive oil{1%tbsp}whole on the wrapped line