]> uap-core.de Git - note.git/commitdiff
count list nodes (for ordered markdown lists)
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 28 Apr 2025 19:43:28 +0000 (21:43 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 28 Apr 2025 19:43:28 +0000 (21:43 +0200)
application/editor.c
application/editor.h
application/note.c

index b83da3304d54c2d4f607540caf6149d9e4fec671..8c2fbf9a2ea15fd9306dadc1a17df560579bd6fb 100644 (file)
@@ -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');
index 5d0e988fbe3259988545adf9aaf86aefb5931d9f..b44e70c4f2a33a21128e29ba2543b887c5b1ea35 100644 (file)
@@ -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 {
index e3872726b25df6ef209525c193f0b3c9f4358b15..fc5af95e6a685d0087717310742f437284b6eca5 100644 (file)
@@ -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);