<pre><code> instead of </pre>
This commit is contained in:
parent
49343dc73c
commit
05a39aecef
1 changed files with 24 additions and 24 deletions
48
cmarkdown.c
48
cmarkdown.c
|
@ -19,7 +19,7 @@ typedef unsigned int (*Parser)(const char *, const char *, int);
|
||||||
struct Tag {
|
struct Tag {
|
||||||
char *search;
|
char *search;
|
||||||
int process;
|
int process;
|
||||||
char *tag;
|
char *before, *after;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,27 +53,27 @@ Parser parsers[] = { dounderline, dohtml, dolineprefix, dolist, doparagraph,
|
||||||
FILE *source;
|
FILE *source;
|
||||||
unsigned int bsize = 0, nohtml = 0;
|
unsigned int bsize = 0, nohtml = 0;
|
||||||
struct Tag lineprefix[] = {
|
struct Tag lineprefix[] = {
|
||||||
{ " ", 0, "pre" },
|
{ " ", 0, "<pre><code>", "</code></pre>" },
|
||||||
{ "\t", 0, "pre" },
|
{ "\t", 0, "<pre><code>", "</code></pre>" },
|
||||||
{ "> ", 2, "blockquote" },
|
{ "> ", 2, "<blockquote>", "</blockquote>" },
|
||||||
{ "###### ", 1, "h6" },
|
{ "###### ", 1, "<h6>", "</h6>" },
|
||||||
{ "##### ", 1, "h5" },
|
{ "##### ", 1, "<h5>", "</h5>" },
|
||||||
{ "#### ", 1, "h4" },
|
{ "#### ", 1, "<h4>", "</h4>" },
|
||||||
{ "### ", 1, "h3" },
|
{ "### ", 1, "<h3>", "</h3>" },
|
||||||
{ "## ", 1, "h2" },
|
{ "## ", 1, "<h2>", "</h2>" },
|
||||||
{ "# ", 1, "h1" },
|
{ "# ", 1, "<h1>", "</h1>" },
|
||||||
};
|
};
|
||||||
struct Tag underline[] = {
|
struct Tag underline[] = {
|
||||||
{ "=", 1, "<h1>" },
|
{ "=", 1, "<h1>", "</h1>" },
|
||||||
{ "-", 1, "<h2>" },
|
{ "-", 1, "<h2>", "</h2>" },
|
||||||
};
|
};
|
||||||
struct Tag surround[] = {
|
struct Tag surround[] = {
|
||||||
{ "``", 0, "code" },
|
{ "``", 0, "<code>", "</code>" },
|
||||||
{ "`", 0, "code" },
|
{ "`", 0, "<code>", "</code>" },
|
||||||
{ "__", 1, "strong" },
|
{ "__", 1, "<strong>", "</strong>" },
|
||||||
{ "**", 1, "strong" },
|
{ "**", 1, "<strong>", "</strong>" },
|
||||||
{ "*", 1, "em" },
|
{ "*", 1, "<em>", "</em>" },
|
||||||
{ "_", 1, "em" },
|
{ "_", 1, "<em>", "</em>" },
|
||||||
};
|
};
|
||||||
char * replace[][2] = {
|
char * replace[][2] = {
|
||||||
{ "\n- - -\n", "\n<hr />\n" },
|
{ "\n- - -\n", "\n<hr />\n" },
|
||||||
|
@ -174,7 +174,7 @@ dolineprefix(const char *begin, const char *end, int newblock) {
|
||||||
if(!(buffer = malloc(BUFFERSIZE)))
|
if(!(buffer = malloc(BUFFERSIZE)))
|
||||||
eprint("Malloc failed.");
|
eprint("Malloc failed.");
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
printf("<%s>\n",lineprefix[i].tag);
|
puts(lineprefix[i].before);
|
||||||
for(j = 0, p += l; p != end; p++, j++) {
|
for(j = 0, p += l; p != end; p++, j++) {
|
||||||
ADDC(buffer,j) = *p;
|
ADDC(buffer,j) = *p;
|
||||||
if(*p == '\n') {
|
if(*p == '\n') {
|
||||||
|
@ -188,7 +188,7 @@ dolineprefix(const char *begin, const char *end, int newblock) {
|
||||||
process(buffer,buffer+strlen(buffer), lineprefix[i].process >= 2);
|
process(buffer,buffer+strlen(buffer), lineprefix[i].process >= 2);
|
||||||
else
|
else
|
||||||
hprint(buffer,buffer+strlen(buffer));
|
hprint(buffer,buffer+strlen(buffer));
|
||||||
printf("</%s>\n",lineprefix[i].tag);
|
puts(lineprefix[i].after);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return -(p - begin);
|
return -(p - begin);
|
||||||
}
|
}
|
||||||
|
@ -407,14 +407,14 @@ dosurround(const char *begin, const char *end, int newblock) {
|
||||||
} while(p && p[-1] == '\\');
|
} while(p && p[-1] == '\\');
|
||||||
if(!p || p > end)
|
if(!p || p > end)
|
||||||
continue;
|
continue;
|
||||||
printf("<%s>",surround[i].tag);
|
fputs(surround[i].before,stdout);
|
||||||
for(q = begin + strlen(surround[i].search); *q == ' '; q++);
|
for(q = begin + strlen(surround[i].search); *q == ' '; q++);
|
||||||
for(qend = p-1; *qend == ' '; qend--);
|
for(qend = p-1; *qend == ' '; qend--);
|
||||||
if(surround[i].process)
|
if(surround[i].process)
|
||||||
process(q, qend+1,0);
|
process(q, qend+1,0);
|
||||||
else
|
else
|
||||||
hprint(q, qend+1);
|
hprint(q, qend+1);
|
||||||
printf("</%s>",surround[i].tag);
|
fputs(surround[i].after,stdout);
|
||||||
return p - begin + l;
|
return p - begin + l;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -435,12 +435,12 @@ dounderline(const char *begin, const char *end, int newblock) {
|
||||||
for(i = 0; i < LENGTH(underline); i++) {
|
for(i = 0; i < LENGTH(underline); i++) {
|
||||||
for(j = 0; p[j] != '\n' && p[j] == underline[i].search[0] && p+j != end; j++);
|
for(j = 0; p[j] != '\n' && p[j] == underline[i].search[0] && p+j != end; j++);
|
||||||
if(j >= l) {
|
if(j >= l) {
|
||||||
printf("<%s>",underline[i].tag);
|
fputs(underline[i].before,stdout);
|
||||||
if(underline[i].process)
|
if(underline[i].process)
|
||||||
process(begin, begin + l, 0);
|
process(begin, begin + l, 0);
|
||||||
else
|
else
|
||||||
hprint(begin, begin + l);
|
hprint(begin, begin + l);
|
||||||
printf("</%s>\n",underline[i].tag);
|
fputs(underline[i].after,stdout);
|
||||||
return -(j + p - begin);
|
return -(j + p - begin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue