image: allow title or dimensions and allow them in any order - 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 1fa74fe8b249d88a0db4bbd96a7f144fcf0c3a6c
 (DIR) parent 30baf9de128f6bf13470f2356cac768e0a8f95d5
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue, 11 May 2021 17:33:18 +0200
       
       image: allow title or dimensions and allow them in any order
       
       Diffstat:
         M smu.c                               |      56 ++++++++++++++++++-------------
       
       1 file changed, 32 insertions(+), 24 deletions(-)
       ---
 (DIR) diff --git a/smu.c b/smu.c
       @@ -292,33 +292,41 @@ dolink(const char *begin, const char *end, int newblock)
                                q++;
                }
        
       -        if ((p = strpbrk(link, "\"'")) && p < end && q > p) {
       -                sep = p[0]; /* separator: can be " or ' */
       -                title = p + 1;
       -                /* strip trailing whitespace */
       -                for (linkend = p; linkend > link && isspace((unsigned char)*(linkend - 1)); linkend--)
       -                        ;
       -                for (titleend = title; titleend < q && *titleend != sep; titleend++)
       -                        ;
       -                for (p = titleend + 1; p < end && isspace((unsigned char)*p); p++)
       -                        ;
       -                /* image dimensions */
       -                if (*p == '=') {
       -                        width = strtol(++p, &numend, 10);
       -                        p = numend;
       -                        if (*numend == 'x')
       -                                height = strtol(++p, &numend, 10);
       -                }
       -        } else {
       -                /* strip trailing whitespace */
       -                for (linkend = q; linkend > link && isspace((unsigned char)*(linkend - 1)); linkend--)
       -                        ;
       -        }
       -
       -        /* Links can be given in angular brackets */
       +        linkend = q;
                if (*link == '<' && *(linkend - 1) == '>') {
                        link++;
                        linkend--;
       +        } else {
       +                /* trim leading spaces */
       +                for (p = link; p < end && isspace((unsigned char)*p); p++)
       +                        ;
       +                for (link = p; p < end; p++) {
       +                        if (isspace((unsigned char)*p)) {
       +                                linkend = p;
       +                                break;
       +                        }
       +                }
       +                for (; p < end; p++) {
       +                        if (isspace((unsigned char)*p))
       +                                continue;
       +                        if (*p == '=') {
       +                                /* image dimensions */
       +                                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;
       +                                title = ++p;
       +                                if ((titleend = strchr(title, sep))) {
       +                                        if (titleend >= end)
       +                                                titleend = end;
       +                                        else
       +                                                p = titleend;
       +                                }
       +                        }
       +                }
                }
        
                len = q + 1 - begin;