Repository navigation
Description
What
Support inline formatting in recipe notes: bold, italic and links, as defined by spec proposal 0022 (accepted). Show them in the web UI and cooking mode, and write them in every output format.
> **Make ahead:** the dough keeps *up to 3 days* in the fridge.
> See the [shaping guide](https://example.com/shaping), or [Spinach pie](<./Spinach pie.cook>).Why
Notes are the prose part of a recipe, and people already type Markdown in them (**Gluten-free option:** …). Today the asterisks show as written, and a note can only link a bare URL (through link_urls). The parser now reads the formatting, so CookCLI needs no Markdown library.
Depends on
- feat!: inline formatting in notes (spec proposal 0022) cooklang-rs#170, which isn't released yet.
cooklang::Content::Textchanges fromStringtoNote { items: Vec<TextRun> }, withTextRun { value, strong, emphasis, link: Option<String> }.note.text()(orDisplay) gives the plain text. - A cooklang-reports release for the same cooklang version. It matches
cooklang::Content::Text(value) => Self::Text(value)(model/content.rs:37, and initem.rsandstep.rs), and CookCLI calls it fromcrates/core/src/report.rs:41. cooklang-language-server depends on cooklang too.
What breaks on the upgrade (compile errors)
src/web/builders.rs:791-795:text.trim()→RecipeSectionItem::Note(String)crates/format/src/human.rs:507-532crates/format/src/cooklang_source.rs:138(w_text_block(w, &str)) and the test helper at:516crates/format/src/markdown.rs:449-457,latex.rs:381-385,typst.rs:353-357
src/server/handlers/recipe_image.rs:273 and crates/format/src/schema.rs:425 skip notes and need no change.
Behaviour
Web UI (templates/recipe.html:429-433, RecipeSectionItem::Note at src/web/templates.rs:1064)
RecipeSectionItem::Notecarries the runs, not a string. Renderstrongas<strong>,emphasisas<em>, and consecutive runs with the samelinkas one<a>. Escape every value and destination, aslink_urlsdoes today..recipe-noteis italic (static/css/components.css:612-621), so emphasis must still show, for example by switching back to upright text.- Links, following the proposal's Opening links:
http:,https:andmailto:become<a target="_blank" rel="noopener noreferrer">.- A destination with no scheme that doesn't start with
//is percent-decoded and resolved like a recipe reference. If it names a recipe in the collection (with or without.cook), it links to that recipe's page. A path that leaves the collection (../, absolute) or doesn't resolve shows its text only. - Anything else (
javascript:,data:,file:,//host, empty) shows its text only.
- Keep
link_urlsauto-linking bare URLs in the plain runs (the proposal allows it), but not inside a run that is already a link.
Cooking mode (templates.rs:506-509 emits {"type":"note","text": …}; static/js/cooking-mode.js:79-91, 130-150 noteHTML())
- Cooking mode shows notes, as decided in Cooking mode: show recipe notes as cards of their own #836. The spec leaves this to each application (docs: applications decide whether notes show in cooking mode spec#179), so keep showing them and apply the same formatting there. Send the runs in the JSON and render them in
noteHTML()with the same escaping and link rules as the template.noteHTML()is a JS copy oflink_urls; both copies need the change.
cook recipe -f … (src/recipe/read.rs:209-259)
json/yaml: no code change. The recipe is serialized with serde, and cooklang-rs#170 keeps{"type":"text","value":"<plain text>"}and adds"items": [...]. Add a test that pins this shape.human: bold and italic where the terminal supports them; a link prints as its text followed by the destination in parentheses.markdown: write**,*and[text](destination)yourself.escape_md_line(markdown.rs:577-604) escapes exactly these characters, so escape each run's value and then wrap it.latex/typst:\textbf/\textit/\href, and*…*/_…_/#link. In typst the note is already inside_Note: …_, so nested emphasis needs care. The snapshots attests/snapshots/document_formats_test__latex_output.snap:84andtypst_output.snap:58will change.cooklang(w_text_block,cooklang_source.rs:229-243): write the runs back as**,*and[text](<destination>)(angle brackets when the destination has a space). Escape with\any literal*,_,[,]and\in a value that would otherwise be read as formatting. No such helper exists yet (cooklang'sescape_textis private and covers other characters). Keep a link's text from wrapping across>lines, using thecomponent_word_separatorpattern at:245-298.
API docs
/api/recipes/{path}returnsitemswith no change, sinceApiRecipeflattens the cooklangRecipe. Document a text block insrc/web/api_docs.rs(today it only shows a step) and regeneratedocs/api.md.
To decide
- Whether a note link to a recipe that doesn't resolve shows as text (the proposal's rule) or as a link that 404s. The proposal says text.
- What a path is relative to: the recipe's folder or the collection root. The iOS and Android apps resolve recipe references from the collection root. Pick the same rule as the server's recipe references, and keep the three apps consistent.
Acceptance
- The note above renders with "Make ahead:" bold, "up to 3 days" italic, the shaping guide as an external link and "Spinach pie" linking to its recipe page, both on the recipe page and in cooking mode.
> [x](javascript:alert(1))and> [x](../../etc/passwd)render the text "x" with no link.cook recipe -f cooklangon a note with formatting, escaped asterisks (2\*250 g) and a link with spaces gives a file that parses to the same runs (round-trip test).cook recipe -f jsonincludes"value"(plain) and"items"for each note.
Activity