diff --git a/smu.c b/smu.c
index 69bb525..f9d70c7 100644
--- 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("
", stdout);
+ fputs("\" ", stdout);
+ if(title && titleend) {
+ fputs("title=\"", stdout);
+ hprint(title, titleend);
+ fputs("\" ", stdout);
+ }
+ fputs("/>", stdout);
}
else {
fputs("", stdout);
+ fputs("\"", stdout);
+ if(title && titleend) {
+ fputs(" title=\"", stdout);
+ hprint(title, titleend);
+ fputs("\"", stdout);
+ }
+ fputs(">", stdout);
process(desc, descend, 0);
fputs("", stdout);
}
- return p + 1 - begin;
+ return len;
}
int
diff --git a/testdoc b/testdoc
index 014c05b..b4f7e0f 100644
--- 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: 
+
+image with alt text: 
+
+image with title: 
+
+image with title (single quote): 
inline html
-----------