aboutsummaryrefslogtreecommitdiff
path: root/g2x.c
diff options
context:
space:
mode:
authorInqiyad Sabr <sabr@ariamath.xyz>2025-11-13 00:05:21 +0600
committerInqiyad Sabr <sabr@ariamath.xyz>2025-11-13 00:05:21 +0600
commitb310fce41b551a12eb59e7348878f6069b8351f1 (patch)
treefaa340a709d95f7b4e2a8cc3be368f7e32eb51c1 /g2x.c
parent46eaf7d134d8c2fd241cb714c7a2af9ed7159084 (diff)
Optimised for better header checks
And removed the rsync flag for updating
Diffstat (limited to 'g2x.c')
-rw-r--r--g2x.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/g2x.c b/g2x.c
index 05b64fc..f6e4f33 100644
--- a/g2x.c
+++ b/g2x.c
@@ -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!
}