smu

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

commit 913a387aff199a02aa4e2bdd39fb0455f6202fde
parent 0121dd058d5399b7d8a8e1e672a8951f3572041e
Author: Enno Boland <g@s01.de>
Date:   Fri, 28 Nov 2014 10:06:32 +0100

apply img and anchor support written by Hiltjo Posthuma. Thanks mate!

Diffstat:
Msmu.c | 38++++++++++++++++++++++++++++++++------
Mtestdoc | 18+++++++++++++++++-
2 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/smu.c b/smu.c @@ -234,8 +234,9 @@ dolineprefix(const char *begin, const char *end, int newblock) { int dolink(const char *begin, const char *end, int newblock) { - int img; + int img, len, sep; const char *desc, *link, *p, *q, *descend, *linkend; + const char *title = NULL, *titleend = NULL; if(*begin == '[') img = 0; @@ -251,24 +252,49 @@ dolink(const char *begin, const char *end, int newblock) { return 0; descend = p; link = p + 2; - if(!(p = strstr(link, ")")) || p > end) + if(!(q = strchr(link, ')')) || q > end) return 0; - linkend = p; + 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(*(linkend - 1)); linkend--); + if(!(p = strchr(title, sep)) || q > end || p > q) + return 0; + titleend = p; + len = p + 2 - begin; + } + else { + linkend = q; + len = q + 1 - begin; + } if(img) { fputs("<img src=\"", stdout); hprint(link, linkend); fputs("\" alt=\"", stdout); hprint(desc, descend); - fputs("\" />", stdout); + fputs("\" ", stdout); + if(title && titleend) { + fputs("title=\"", stdout); + hprint(title, titleend); + fputs("\" ", stdout); + } + fputs("/>", stdout); } else { fputs("<a href=\"", stdout); hprint(link, linkend); - fputs("\">", stdout); + fputs("\"", stdout); + if(title && titleend) { + fputs(" title=\"", stdout); + hprint(title, titleend); + fputs("\"", stdout); + } + fputs(">", stdout); process(desc, descend, 0); fputs("</a>", stdout); } - return p + 1 - begin; + return len; } int diff --git a/testdoc b/testdoc @@ -54,7 +54,23 @@ code: links ----- -[suckless](http://suckless.org) +link: [suckless](http://suckless.org/) + +link with title: [suckless](http://suckless.org/ "software that sucks less") + +link with title (single quote): [suckless](http://suckless.org/ 'software that sucks less') + + +images +------ + +image: ![](http://st.suckless.org/screenshots/20h-2012-s.png) + +image with alt text: ![alt text](http://st.suckless.org/screenshots/20h-2012-s.png) + +image with title: ![alt text](http://st.suckless.org/screenshots/20h-2012-s.png "screenshot of st") + +image with title (single quote): ![alt text](http://st.suckless.org/screenshots/20h-2012-s.png 'screenshot of st') inline html -----------