smu

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

commit b4bfba10cb2c000c39249228fcf6286831484a66
parent 4aea24b36933f3bb3e68fc56226da50803e4d337
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 11 May 2021 01:42:25 +0200

only escape quotes in attributes, in HTML text nodes it's not needed and ugly

Diffstat:
Msmu.c | 31++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/smu.c b/smu.c @@ -33,6 +33,7 @@ static int dosurround(const char *begin, const char *end, int newblock); /* Par static int dounderline(const char *begin, const char *end, int newblock); /* Parser for underline tags */ static void *ereallocz(void *p, size_t size); static void hprint(const char *begin, const char *end); /* escapes HTML and prints it to output */ +static void hprintattr(const char *begin, const char *end); /* escapes HTML for attributes and prints it to output */ static void process(const char *begin, const char *end, int isblock); /* Processes range between begin and end. */ /* list of parsers */ @@ -305,24 +306,24 @@ dolink(const char *begin, const char *end, int newblock) { len = q + 1 - begin; if(img) { fputs("<img src=\"", stdout); - hprint(link, linkend); + hprintattr(link, linkend); fputs("\" alt=\"", stdout); - hprint(desc, descend); + hprintattr(desc, descend); fputs("\" ", stdout); if(title && titleend) { fputs("title=\"", stdout); - hprint(title, titleend); + hprintattr(title, titleend); fputs("\" ", stdout); } fputs("/>", stdout); } else { fputs("<a href=\"", stdout); - hprint(link, linkend); + hprintattr(link, linkend); fputs("\"", stdout); if(title && titleend) { fputs(" title=\"", stdout); - hprint(title, titleend); + hprintattr(title, titleend); fputs("\"", stdout); } fputs(">", stdout); @@ -495,7 +496,7 @@ doshortlink(const char *begin, const char *end, int newblock) { fprintf(stdout, "&#%u;", *c); } else { - hprint(begin + 1, p); + hprintattr(begin + 1, p); fputs("\">", stdout); hprint(begin + 1, p); } @@ -585,7 +586,7 @@ ereallocz(void *p, size_t size) { } void -hprint(const char *begin, const char *end) { +hprintattr(const char *begin, const char *end) { const char *p; for(p = begin; p != end; p++) { @@ -603,6 +604,22 @@ hprint(const char *begin, const char *end) { } void +hprint(const char *begin, const char *end) { + const char *p; + + for(p = begin; p != end; p++) { + if(*p == '&') + fputs("&amp;", stdout); + else if(*p == '>') + fputs("&gt;", stdout); + else if(*p == '<') + fputs("&lt;", stdout); + else + fputc(*p, stdout); + } +} + +void process(const char *begin, const char *end, int newblock) { const char *p, *q; int affected;