From f3466836ae192dbb78aa3a15020909cc76147aa8 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 28 Apr 2025 21:43:28 +0200 Subject: [PATCH] count list nodes (for ordered markdown lists) --- application/editor.c | 13 +++++++++++-- application/editor.h | 3 +++ application/note.c | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/application/editor.c b/application/editor.c index b83da33..8c2fbf9 100644 --- a/application/editor.c +++ b/application/editor.c @@ -98,6 +98,7 @@ static MDNode* md_node_create(MDParserData *data) { if(current) { if(current->closed) { current->next = node; + node->num = current->num + 1; if(current->parent) { current->parent->children_end = node; } @@ -345,6 +346,8 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de sec.length = MDDocStyleSection_LIST; sec.style = EDITOR_STYLE_LIST0; sec.link = NULL; + sec.num = n->num; + sec.depth = depth; cxListAdd(sections, &sec); size_t start_pos = buf->pos; @@ -352,7 +355,7 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de MDNode *c = n->children_begin; depth++; while(c) { - linearize_mdnodes(buf, sections, c, depth); + linearize_mdnodes(buf, sections, c, depth+1); c = c->next; } @@ -360,6 +363,8 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de sec.length = buf->pos - start_pos; sec.style = EDITOR_STYLE_LIST0; sec.link = NULL; + sec.num = 0; + sec.depth = depth; cxListAdd(sections, &sec); cxBufferPut(buf, '\n'); @@ -369,6 +374,7 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de sec.length = MDDocStyleSection_IMAGE; sec.style = n->children_begin ? n->children_begin->text.ptr : NULL; sec.link = n->link.ptr; + sec.num = 0; cxListAdd(sections, &sec); } else { size_t start_pos = buf->pos; @@ -376,7 +382,7 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de MDNode *c = n->children_begin; depth++; while(c) { - linearize_mdnodes(buf, sections, c, depth); + linearize_mdnodes(buf, sections, c, depth+1); c = c->next; } @@ -385,6 +391,7 @@ static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int de sec.length = buf->pos - start_pos; sec.style = node_style(n); sec.link = n->link.ptr; + sec.num = 0; cxListAdd(sections, &sec); } } @@ -405,6 +412,7 @@ static const char* paragraph_style(MDPara *p) { case MD_BLOCK_QUOTE: return EDITOR_STYLE_QUOTE; case MD_BLOCK_CODE: return EDITOR_STYLE_CODE_BLOCK; case MD_BLOCK_UL: return EDITOR_STYLE_PARAGRAPH; + case MD_BLOCK_OL: return EDITOR_STYLE_PARAGRAPH; default: return EDITOR_STYLE_PARAGRAPH; } } @@ -425,6 +433,7 @@ static void linearize_paragraph(CxBuffer *buf, CxList *sections, MDPara *p) { sec.length = buf->pos - start_pos; sec.style = paragraph_style(p); sec.link = NULL; + sec.num = 0; cxListAdd(sections, &sec); cxBufferPut(buf, '\n'); diff --git a/application/editor.h b/application/editor.h index 5d0e988..b44e70c 100644 --- a/application/editor.h +++ b/application/editor.h @@ -83,6 +83,7 @@ struct MDNode { MDNode *children_begin; MDNode *children_end; MDNode *next; + int num; int closed; }; @@ -102,6 +103,8 @@ struct MDDocStyleSection { int length; const char *style; const char *link; + int depth; + int num; }; struct MDActiveStyles { diff --git a/application/note.c b/application/note.c index e387272..fc5af95 100644 --- a/application/note.c +++ b/application/note.c @@ -93,7 +93,7 @@ void notemodel_set_note(NoteModel *model, Resource *note) { ui_set(model->title, note->title); if(note->content_loaded) { - // TODO: when multiple note types are implemented, chec contenttype + // TODO: when multiple note types are implemented, check contenttype // and set model->text, model->html or something else if(!note->contenttype) { ui_set(model->text, note->content.ptr); -- 2.43.5