add -l option to set lazyload hint for images that have dimensions - 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 bcfa37c77dc9519b54e05813b1f73dbbf0f0b4c9 (DIR) parent fbc3d2b11f52754309998077a50a757278671759 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Tue, 11 May 2021 17:30:03 +0200 add -l option to set lazyload hint for images that have dimensions Diffstat: M smu.1 | 3 +++ M smu.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) --- (DIR) diff --git a/smu.1 b/smu.1 @@ -7,6 +7,7 @@ .Sh SYNOPSIS .Nm .Op Fl h +.Op Fl l .Op Fl n .Op Fl v .Sh DESCRIPTION @@ -16,6 +17,8 @@ The options are as follows: .Bl -tag -width Ds .It Fl h prints usage information to stderr, then exits. +.It Fl l +set loading="lazy" hint attribute for images if it has a width and a height. .It Fl n escapes all HTML tags. .It Fl v (DIR) diff --git a/smu.c b/smu.c @@ -41,7 +41,7 @@ static void process(const char *begin, const char *end, int isblock); /* Pro static Parser parsers[] = { dounderline, docomment, dolineprefix, dolist, doparagraph, dogtlt, dosurround, dolink, doshortlink, dohtml, doamp, doreplace }; -static int nohtml = 0; +static int lazyimg = 0, nohtml = 0; static Tag lineprefix[] = { { " ", 0, "<pre><code>", "\n</code></pre>" }, @@ -337,6 +337,8 @@ dolink(const char *begin, const char *end, int newblock) printf("width=\"%ld\" ", width); if (height > 0) printf("height=\"%ld\" ", height); + if (width > 0 && height > 0 && lazyimg) + fputs("loading=\"lazy\" ", stdout); fputs("/>", stdout); } else { fputs("<a href=\"", stdout); @@ -692,7 +694,7 @@ process(const char *begin, const char *end, int newblock) void usage(char **argv) { - eprint("usage: %s [-n]\n\t-n escape HTML strictly\n", argv[0]); + eprint("usage: %s [-l] [-n]\n", argv[0]); } int @@ -710,6 +712,8 @@ main(int argc, char *argv[]) eprint("smu v%s\n", VERSION); else if (!strcmp("-n", argv[i])) nohtml = 1; + else if (!strcmp("-l", argv[i])) + lazyimg = 1; else usage(argv); }