Conversation
Implement the @? operator for marking ingredients as optional, following
the cooklang-rs extension convention. Optional ingredients are displayed
with '(optional)' suffix in all output formats.
Changes:
- Add OPTIONAL_INGREDIENT token type and lexer support
- Update parser to handle @? and set Optional field on components
- Add Optional bool field to Ingredient struct
- Update Render() and RenderDisplay() methods for optional ingredients
- Add optional ingredient support to HTML, Markdown, and Print renderers
- Add spec tests and parser/lexer unit tests
- Add example Gin_and_Tonic.cook recipe demonstrating optional garnishes
Example usage:
Add @?thyme{2%sprigs} if desired.
Garnish with @?lime wedge{1} or @?lemon wheel{1}.
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.
Summary
@?operator for marking ingredients as optional, following the cooklang-rs extension convention(optional)suffix across all output formats (HTML, Markdown, Print, default display)Changes
Token & Lexer (
token/token.go,lexer/lexer.go)OPTIONAL_INGREDIENT = "@?"token type@?when followed by valid identifier, falls back to ILLEGAL otherwiseParser (
parser/parser.go)Optional boolfield toComponentstruct@and@?tokensCore Types (
cooklang.go)Optional boolfield toIngredientstructRender()to output@?prefix for optional ingredientsRenderDisplay()to append(optional)suffixRenderers
renderers/html.go): AddedoptionalCSS class and(optional)markerrenderers/markdown.go): Added*(optional)*suffix in ingredients list and inlinerenderers/print.go): Added.optionaland.optional-markerCSS, displays(optional)Tests & Examples
@?tokenization (6 test cases)canonical_extensions.yaml(6 test cases)example_recipes/Gin_and_Tonic.cookdemonstrating optional garnishesExample Usage
Output: