Code » md4c » commit 455a90e
Add INDENT extension so lines prefixed with : get..
author | Olivier Brunel
<jjk@jjacky.com> 2022-12-31 22:26:40 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2022-12-31 22:26:40 UTC |
parent | 102f27685e0d06216903c8adac7dfd85bee47d9e |
src/md4c.c | +39 | -5 |
src/md4c.h | +4 | -0 |
diff --git a/src/md4c.c b/src/md4c.c index 274b395..b95492e 100644 --- a/src/md4c.c +++ b/src/md4c.c @@ -5015,7 +5015,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--; } @@ -5025,7 +5027,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>. */ @@ -5720,6 +5723,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 == _T('!')) return FALSE; @@ -5790,6 +5796,10 @@ md_enter_child_containers(MD_CTX* ctx, int n_children, MD_LINE_ANALYSIS* line) MD_CHECK(md_push_container_bytes(ctx, MD_BLOCK_QUOTE, 0, 0, MD_BLOCK_CONTAINER_OPENER)); break; + case _T(':'): + MD_CHECK(md_push_container_bytes(ctx, MD_BLOCK_INDENT, 0, 0, MD_BLOCK_CONTAINER_OPENER)); + break; + case _T('!'): MD_CHECK(md_push_box_bytes(ctx, line, MD_BLOCK_CONTAINER_OPENER)); break; @@ -5835,6 +5845,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; + case _T('!'): MD_CHECK(md_push_container_bytes(ctx, MD_BLOCK_BOX, 0, 0, MD_BLOCK_CONTAINER_CLOSER)); @@ -5873,6 +5888,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 block box mark. */ if((ctx->parser.flags & MD_FLAG_BOX) && CH(off) == _T('!')) { off++; @@ -5970,6 +5997,9 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, if((c->ch == _T('>') && line->indent < ctx->code_indent_offset && off < ctx->size && CH(off) == _T('>')) || + (c->ch == _T(':') && line->indent < ctx->code_indent_offset && + off < ctx->size && CH(off) == _T(':')) + || (c->ch == _T('!') && line->indent < ctx->code_indent_offset && off < ctx->size && CH(off) == _T('!'))) { @@ -5985,7 +6015,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; @@ -6002,6 +6032,7 @@ 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('!')) n_parents++; } @@ -6078,6 +6109,7 @@ 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('!')); #if 1 @@ -6093,6 +6125,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, * item can begin with at most one blank line." */ 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)) @@ -6113,6 +6146,7 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end, ctx->last_line_has_list_loosening_effect = FALSE; 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)) @@ -6206,7 +6240,7 @@ 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 && @@ -6414,7 +6448,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 642148f..f77bdca 100644 --- a/src/md4c.h +++ b/src/md4c.h @@ -58,6 +58,9 @@ typedef enum MD_BLOCKTYPE { /* <blockquote>...</blockquote> */ MD_BLOCK_QUOTE, + /* indented block */ + MD_BLOCK_INDENT, + /* <div class="box">...</div> */ MD_BLOCK_BOX, @@ -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 box 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)