From faa51503466b893312c238fffbcccf8e545af8db Mon Sep 17 00:00:00 2001 From: david parsons Date: Tue, 21 Feb 2023 11:03:12 -0800 Subject: [PATCH] add the new runtime flag ALT_AS_TITLE; if an image has no title, use the alt text as the title --- flags.c | 1 + generate.c | 13 +++++++++---- markdown.h | 1 + mkdio.h.in | 1 + pgm_options.c | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/flags.c b/flags.c index 88b8063..a37218d 100644 --- a/flags.c +++ b/flags.c @@ -37,6 +37,7 @@ static struct flagnames flagnames[] = { { MKD_URLENCODEDANCHOR, "URLENCODEDANCHOR" }, { MKD_LATEX, "LATEX" }, { MKD_EXPLICITLIST, "EXPLICITLIST" }, + { MKD_ALT_AS_TITLE, "ALT_AS_TITLE" }, }; #define NR(x) (sizeof x/sizeof x[0]) diff --git a/generate.c b/generate.c index 11d36f7..ee6159a 100644 --- a/generate.c +++ b/generate.c @@ -559,7 +559,9 @@ typedef struct linkytype { } linkytype; static linkytype imaget = { 0, 0, "\"",", { { [MKD_NOIMAGE] = 1, [MKD_TAGTEXT] = 1} }, IS_URL }; + 1, " alt=\"", "\" />", { { [MKD_NOIMAGE] = 1, + [MKD_TAGTEXT] = 1, + [MKD_ALT_AS_TITLE] = 1 } }, IS_URL }; static linkytype linkt = { 0, 0, "", "", { {[MKD_NOLINKS] = 1} }, IS_URL }; @@ -652,7 +654,7 @@ extra_linky(MMIOT *f, Cstring text, Footnote *ref) if ( ref->fn_flags & REFERENCED ) return 0; - if ( is_flag_set(&f->flags,IS_LABEL) ) + if ( is_flag_set(&f->flags, IS_LABEL) ) ___mkd_reparse(T(text), S(text), &(linkt.flags), f, 0); else { ref->fn_flags |= REFERENCED; @@ -728,9 +730,12 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref) if ( ref->width ) Qprintf(f, " width=\"%d\"", ref->width); } - if ( S(ref->title) ) { + if ( S(ref->title) || (is_flag_set(&f->flags, MKD_ALT_AS_TITLE) && is_flag_set(&tag->flags, MKD_ALT_AS_TITLE)) ) { Qstring(" title=\"", f); - ___mkd_reparse(T(ref->title), S(ref->title), &tagtext, f, 0); + if ( S(ref->title) ) + ___mkd_reparse(T(ref->title), S(ref->title), &tagtext, f, 0); + else + ___mkd_reparse(T(text), S(text), &tagtext, f, 0); Qchar('"', f); } diff --git a/markdown.h b/markdown.h index e0ff481..d3f7854 100644 --- a/markdown.h +++ b/markdown.h @@ -43,6 +43,7 @@ enum { MKD_NOLINKS=0, /* don't do link processing, block tags */ MKD_GITHUBTAGS, /* allow dash and underscore in element names */ MKD_URLENCODEDANCHOR, /* urlencode non-identifier chars instead of replacing with dots */ MKD_LATEX, /* handle embedded LaTeX escapes */ + MKD_ALT_AS_TITLE, /* use alt text as the title if no title is listed */ /* end of user flags */ IS_LABEL, MKD_NR_FLAGS }; diff --git a/mkdio.h.in b/mkdio.h.in index 56626e2..359614a 100644 --- a/mkdio.h.in +++ b/mkdio.h.in @@ -40,6 +40,7 @@ enum { MKD_NOLINKS=0, /* don't do link processing, block tags */ MKD_GITHUBTAGS, /* allow dash and underscore in element names */ MKD_URLENCODEDANCHOR, /* urlencode non-identifier chars instead of replacing with dots */ MKD_LATEX, /* handle embedded LaTeX escapes */ + MKD_ALT_AS_TITLE, /* use alt text as the title if no title is listed */ MKD_NR_FLAGS }; /* abstract flag type */ diff --git a/pgm_options.c b/pgm_options.c index ec1b22b..a9312b6 100644 --- a/pgm_options.c +++ b/pgm_options.c @@ -78,6 +78,7 @@ static struct _opt { { "regular-listitem","github-style check items", 0, 0, 1, 1, MKD_NORMAL_LISTITEM } , { "definitionlist","both discount & markdown extra definition lists", 1 }, { "dlist", "both discount & markdown extra definition lists", 1, 0, 1 }, + { "alt_as_title", "use the alt text as a title if there isn't one (images)", 0, 0, 0, 1, MKD_ALT_AS_TITLE }, } ; #define NR(x) (sizeof x / sizeof x[0])