From c64c81b599143785ddc067ee9ea5dc76c92d5723 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 27 Apr 2026 00:58:47 -0400 Subject: [PATCH] Can now position the image in any cell. --- assets/layouts.json | 12 +++- sample/about-bezos.md | 7 +++ src/md_parser.cpp | 135 +++++++++++++++++++++++------------------- src/md_parser.rl | 10 +++- src/slides_ui.cpp | 4 +- 5 files changed, 104 insertions(+), 64 deletions(-) diff --git a/assets/layouts.json b/assets/layouts.json index fe70220..9bd4f2c 100644 --- a/assets/layouts.json +++ b/assets/layouts.json @@ -12,7 +12,17 @@ "default_slide": [ "[=*%(300,200)title|_|_|_|_]", "[_|_|_]", - "[*%(300,600)content|_|_|*%(200,600)alt|_]", + "[*%(300,600)content|_|_|*%(200,600)image|_]", + "[_|_|_|_|_]", + "[_|_|_|_|_]", + "[_|_|_|_|_]", + "[_|_|_|_|_]", + "[_|_|_|_|_]" + ], + "image_left": [ + "[=*%(300,200)title|_|_|_|_]", + "[_|_|_]", + "[*%(200,600)image|_|*%(300,600)content|_|_]", "[_|_|_|_|_]", "[_|_|_|_|_]", "[_|_|_|_|_]", diff --git a/sample/about-bezos.md b/sample/about-bezos.md index 1ad05e0..9157c61 100644 --- a/sample/about-bezos.md +++ b/sample/about-bezos.md @@ -65,6 +65,13 @@ One Word * Text will go over image * Image will stretch to fill --- +{"layout": "image_left"} +# Specific Positions +![image](assets/sample_bg.jpg) +* !(assets/sample_bg.jpg) +* Text will go over image +* Image will stretch to fill +--- # Hot Reload * It watches the file and reloads when it changes diff --git a/src/md_parser.cpp b/src/md_parser.cpp index 35149df..0c60073 100644 --- a/src/md_parser.cpp +++ b/src/md_parser.cpp @@ -12,7 +12,7 @@ enum { }; -#line 93 "..//src/md_parser.rl" +#line 101 "..//src/md_parser.rl" @@ -20,20 +20,20 @@ enum { static const char _Parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, - 7, 1, 8, 1, 9, 2, 0, 4, - 2, 0, 8, 2, 4, 0, 2, 5, - 8, 2, 8, 0, 3, 0, 4, 8, - 3, 4, 0, 8, 3, 5, 0, 8, - 3, 5, 8, 0, 4, 5, 0, 4, - 8 + 7, 1, 8, 1, 9, 1, 10, 2, + 0, 4, 2, 0, 9, 2, 4, 0, + 2, 5, 9, 2, 9, 0, 3, 0, + 4, 9, 3, 4, 0, 9, 3, 5, + 0, 9, 3, 5, 9, 0, 4, 5, + 0, 4, 9 }; static const char _Parser_key_offsets[] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 29, 33, 37, - 47, 48, 48, 49, 51, 54, 58, 62, - 65, 67, 69, 70, 74, 78, 88, 89, - 90, 99 + 47, 49, 49, 50, 52, 56, 61, 62, + 65, 69, 73, 76, 78, 80, 81, 85, + 89, 99, 100, 101, 110 }; static const char _Parser_trans_keys[] = { @@ -43,38 +43,39 @@ static const char _Parser_trans_keys[] = { 45, 123, 125, 9, 13, 10, 32, 9, 13, 10, 32, 9, 13, 10, 32, 33, 35, 42, 45, 123, 125, 9, 13, 40, - 41, 10, 41, 32, 9, 13, 10, 32, - 9, 13, 10, 32, 9, 13, 32, 9, - 13, 10, 45, 10, 45, 10, 10, 32, - 9, 13, 10, 32, 9, 13, 10, 32, - 33, 35, 42, 45, 123, 125, 9, 13, - 125, 125, 10, 32, 33, 35, 42, 123, - 125, 9, 13, 10, 32, 33, 35, 42, - 123, 125, 9, 13, 0 + 91, 41, 10, 41, 65, 90, 97, 122, + 93, 65, 90, 97, 122, 40, 32, 9, + 13, 10, 32, 9, 13, 10, 32, 9, + 13, 32, 9, 13, 10, 45, 10, 45, + 10, 10, 32, 9, 13, 10, 32, 9, + 13, 10, 32, 33, 35, 42, 45, 123, + 125, 9, 13, 125, 125, 10, 32, 33, + 35, 42, 123, 125, 9, 13, 10, 32, + 33, 35, 42, 123, 125, 9, 13, 0 }; static const char _Parser_single_lengths[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 7, 1, 1, 8, 2, 2, 8, - 1, 0, 1, 2, 1, 2, 2, 1, - 2, 2, 1, 2, 2, 8, 1, 1, - 7, 7 + 2, 0, 1, 2, 0, 1, 1, 1, + 2, 2, 1, 2, 2, 1, 2, 2, + 8, 1, 1, 7, 7 }; static const char _Parser_range_lengths[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 0, 1, 1, 1, 1, - 0, 0, 0, 1, 1, 1, 0, 0, - 1, 1 + 0, 0, 0, 0, 2, 2, 0, 1, + 1, 1, 1, 0, 0, 0, 1, 1, + 1, 0, 0, 1, 1 }; static const unsigned char _Parser_index_offsets[] = { 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 25, 27, 29, 39, 43, 47, - 57, 59, 60, 62, 65, 68, 72, 76, - 79, 82, 85, 87, 91, 95, 105, 107, - 109, 118 + 57, 60, 61, 63, 66, 69, 73, 75, + 78, 82, 86, 89, 92, 95, 97, 101, + 105, 115, 117, 119, 128 }; static const char _Parser_indicies[] = { @@ -85,45 +86,49 @@ static const char _Parser_indicies[] = { 23, 24, 25, 1, 1, 20, 19, 27, 26, 26, 16, 27, 28, 28, 17, 29, 20, 22, 23, 24, 25, 1, 1, 20, - 19, 30, 1, 31, 33, 32, 34, 33, - 32, 35, 35, 1, 38, 37, 37, 36, - 18, 37, 37, 36, 39, 39, 1, 1, - 40, 16, 18, 41, 17, 42, 1, 44, - 43, 43, 16, 44, 45, 45, 17, 46, - 10, 12, 13, 14, 47, 1, 1, 10, - 9, 1, 48, 49, 48, 52, 51, 53, - 54, 55, 1, 1, 51, 50, 11, 10, - 12, 13, 14, 15, 1, 10, 9, 0 + 19, 30, 31, 1, 32, 34, 33, 35, + 34, 33, 36, 36, 1, 38, 37, 37, + 1, 30, 1, 39, 39, 1, 42, 41, + 41, 40, 18, 41, 41, 40, 43, 43, + 1, 1, 44, 16, 18, 45, 17, 46, + 1, 48, 47, 47, 16, 48, 49, 49, + 17, 50, 10, 12, 13, 14, 51, 1, + 1, 10, 9, 1, 52, 53, 52, 56, + 55, 57, 58, 59, 1, 1, 55, 54, + 11, 10, 12, 13, 14, 15, 1, 10, + 9, 0 }; static const char _Parser_trans_targs[] = { 2, 0, 3, 4, 5, 6, 7, 8, - 9, 10, 27, 29, 16, 20, 23, 30, - 11, 11, 12, 10, 13, 15, 16, 20, - 23, 24, 14, 15, 14, 15, 17, 18, - 18, 19, 12, 21, 11, 22, 21, 21, - 25, 26, 33, 28, 29, 28, 29, 24, - 31, 32, 10, 27, 29, 16, 20, 23 + 9, 10, 30, 32, 16, 23, 26, 33, + 11, 11, 12, 10, 13, 15, 16, 23, + 26, 27, 14, 15, 14, 15, 17, 20, + 18, 18, 19, 12, 21, 21, 22, 24, + 11, 25, 24, 24, 28, 29, 36, 31, + 32, 31, 32, 27, 34, 35, 10, 30, + 32, 16, 23, 26 }; static const char _Parser_trans_actions[] = { 1, 0, 0, 0, 11, 0, 0, 0, - 15, 33, 24, 36, 17, 17, 17, 1, - 5, 0, 9, 1, 1, 21, 0, 0, - 0, 1, 5, 9, 0, 27, 0, 1, - 0, 13, 0, 3, 1, 1, 0, 7, - 5, 0, 19, 5, 9, 0, 40, 33, - 0, 0, 48, 44, 52, 30, 30, 30 + 17, 35, 26, 38, 19, 19, 19, 1, + 5, 0, 9, 1, 1, 23, 0, 0, + 0, 1, 5, 9, 0, 29, 0, 0, + 1, 0, 15, 0, 1, 0, 13, 3, + 1, 1, 0, 7, 5, 0, 21, 5, + 9, 0, 42, 35, 0, 0, 50, 46, + 54, 32, 32, 32 }; static const int Parser_start = 1; -static const int Parser_first_final = 33; +static const int Parser_first_final = 36; static const int Parser_error = 0; static const int Parser_en_main = 1; -#line 96 "..//src/md_parser.rl" +#line 104 "..//src/md_parser.rl" bool Parser::parse(const std::string& input) { @@ -139,14 +144,14 @@ bool Parser::parse(const std::string& input) { last = DECK; -#line 134 "..//src/md_parser.cpp" +#line 139 "..//src/md_parser.cpp" { cs = Parser_start; } -#line 111 "..//src/md_parser.rl" +#line 119 "..//src/md_parser.rl" -#line 137 "..//src/md_parser.cpp" +#line 142 "..//src/md_parser.cpp" { int _klen; unsigned int _trans; @@ -272,34 +277,42 @@ _match: case 6: #line 50 "..//src/md_parser.rl" { + std::string cell = input.substr(start - begin, p - start); + fmt::println("CELL {}", cell); + config["image_cell"] = cell; + } + break; + case 7: +#line 56 "..//src/md_parser.rl" + { std::string image = input.substr(start - begin, p - start); fmt::println("IMAGE image={}, start={}, length={}", image, start - begin, p - start); config["image"] = image; } break; - case 7: -#line 57 "..//src/md_parser.rl" + case 8: +#line 63 "..//src/md_parser.rl" { last = PLAIN; fmt::println("----- START"); } break; - case 8: -#line 62 "..//src/md_parser.rl" + case 9: +#line 68 "..//src/md_parser.rl" { title.clear(); content.clear(); } break; - case 9: -#line 67 "..//src/md_parser.rl" + case 10: +#line 73 "..//src/md_parser.rl" { deck->slides.emplace_back(title, content, config, deck->config); config.clear(); } break; -#line 279 "..//src/md_parser.cpp" +#line 291 "..//src/md_parser.cpp" } } @@ -312,7 +325,7 @@ _again: _out: {} } -#line 112 "..//src/md_parser.rl" +#line 120 "..//src/md_parser.rl" bool good = pe - p == 0; diff --git a/src/md_parser.rl b/src/md_parser.rl index 1ac088d..639d021 100644 --- a/src/md_parser.rl +++ b/src/md_parser.rl @@ -47,6 +47,12 @@ enum { } } + action cell { + std::string cell = input.substr(start - begin, fpc - start); + fmt::println("CELL {}", cell); + config["image_cell"] = cell; + } + action image { std::string image = input.substr(start - begin, fpc - start); fmt::println("IMAGE image={}, start={}, length={}", @@ -75,12 +81,14 @@ enum { pound = '#' %title; asterisk = '*' %enum; bang = '!'; + at = '@'; dash = '-' %enum; json = ('{'|'}'); other = ^(bang|pound|asterisk|eol|json) %plain; content = (any+ -- eol) >mark %content; - image = bang '(' (any+) >mark %image ')' :>> eol; + cell = '[' (alpha+) >mark %cell ']'; + image = bang cell? '(' (any+) >mark %image ')' :>> eol; meta = ('{' ( any+ -- '}') '}') >mark %meta; title = pound space+ content :>> eol; enum = asterisk space+ content :>> eol; diff --git a/src/slides_ui.cpp b/src/slides_ui.cpp index a0e2563..a9ec238 100644 --- a/src/slides_ui.cpp +++ b/src/slides_ui.cpp @@ -40,7 +40,9 @@ void Slide::init(lel::Cell& cell, const std::string& layout) { $gui.set(content, $content_font); if($config.contains("image")) { - $gui.set(content, {$config["image"]}); + std::string image_name = $config["image"]; + auto at_cell = $config.contains("image_cell") ? $gui.entity($config["image_cell"]) : content; + $gui.set(at_cell, {image_name}); } $gui.init();