From: Olaf Wintermann Date: Sat, 7 Feb 2026 11:03:43 +0000 (+0100) Subject: implement underline text style X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=4d7c6b61ce7a969892f760dc274097b0ddcda7df;p=note.git implement underline text style --- diff --git a/application/editor.c b/application/editor.c index 9dbcbd1..2f7bb37 100644 --- a/application/editor.c +++ b/application/editor.c @@ -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; } diff --git a/application/editor.h b/application/editor.h index c8fca31..5598c29 100644 --- a/application/editor.h +++ b/application/editor.h @@ -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; }; diff --git a/application/gtk-text.c b/application/gtk-text.c index caa68ec..3521972 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -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; diff --git a/application/note.c b/application/note.c index 7c88043..49bf8e5 100644 --- a/application/note.c +++ b/application/note.c @@ -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) {