author | Olivier Brunel
<jjk@jjacky.com> 2022-12-31 22:26:40 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-07-19 12:54:54 UTC |
parent | 48a215a5398916c2eea9cdfea07530dda5d8ddff |
src/md4c.c | +43 | -8 |
src/md4c.h | +4 | -0 |
diff --git a/src/md4c.c b/src/md4c.c index 136edce..5be3809 100644 --- a/src/md4c.c +++ b/src/md4c.c @@ -5041,7 +5041,9 @@ md_process_all_blocks(MD_CTX* ctx) if(block->flags & MD_BLOCK_CONTAINER_CLOSER) { MD_LEAVE_BLOCK(block->type, &det); - if(block->type == MD_BLOCK_UL || block->type == MD_BLOCK_OL || block->type == MD_BLOCK_QUOTE || block->type == MD_BLOCK_BOX) + if(block->type == MD_BLOCK_UL || block->type == MD_BLOCK_OL + || block->type == MD_BLOCK_QUOTE || block->type == MD_BLOCK_BOX + || block->type == MD_BLOCK_INDENT) ctx->n_containers--; } @@ -5051,7 +5053,8 @@ md_process_all_blocks(MD_CTX* ctx) if(block->type == MD_BLOCK_UL || block->type == MD_BLOCK_OL) { ctx->containers[ctx->n_containers].is_loose = (block->flags & MD_BLOCK_LOOSE_LIST); ctx->n_containers++; - } else if(block->type == MD_BLOCK_QUOTE || block->type == MD_BLOCK_BOX) { + } else if(block->type == MD_BLOCK_QUOTE || block->type == MD_BLOCK_BOX + || block->type == MD_BLOCK_INDENT) { /* This causes that any text in a block quote, even if * nested inside a tight list item, is wrapped with * <p>...</p>. */ @@ -5749,6 +5752,9 @@ md_is_container_compatible(const MD_CONTAINER* pivot, const MD_CONTAINER* contai if(container->ch == _T('!')) return FALSE; + if(container->ch == _T(':')) + return FALSE; + if(container->ch != pivot->ch) return FALSE; if(container->mark_indent > pivot->contents_indent) @@ -5820,6 +5826,10 @@ md_enter_child_containers(MD_CTX* ctx, int n_children, MD_LINE_ANALYSIS* line) MD_CHECK(md_push_box_bytes(ctx, line, MD_BLOCK_CONTAINER_OPENER)); break; + case _T(':'): + MD_CHECK(md_push_container_bytes(ctx, MD_BLOCK_INDENT, 0, 0, MD_BLOCK_CONTAINER_OPENER)); + break; + default: MD_UNREACHABLE(); break; @@ -5866,6 +5876,11 @@ md_leave_child_containers(MD_CTX* ctx, int n_keep) 0, MD_BLOCK_CONTAINER_CLOSER)); break; + case _T(':'): + MD_CHECK(md_push_container_bytes(ctx, MD_BLOCK_INDENT, 0, + 0, MD_BLOCK_CONTAINER_CLOSER)); + break; + default: MD_UNREACHABLE(); break; @@ -5911,6 +5926,18 @@ md_is_container_mark(MD_CTX* ctx, unsigned indent, OFF beg, OFF* p_end, MD_CONTA return TRUE; } + /* Check for indent mark. */ + if(CH(off) == _T(':')) { + off++; + p_container->ch = _T(':'); + p_container->is_loose = FALSE; + p_container->is_task = FALSE; + p_container->mark_indent = indent; + p_container->contents_indent = indent + 1; + *p_end = off; + return TRUE; + } + /* Check for list item bullet mark. */ if(ISANYOF(off, _T("-+*")) && (off+1 >= ctx->size || ISBLANK(off+1) || ISNEWLINE(off+1))) { p_container->ch = CH(off); @@ -5997,7 +6024,10 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, off < ctx->size && CH(off) == _T('>')) || (c->ch == _T('!') && line->indent < ctx->code_indent_offset && - off < ctx->size && CH(off) == _T('!'))) + off < ctx->size && CH(off) == _T('!')) + || + (c->ch == _T(':') && line->indent < ctx->code_indent_offset && + off < ctx->size && CH(off) == _T(':'))) { /* Block quote mark. */ off++; @@ -6011,7 +6041,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, line->beg = off; - } else if(c->ch != _T('>') && c->ch != _T('!') + } else if(c->ch != _T('>') && c->ch != _T('!') && c->ch != _T(':') && line->indent >= c->contents_indent) { /* List. */ line->indent -= c->contents_indent; @@ -6028,7 +6058,8 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, if(n_brothers + n_children == 0) { while(n_parents < ctx->n_containers && ctx->containers[n_parents].ch != _T('>') - && ctx->containers[n_parents].ch != _T('!')) + && ctx->containers[n_parents].ch != _T('!') + && ctx->containers[n_parents].ch != _T(':')) n_parents++; } } @@ -6104,7 +6135,8 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, ctx->last_line_has_list_loosening_effect = (n_parents > 0 && n_brothers + n_children == 0 && ctx->containers[n_parents-1].ch != _T('>') && - ctx->containers[n_parents-1].ch != _T('!')); + ctx->containers[n_parents-1].ch != _T('!') && + ctx->containers[n_parents-1].ch != _T(':')); #if 1 /* See https://github.com/mity/md4c/issues/6 @@ -6120,6 +6152,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, */ if(n_parents > 0 && ctx->containers[n_parents-1].ch != _T('>') && ctx->containers[n_parents-1].ch != _T('!') && + ctx->containers[n_parents-1].ch != _T(':') && n_brothers + n_children == 0 && ctx->current_block == NULL && ctx->n_block_bytes > (int) sizeof(MD_BLOCK)) { @@ -6140,6 +6173,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, if(ctx->last_list_item_starts_with_two_blank_lines) { if(n_parents > 0 && ctx->containers[n_parents-1].ch != _T('>') && ctx->containers[n_parents-1].ch != _T('!') && + ctx->containers[n_parents-1].ch != _T(':') && n_brothers + n_children == 0 && ctx->current_block == NULL && ctx->n_block_bytes > (int) sizeof(MD_BLOCK)) { @@ -6232,7 +6266,8 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, { if(pivot_line->type == MD_LINE_TEXT && n_parents == ctx->n_containers && (off >= ctx->size || ISNEWLINE(off)) && container.ch != _T('>') - && container.ch != _T('!')) + && container.ch != _T('!') + && container.ch != _T(':')) { /* Noop. List mark followed by a blank line cannot interrupt a paragraph. */ } else if(pivot_line->type == MD_LINE_TEXT && n_parents == ctx->n_containers && @@ -6440,7 +6475,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, /* If we belong to a list after seeing a blank line, the list is loose. */ if(prev_line_has_list_loosening_effect && line->type != MD_LINE_BLANK && n_parents + n_brothers > 0) { MD_CONTAINER* c = &ctx->containers[n_parents + n_brothers - 1]; - if(c->ch != _T('>') && c->ch != _T('!')) { + if(c->ch != _T('>') && c->ch != _T('!') && c->ch != _T(':')) { MD_BLOCK* block = (MD_BLOCK*) (((char*)ctx->block_bytes) + c->block_byte_off); block->flags |= MD_BLOCK_LOOSE_LIST; } diff --git a/src/md4c.h b/src/md4c.h index c1b8b3e..b484185 100644 --- a/src/md4c.h +++ b/src/md4c.h @@ -61,6 +61,9 @@ typedef enum MD_BLOCKTYPE { /* <div class="box">...</div> */ MD_BLOCK_BOX, + /* indented block */ + MD_BLOCK_INDENT, + /* <ul>...</ul> * Detail: Structure MD_BLOCK_UL_DETAIL. */ MD_BLOCK_UL, @@ -334,6 +337,7 @@ typedef struct MD_SPAN_WIKILINK { #define MD_FLAG_BOLD 0x10000 /* Enable bold extension */ #define MD_FLAG_BOX 0x20000 /* Enable box extension */ #define MD_FLAG_HIGHLIGHT 0x40000 /* Enable highlight extension */ +#define MD_FLAG_INDENT 0x80000 /* Enable indent extension */ #define MD_FLAG_PERMISSIVEAUTOLINKS (MD_FLAG_PERMISSIVEEMAILAUTOLINKS | MD_FLAG_PERMISSIVEURLAUTOLINKS | MD_FLAG_PERMISSIVEWWWAUTOLINKS) #define MD_FLAG_NOHTML (MD_FLAG_NOHTMLBLOCKS | MD_FLAG_NOHTMLSPANS)