commit b65bc6d92bc260d97747d5423c2936f80bab1628
parent cd0b68c0b8bfbcbe22cb475e8875ad078baa5ae5
Author: gottox@rootkit.lan <gottox@rootkit.lan>
Date: Mon, 10 Dec 2007 12:13:24 +0100
fixing stupid mistake
adding shortlink support
Diffstat:
M | cmarkdown.c | | | 48 | +++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/cmarkdown.c b/cmarkdown.c
@@ -50,7 +50,9 @@ unsigned int dounderline(const char *begin, const char *end);
/* Parser for underline tags */
unsigned int dolink(const char *begin, const char *end);
/* Parser for links and images */
-Parser parsers[] = { dounderline, dolineprefix, dosurround, dolink, doreplace };
+unsigned int doshortlink(const char *begin, const char *end);
+ /* Parser for links and images */
+Parser parsers[] = { dounderline, dolineprefix, dosurround, dolink, doshortlink, doreplace };
/* list of parsers */
FILE *source;
@@ -136,6 +138,46 @@ dolink(const char *begin, const char *end) {
}
return p + 1 - begin;
}
+unsigned int
+doshortlink(const char *begin, const char *end) {
+ const char *p, *c;
+ int ismail = 0;
+
+ if(*begin != '<')
+ return 0;
+ for(p = begin+1; p && p != end && !strstr(" \t\n",p); p++) {
+ switch(*p) {
+ case ':':
+ ismail = -1;
+ break;
+ case '@':
+ if(ismail == 0)
+ ismail = 1;
+ break;
+ case '>':
+ fputs("<a href=\"",stdout);
+ if(ismail == 1) {
+ /* mailto: */
+ fputs("mailto:",stdout);
+ for(c = begin+1; *c != '>'; c++) {
+ printf("&#%u;",*c);
+ }
+ fputs("\">",stdout);
+ for(c = begin+1; *c != '>'; c++) {
+ printf("&#%u;",*c);
+ }
+ }
+ else {
+ hprint(begin+1,p-1);
+ fputs("\">",stdout);
+ hprint(begin+1,p-1);
+ }
+ fputs("</a>",stdout);
+ return p - begin + 1;
+ }
+ }
+ return 0;
+}
unsigned int
dosurround(const char *begin, const char *end) {
@@ -197,7 +239,7 @@ dolineprefix(const char *begin, const char *end) {
if(!(buffer = malloc(end - begin+1)))
ERRMALLOC;
- printf("<%s>",surround[i].tag);
+ printf("<%s>",lineprefix[i].tag);
for(p = begin, j = 0; p != end; p++, j++) {
buffer[j] = *p;
if(*p == '\n') {
@@ -210,7 +252,7 @@ dolineprefix(const char *begin, const char *end) {
process(buffer,buffer+strlen(buffer));
else
hprint(buffer,buffer+strlen(buffer));
- printf("</%s>",surround[i].tag);
+ printf("</%s>",lineprefix[i].tag);
free(buffer);
return p - begin;
}