author | Olivier Brunel
<jjk@jjacky.com> 2022-12-29 17:18:35 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2022-12-29 17:18:35 UTC |
parent | 49dfd42e85222793b4f7509ad8182e8b202c46bc |
base.htm | +6 | -0 |
base.md | +26 | -17 |
common.css | +2 | -2 |
light.css | +5 | -5 |
main.c | +60 | -1 |
struct.css | +5 | -1 |
diff --git a/base.htm b/base.htm index da80b72..e696d03 100644 --- a/base.htm +++ b/base.htm @@ -214,6 +214,12 @@ int main(int argc, char **argv) And finally simple notes : <div class="box note"><span>Note</span> <p>This is a note.</p></div> + <p>Box inside a box:</p> + <div class="box note"><span>Note</span> + <p>This is a note.</p> + <div class="box hint"><span>Yep</span><p>That + works.</p></div> + </div> </p> </section> <footer> diff --git a/base.md b/base.md index bb90f09..24e95fc 100644 --- a/base.md +++ b/base.md @@ -38,7 +38,6 @@ We have ^^superscript^^ as well as ,,subscript,, also. Here's some ``typetext stuff`` after which will follow no less than a quote : ->!https://source.lnk > Here it is. I'm a quote. \ > No really, I was said by someone, once. \ > I swear. @@ -132,10 +131,9 @@ about. So... You can use <kbd>Alt</kbd> + <kbd>C</kbd>, <kbd>Space</kbd> or the famous <kbd>any</kbd> key. -!!! INFO: Confession -Okay, this isn't anything from ``qmdoc`` really. -That's just a plain old HTML tag, which we styled nicely. Still. -!!! +! INFO: Confession +! Okay, this isn't anything from ``qmdoc`` really. +! That's just a /plain old HTML tag/, which we styled nicely. Still. ## Buttons @@ -151,22 +149,33 @@ about <kbd>Ctrl</kbd> + <mbl> or similar. A few boxes that can be useful from time to time : \ First, we have hints : -!!! HINT: -Here goes a hint. -!!! + +! HINT: +! Here goes a hint. Then basic informations : -!!! INFO: -Here goes some information. -!!! + +! INFO: +! Here goes some information. The usual warnings : -!!! WARNING: -Here goes a warning. -!!! + +! WARNING: +! Here goes a warning. And finally simple notes : -!!! NOTE: -This is a note. -!!! +! NOTE: +! This is a note. + +And a quote: + +> what? + +One can embed things. +! NOTE: Example +! For example, here's a quote: +! > This is a quote. +! +! ! Attention ! +! ! You can even put box into box. diff --git a/common.css b/common.css index e29baa1..7d0bd4e 100644 --- a/common.css +++ b/common.css @@ -81,10 +81,10 @@ main span.button { padding: 4px; font-size: 90%; } -main div.box :first-child::before { +main div.box > :first-child::before { content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAApUlEQVQ4y82TwQnDMAxFpVJyLPiSbbJETr13Fo+RZZxLRghkgnSEEni9ONS0sg1tDv3wwfjbX7Iki/wVAAd4IPBCiHuudrkHVvJYgb50eaOO7cMkpv0eeQGukYuRiUsNvBFpSvTJ0P2un0Sk+6Le3WEG58yBFrjt61r7Qqbij0gLIX3CaPgOqtqoaiMig6GPtTbOwCVyLraxMEj3yPIgHTLKv3ymJySzt16bW/sWAAAAAElFTkSuQmCC); } -main div.box :first-child { +main div.box > :first-child { font-weight: 700; } main footer { diff --git a/light.css b/light.css index 6dd85e6..9db05b2 100644 --- a/light.css +++ b/light.css @@ -58,31 +58,31 @@ main span.button { border: 1px solid #555; background-image: linear-gradient(#fff 0%,#fff 1%,#f2f2f2 1%,#ebebeb 50%,#ddd 50%,#cfcfcf 99%,#fff 99%,#fff 100%); } -main div.box :first-child { +main div.box > :first-child { color: #eee; } main div.box.hint { background: #91ffad; } -main div.box.hint :first-child { +main div.box.hint > :first-child { background: #24ae2d; } main div.box.info { background: #71e1fb; } -main div.box.info :first-child { +main div.box.info > :first-child { background: #217ed0; } main div.box.warn { background: #fdbf91; } -main div.box.warn :first-child { +main div.box.warn > :first-child { background: #df5b5b; } main div.box.note { background: #c4bfb0; } -main div.box.note :first-child { +main div.box.note > :first-child { background: #5c5353; } main footer { diff --git a/main.c b/main.c index 1be3d29..e014a06 100644 --- a/main.c +++ b/main.c @@ -255,6 +255,38 @@ attribute(struct ctx *ctx, MD_ATTRIBUTE *attr) return 1; } +static struct { + const char *type; + const char *class; + const char *title; +} box_types[] = { + { "WARNING", "warn", "Warning" }, + { "INFO", "info", "Information" }, + { "HINT", "hint", "Hint" }, + { "NOTE", "note", "Note" } +}; + +static int +attribute_box_type(MD_ATTRIBUTE *attr) +{ + int n_types = sizeof(box_types) / sizeof(box_types[0]); + + const char *text = attr->text; + MD_SIZE l = attr->substr_offsets[1] - attr->substr_offsets[0]; + + /* if not TEXT_NORMAL or empty, use default */ + if (attr->substr_types[0] != MD_TEXT_NORMAL || l == 0 || (l != 4 && l != 7)) + return 0; + + for (int i = 0; i < n_types; ++i) { + if (!memcmp(text, box_types[i].type, l)) + return i; + } + + /* unknown type, use default */ + return 0; +} + static int enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) @@ -333,6 +365,27 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_) return ERR_PARSER_ENTER_BLOCK; break; + case MD_BLOCK_BOX: + ; + MD_BLOCK_BOX_DETAIL *d = details; + int idx = attribute_box_type(&d->type); + + if (!raw_str(ctx, "<div class=\"box ") + || !raw_str(ctx, box_types[idx].class) + || !raw_str(ctx, "\"><span>")) + return ERR_PARSER_ENTER_BLOCK; + + if (d->title.substr_offsets[0] + d->title.substr_offsets[1] == 0) { + if (!raw_str(ctx, box_types[idx].title)) + return ERR_PARSER_ENTER_BLOCK; + } else { + if (!attribute(ctx, &d->title)) + return ERR_PARSER_ENTER_BLOCK; + } + if (!raw_str(ctx, "</span>")) + return ERR_PARSER_ENTER_BLOCK; + break; + case MD_BLOCK_UL: if (!raw_str(ctx, "<ul>")) return ERR_PARSER_ENTER_BLOCK; @@ -484,6 +537,11 @@ leave_block(MD_BLOCKTYPE type, void *details, void *ctx_) return ERR_PARSER_LEAVE_BLOCK; break; + case MD_BLOCK_BOX: + if (!raw_str(ctx, "</div>")) + return ERR_PARSER_LEAVE_BLOCK; + break; + case MD_BLOCK_UL: if (!raw_str(ctx, "</ul>")) return ERR_PARSER_LEAVE_BLOCK; @@ -816,7 +874,8 @@ convert_page(struct ctx *ctx, int fddest) const MD_PARSER parser = { .flags = MD_FLAG_COLLAPSEWHITESPACE | MD_FLAG_PERMISSIVEAUTOLINKS - | MD_FLAG_NOHTMLBLOCKS | MD_FLAG_STRIKETHROUGH | MD_FLAG_UNDERLINE, + | MD_FLAG_NOHTMLBLOCKS | MD_FLAG_STRIKETHROUGH | MD_FLAG_UNDERLINE + | MD_FLAG_ITALIC | MD_FLAG_BOLD | MD_FLAG_BOX, .enter_block = enter_block, .leave_block = leave_block, .enter_span = enter_span, diff --git a/struct.css b/struct.css index 2a1edd3..a69ab2c 100644 --- a/struct.css +++ b/struct.css @@ -175,7 +175,7 @@ main div.box { padding: 0px; line-height: 15px; } -main div.box :first-child { +main div.box > :first-child { display: block; margin: 0px; padding: 4px; @@ -183,6 +183,10 @@ main div.box :first-child { main div.box p { margin: 4px 11px; } +main div.box div.box { + width: 90%; + margin: auto; +} main footer { padding: 8px 23px; margin: 0 -23px;