Repository navigation
fix(format): stop hard wrapping markdown output - #512
Merged
Merged
Conversation
The Markdown writer ran steps and the description through `textwrap` at `termwidth().min(80)`, which put a line break in the middle of a sentence and made the output depend on the width of the terminal that produced it. The continuation lines also sat at column zero, which ends the ordered list for a CommonMark parser. Emit only the line breaks the recipe itself has, indenting them to the list item's content column. This also fixes the `-` bullets a step can contain, which used to break out of the step they belong to. Fixes #497
|
Review of #512 — stop hard wrapping markdown output Nice, focused fix. Root cause (piping recipe text through Code quality
Potential bugs
Performance
Security
Test coverage
Overall this looks correct, minimal, and well-tested — happy with this as-is; the notes above are non-blocking suggestions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #497.
Problem
The Markdown writer piped steps and the description through
textwrapattermwidth().min(80). Terminal-driven hard wrapping in a file format has three consequences:...San Marzano tomato\nsauce on it...);cook recipe -f markdownis not reproducible — that also made therecipe_markdown_outputsnapshot test width-dependent;Fix
print_wrapped/print_wrapped_with_optionsare replaced bywrite_block(w, text, first, rest), which emits only the line breaks the recipe itself has:"5. "prefixes the first line; any later line is indented to the marker width (" "), the CommonMark content column. This also corrects the-bullets a step can contain, which previously broke out of their list item."> "(blockquote style) or nothing (heading style). The prefix is trimmed off blank lines so no stray trailing whitespace turns into a hard break.seed/Neapolitan Pizza.cookstep 5 now renders as a single line, as the issue asks.Tests
Three new unit tests in
crates/format/src/markdown.rs, written before the fix and watched fail:step_text_is_not_hard_wrappeddescription_is_not_hard_wrappeda_list_inside_a_step_is_indented_under_the_numbersnapshot_test__recipe_markdown_outputis re-recorded; its only diff is the unwrapped step.The
cooklangoutput format wraps the same way, but is left alone: the parser joins soft-wrapped lines back into one step, and a round trip preserves the step count.textwrapis still used by the human and cooklang writers.cargo test,cargo fmt --checkandcargo clippy --all-targetspass cleanly.