From b310fce41b551a12eb59e7348878f6069b8351f1 Mon Sep 17 00:00:00 2001
From: Inqiyad Sabr
Date: Thu, 13 Nov 2025 00:05:21 +0600
Subject: Optimised for better header checks
And removed the rsync flag for updating
---
g2x.c | 47 ++++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 23 deletions(-)
(limited to 'g2x.c')
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("");
- xmlput(4);
- html("
\n");
+ if (!strncmp(buf,"# ",2))
+ {// Match # for first header
+ html("");
+ xmlput(2);
+ html("
\n");
}
- else if (!strncmp(buf,"##",2)) // Match ##
- {
+ else if (!strncmp(buf,"## ",3))
+ {// Match ## for second header
html("");
xmlput(3);
html("
\n");
}
- else if (buf[0] == '#') // Match #
- {
- html("");
- xmlput(2);
- html("
\n");
+ else if (!strncmp(buf,"### ",4))
+ {// Match ### for third header
+ html("");
+ xmlput(4);
+ html("
\n");
}
- else if (buf[0] == '>') // Match > for blockquote
- {
- html(""); xmlput(2);
+ else if (!strncmp(buf,"> ",2))
+ {// Match "> " for blockquote
+ html("");
+ xmlput(2);
html("
\n");
}
- else if (buf[0] == '*') // Match lists
- {
+ else if (!strncmp(buf,"* ",2))
+ {// Match * for lists
if (list_state == 0) html("\n");
html("- "); xmlput(2); html("
\n");
list_state = 1; // in a list
}
else if (list_state == 1)
- {
+ {// In a set of lists
html("
\n");
list_state = 0; // out of a list
}
else if (!strncmp(buf,"=>",2)) // Match links
- {
+ {// Match => for hyperlinks
html(""); xmlput(pos+1); html("
\n");
}
- else if (!strncmp(buf,"```",3)) // Match codeblocks
- {
+ else if (!strncmp(buf,"```",3))
+ {// Match ``` codeblocks, ignore the block-name
fgets(buf,BUFSIZE,stdin); html("");
while (strncmp(buf,"```",3))
{
@@ -100,5 +101,5 @@ int main(void)
html("\n");
}
} html("