improve attribute parsing for links and images + do not output empty titles - smu - smu - simple markup (Markdown) processor (fork, fixes + features)
 (HTM) git clone git://git.codemadness.org/smu
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit b3c8d1c2bd22c00581982a70ecf7f943168a41c3
 (DIR) parent 2a2b8581a3302d94a9d9d461b7c4ef882c58ab86
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Thu, 13 May 2021 16:48:27 +0200
       
       improve attribute parsing for links and images + do not output empty titles
       
       discount and lowdown do not output empty titles either.
       
       Diffstat:
         M smu.c                               |      32 ++++++++++++++++----------------
       
       1 file changed, 16 insertions(+), 16 deletions(-)
       ---
 (DIR) diff --git a/smu.c b/smu.c
       @@ -260,7 +260,7 @@ int
        dolink(const char *begin, const char *end, int newblock)
        {
                long width = 0, height = 0;
       -        int img, len, sep, parens_depth = 1;
       +        int img, len, parens_depth = 1;
                char *numend;
                const char *desc, *link, *p, *q, *descend, *linkend;
                const char *title = NULL, *titleend = NULL;
       @@ -301,26 +301,22 @@ dolink(const char *begin, const char *end, int newblock)
                        /* trim leading spaces */
                        for (p = link; p < q && isspace((unsigned char)*p); p++)
                                ;
       +
                        for (link = p; p < q; p++) {
       -                        if (isspace((unsigned char)*p)) {
       -                                linkend = p;
       -                                break;
       -                        }
       -                }
       -                for (; p < q; p++) {
       -                        if (isspace((unsigned char)*p))
       -                                continue;
       -                        if (*p == '=') {
       +                        if (*p == '=' && img && p != link &&
       +                            isspace((unsigned char)p[-1])) {
                                        /* image dimensions */
       +                                linkend = p;
                                        width = strtol(++p, &numend, 10);
                                        p = numend;
                                        if (*numend == 'x')
                                                height = strtol(++p, &numend, 10);
       -                        } else if (*p == '\'' || *p == '"') {
       -                                /* separator: can be " or ' */
       -                                sep = *p;
       +                        } else if ((*p == '\'' || *p == '"') && p != link &&
       +                                   isspace((unsigned char)p[-1])) {
       +                                /* title attribute: for links and images */
       +                                linkend = p;
                                        title = ++p;
       -                                if ((titleend = strchr(title, sep))) {
       +                                if ((titleend = strchr(title, *(p - 1)))) {
                                                if (titleend >= q)
                                                        titleend = q;
                                                else
       @@ -328,6 +324,10 @@ dolink(const char *begin, const char *end, int newblock)
                                        }
                                }
                        }
       +
       +                /* trim trailing spaces from link */
       +                for (; linkend > link && isspace((unsigned char)linkend[-1]); linkend--)
       +                        ;
                }
        
                len = q + 1 - begin;
       @@ -337,7 +337,7 @@ dolink(const char *begin, const char *end, int newblock)
                        fputs("\" alt=\"", stdout);
                        hprintattr(desc, descend);
                        fputs("\" ", stdout);
       -                if (title && titleend) {
       +                if (title && titleend && title != titleend) {
                                fputs("title=\"", stdout);
                                hprintattr(title, titleend);
                                fputs("\" ", stdout);
       @@ -353,7 +353,7 @@ dolink(const char *begin, const char *end, int newblock)
                        fputs("<a href=\"", stdout);
                        hprintattr(link, linkend);
                        fputs("\"", stdout);
       -                if (title && titleend) {
       +                if (title && titleend && title != titleend) {
                                fputs(" title=\"", stdout);
                                hprintattr(title, titleend);
                                fputs("\"", stdout);