diff options
Diffstat (limited to 'g2x.c')
| -rw-r--r-- | g2x.c | 47 |
1 files changed, 24 insertions, 23 deletions
@@ -32,46 +32,47 @@ int main(void) // Reading a line from stdin into buf while (fgets(buf,BUFSIZE,stdin) != NULL) { - if (!strncmp(buf,"###",3)) // Match ### - { - html("<h3>"); - xmlput(4); - html("</h3>\n"); + if (!strncmp(buf,"# ",2)) + {// Match # for first header + html("<h1>"); + xmlput(2); + html("</h1>\n"); } - else if (!strncmp(buf,"##",2)) // Match ## - { + else if (!strncmp(buf,"## ",3)) + {// Match ## for second header html("<h2>"); xmlput(3); html("</h2>\n"); } - else if (buf[0] == '#') // Match # - { - html("<h1>"); - xmlput(2); - html("</h1>\n"); + else if (!strncmp(buf,"### ",4)) + {// Match ### for third header + html("<h3>"); + xmlput(4); + html("</h3>\n"); } - else if (buf[0] == '>') // Match > for blockquote - { - html("<p><blockquote>"); xmlput(2); + else if (!strncmp(buf,"> ",2)) + {// Match "> " for blockquote + html("<p><blockquote>"); + xmlput(2); html("</blockquote></p>\n"); } - else if (buf[0] == '*') // Match lists - { + else if (!strncmp(buf,"* ",2)) + {// Match * for lists if (list_state == 0) html("<ul>\n"); html("<li>"); xmlput(2); html("</li>\n"); list_state = 1; // in a list } else if (list_state == 1) - { + {// In a set of lists html("</ul>\n"); list_state = 0; // out of a list } else if (!strncmp(buf,"=>",2)) // Match links - { + {// Match => for hyperlinks html("<p><a href=\""); for (pos = 3; buf[pos] != ' ';) putchar(buf[pos++]); - // read entire URL + // read entire URL, then check for "gmi" in URL. if ( buf[pos-3] == 'g' && buf[pos-2] == 'm' && @@ -82,8 +83,8 @@ int main(void) } html("\">"); xmlput(pos+1); html("</a></p>\n"); } - else if (!strncmp(buf,"```",3)) // Match codeblocks - { + else if (!strncmp(buf,"```",3)) + {// Match ``` codeblocks, ignore the block-name fgets(buf,BUFSIZE,stdin); html("<pre><code>"); while (strncmp(buf,"```",3)) { @@ -100,5 +101,5 @@ int main(void) html("</p>\n"); } } html("</body>"); html("</html>"); - // I love gemini! + // I love the gemini protocol! } |