add the new runtime flag ALT_AS_TITLE; if an image has no title, use the alt text as the title

This commit is contained in:
david parsons
2023-02-21 11:03:12 -08:00
parent 5d13c2828d
commit faa5150346
5 changed files with 13 additions and 4 deletions
+1
View File
@@ -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])
+7 -2
View File
@@ -559,7 +559,9 @@ typedef struct linkytype {
} linkytype;
static linkytype imaget = { 0, 0, "<img src=\"", "\"",
1, " alt=\"", "\" />", { { [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, "<a href=\"", "\"",
0, ">", "</a>", { {[MKD_NOLINKS] = 1} }, IS_URL };
@@ -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);
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);
}
+1
View File
@@ -43,6 +43,7 @@ enum { MKD_NOLINKS=0, /* don't do link processing, block <a> 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 };
+1
View File
@@ -40,6 +40,7 @@ enum { MKD_NOLINKS=0, /* don't do link processing, block <a> 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 */
+1
View File
@@ -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])