Commit 1b2e874
authored
feat: Aiming for Cooklang feature completenes (#15)
* feat: implement note blocks per Cooklang spec proposal
Add support for note blocks using the > syntax at start of lines.
Notes are supplementary information that appears in recipe details
but not during cooking mode.
Syntax:
> This is a single-line note.
> This is a multi-line note
> that continues on multiple lines.
Implementation:
- Add NOTE token type to token/token.go
- Implement readNote() in lexer to handle > at start of line
- Add Note struct with StepComponent interface methods
- Update parser to handle NOTE tokens (creates separate step)
- Update ToCooklangRecipe to convert note components
- Update HTML and Markdown renderers to render notes as blockquotes
- Add comprehensive tests for note lexing
Per spec proposal: https://github.com/cooklang/spec/blob/main/proposals/0005-note-blocks.md
* test: add comprehensive tests for comments, sections, and notes
- Add lexer tests for single-line comments (-- comment)
- Add parser tests for notes (TestNoteParsing, TestMultipleNotes, TestNoteWithSections)
- Fix parser to handle NOTE tokens after newlines (was falling through to default case)
This ensures notes work correctly when appearing after section headers
or other block-level elements.
* feat: add canonical_extensions.yaml spec tests for block comments, sections, and notes
Add comprehensive YAML test spec file covering:
- Block comments [- comment -]
- Sections (= Section Name =)
- Notes (> note text)
- Combined extended features
These tests document the current parser behavior for extended
Cooklang syntax features from the official spec's Advanced section.
* feat: implement fixed quantities for ingredients (=prefix)
- Add Fixed field to Component struct (parser) and Ingredient struct
- Update parseQuantityAndUnit to detect leading '=' and set isFixed flag
- Update ToCooklangRecipe to propagate Fixed field to Ingredient
- Update Ingredient.Render() to output '=' prefix for fixed quantities
- Add spec tests for fixed quantities in canonical_extensions.yaml
- Fix flaky example test by sorting ingredients for deterministic output
Fixed quantities (e.g., @salt{=1%tsp}) indicate amounts that should not
scale when adjusting recipe servings, as documented in the Cooklang spec.
* test: add unit tests for token package
- TestLookupIdent: verify keyword lookup for @, #, ~ and fallback to IDENT
- TestTokenType: ensure all token type constants are unique and non-empty
- TestToken: basic struct instantiation test1 parent 937d2b1 commit 1b2e874
12 files changed
Lines changed: 961 additions & 18 deletions
File tree
- lexer
- parser
- renderers
- spec
- token
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | | - | |
| 225 | + | |
225 | 226 | | |
226 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
227 | 232 | | |
228 | | - | |
| 233 | + | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
| |||
349 | 354 | | |
350 | 355 | | |
351 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
352 | 368 | | |
353 | 369 | | |
354 | 370 | | |
355 | 371 | | |
356 | 372 | | |
357 | 373 | | |
| 374 | + | |
358 | 375 | | |
359 | 376 | | |
360 | 377 | | |
361 | 378 | | |
| 379 | + | |
362 | 380 | | |
363 | 381 | | |
364 | 382 | | |
| |||
445 | 463 | | |
446 | 464 | | |
447 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
448 | 480 | | |
449 | 481 | | |
450 | 482 | | |
| |||
721 | 753 | | |
722 | 754 | | |
723 | 755 | | |
| 756 | + | |
724 | 757 | | |
725 | 758 | | |
726 | 759 | | |
| |||
759 | 792 | | |
760 | 793 | | |
761 | 794 | | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
762 | 799 | | |
763 | 800 | | |
764 | 801 | | |
| |||
1044 | 1081 | | |
1045 | 1082 | | |
1046 | 1083 | | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1047 | 1093 | | |
1048 | 1094 | | |
1049 | 1095 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
221 | 226 | | |
222 | 227 | | |
223 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
89 | 96 | | |
90 | 97 | | |
91 | 98 | | |
| |||
460 | 467 | | |
461 | 468 | | |
462 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
0 commit comments