]> uap-core.de Git - note.git/commitdiff
implement underline text style
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 7 Feb 2026 11:03:43 +0000 (12:03 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 7 Feb 2026 11:03:43 +0000 (12:03 +0100)
application/editor.c
application/editor.h
application/gtk-text.c
application/note.c

index 9dbcbd1ca6e36965799e886e3cf31b5b10ae0aeb..2f7bb3772d96d858cc9635558bb916a3afb17a95 100644 (file)
@@ -297,6 +297,7 @@ MDDoc* parse_markdown(cxstring markdown) {
     parser.enter_span = md_enter_span;
     parser.leave_span = md_leave_span;
     parser.text = md_text;
+    parser.flags = MD_FLAG_UNDERLINE;
     
     if(md_parse(markdown.ptr, markdown.length, &parser, &data)) {
         cxMempoolFree(mp);
@@ -328,6 +329,7 @@ static const char* node_style(MDNode *n) {
         case MD_SPAN_STRONG: return EDITOR_STYLE_STRONG;
         case MD_SPAN_A: return EDITOR_STYLE_LINK;
         case MD_SPAN_CODE: return EDITOR_STYLE_CODE;
+        case MD_SPAN_U: return EDITOR_STYLE_UNDERLINE;
     }
     return NULL;
 }
index c8fca31ca33c6e7421fd303604d1e76c9b0aa6d0..5598c2994ac14a8150f4598e2de34266717062d4 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 #define EDITOR_STYLE_ORDLIST0   "ol0"
 #define EDITOR_STYLE_EMPHASIS   "_emphasis"
 #define EDITOR_STYLE_STRONG     "_strong"
+#define EDITOR_STYLE_UNDERLINE  "_underline"
 #define EDITOR_STYLE_CODE       "_code"
 #define EDITOR_STYLE_LINK       "_link"
 
@@ -113,6 +114,7 @@ struct MDActiveStyles {
     int paragraph_index;
     UiBool emphasis;
     UiBool strong;
+    UiBool underline;
     UiBool code;
 };
     
index caa68ec36464b9ac2a5567ab5bc6f5e9d919d15c..3521972f4b5ad61aa9ef0c7415cdc6c91ccfad30 100644 (file)
@@ -133,6 +133,7 @@ void editor_global_init() {
     cxMapPut(markdown_tags, EDITOR_STYLE_CODE_BLOCK, &((MDTag){"    ", NULL}));
     cxMapPut(markdown_tags, EDITOR_STYLE_STRONG, &((MDTag){"**", "**"}));
     cxMapPut(markdown_tags, EDITOR_STYLE_EMPHASIS, &((MDTag){"*", "*"}));
+    cxMapPut(markdown_tags, EDITOR_STYLE_UNDERLINE, &((MDTag){"_", "_"}));
     cxMapPut(markdown_tags, EDITOR_STYLE_CODE, &((MDTag){"`", "`"}));
 }
 
@@ -810,6 +811,10 @@ static void tagstyle_strong(MDActiveStyles *style, GtkTextTag *tag) {
     style->strong = TRUE;
 }
 
+static void tagstyle_underline(MDActiveStyles *style, GtkTextTag *tag) {
+    style->underline = TRUE;
+}
+
 static void tagstyle_code(MDActiveStyles *style, GtkTextTag *tag) {
     style->code = TRUE;
 }
@@ -880,6 +885,11 @@ void init_tagtable(GtkTextTagTable *table) {
     g_object_set_data(G_OBJECT(tag), "set_style", (void*)tagstyle_strong);
     gtk_text_tag_table_add(table, tag);
     
+    tag = gtk_text_tag_new(EDITOR_STYLE_UNDERLINE);
+    g_object_set(tag, "underline", PANGO_UNDERLINE_SINGLE, NULL);
+    g_object_set_data(G_OBJECT(tag), "set_style", (void*)tagstyle_underline);
+    gtk_text_tag_table_add(table, tag);
+    
     tag = gtk_text_tag_new(EDITOR_STYLE_CODE);
     g_object_set(tag, "family", "Monospace", "background", "#efefef", NULL);
     g_object_set_data(G_OBJECT(tag), "set_style", (void*)tagstyle_code);
@@ -979,6 +989,7 @@ static CxMap* tags2map(GSList *tags) {
             snprintf(buf, 32, "_%d", anon_tag++);
             cxMapPut(map, buf, t);
         }
+        g_value_unset(&name_value);
         tags = tags->next;
     }
     return map;
index 7c88043b12999f3db6889885e6a3520a03572468..49bf8e5fc1ffc950ffdb90f96c5dc4ef225356b6 100644 (file)
@@ -247,7 +247,9 @@ void note_text_style_set_emphasis(NoteModel *note, UiBool enabled) {
 }
 
 void note_text_style_set_underline(NoteModel *note, UiBool enabled) {
-    
+    if(!editor_set_style(note->text, EDITOR_STYLE_UNDERLINE, enabled)) {
+        ui_set(note->textnote_underline, !enabled);
+    }
 }
 
 void note_text_style_set_code(NoteModel *note, UiBool enabled) {