smu

Simple markup processor
git clone https://git.sinitax.com/codemadness/smu
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 84c908fb6f3609c25ea60c57c7009490c3c77044
parent 9f36d5824c364b655100d211cf156e7c580464c4
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 11 May 2021 01:47:41 +0200

add support for image dimensions and fix a crash

input for image dimensions:

![a](b =2x3) or
![a](b =2)

input to crash:

![a](b ")

Diffstat:
Msmu.c | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/smu.c b/smu.c @@ -251,7 +251,9 @@ dolineprefix(const char *begin, const char *end, int newblock) { int dolink(const char *begin, const char *end, int newblock) { + long width = 0, height = 0; int img, len, sep, parens_depth = 1; + char *numend; const char *desc, *link, *p, *q, *descend, *linkend; const char *title = NULL, *titleend = NULL; @@ -288,9 +290,14 @@ dolink(const char *begin, const char *end, int newblock) { title = p + 1; /* strip trailing whitespace */ for(linkend = p; linkend > link && isspace(*(linkend - 1)); linkend--); - for(titleend = q - 1; titleend > link && isspace(*(titleend)); titleend--); - if(*titleend != sep) { - return 0; + for(titleend = title; titleend < q && *titleend != sep; titleend++); + for(p = titleend + 1; p < end && isspace(*p); p++); + /* image dimensions */ + if(*p == '=') { + width = strtol(++p, &numend, 10); + p = numend; + if(*numend == 'x') + height = strtol(++p, &numend, 10); } } else { @@ -315,6 +322,10 @@ dolink(const char *begin, const char *end, int newblock) { hprintattr(title, titleend); fputs("\" ", stdout); } + if(width > 0) + printf("width=\"%ld\" ", width); + if(height > 0) + printf("height=\"%ld\" ", height); fputs("/>", stdout); } else {