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

This commit is contained in:
Enno Boland 2014-11-28 10:06:32 +01:00
parent 0121dd058d
commit 913a387aff
2 changed files with 49 additions and 7 deletions

38
smu.c
View file

@ -234,8 +234,9 @@ dolineprefix(const char *begin, const char *end, int newblock) {
int int
dolink(const char *begin, const char *end, int newblock) { 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 *desc, *link, *p, *q, *descend, *linkend;
const char *title = NULL, *titleend = NULL;
if(*begin == '[') if(*begin == '[')
img = 0; img = 0;
@ -251,24 +252,49 @@ dolink(const char *begin, const char *end, int newblock) {
return 0; return 0;
descend = p; descend = p;
link = p + 2; link = p + 2;
if(!(p = strstr(link, ")")) || p > end) if(!(q = strchr(link, ')')) || q > end)
return 0; 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) { if(img) {
fputs("<img src=\"", stdout); fputs("<img src=\"", stdout);
hprint(link, linkend); hprint(link, linkend);
fputs("\" alt=\"", stdout); fputs("\" alt=\"", stdout);
hprint(desc, descend); hprint(desc, descend);
fputs("\" />", stdout); fputs("\" ", stdout);
if(title && titleend) {
fputs("title=\"", stdout);
hprint(title, titleend);
fputs("\" ", stdout);
}
fputs("/>", stdout);
} }
else { else {
fputs("<a href=\"", stdout); fputs("<a href=\"", stdout);
hprint(link, linkend); hprint(link, linkend);
fputs("\">", stdout); fputs("\"", stdout);
if(title && titleend) {
fputs(" title=\"", stdout);
hprint(title, titleend);
fputs("\"", stdout);
}
fputs(">", stdout);
process(desc, descend, 0); process(desc, descend, 0);
fputs("</a>", stdout); fputs("</a>", stdout);
} }
return p + 1 - begin; return len;
} }
int int

18
testdoc
View file

@ -54,7 +54,23 @@ code:
links 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 inline html
----------- -----------