aboutsummaryrefslogtreecommitdiff
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
parent46eaf7d134d8c2fd241cb714c7a2af9ed7159084 (diff)
Optimised for better header checks
And removed the rsync flag for updating
-rwxr-xr-xc2x2
-rw-r--r--g2x.c47
2 files changed, 25 insertions, 24 deletions
diff --git a/c2x b/c2x
index 7d6a1b0..195c922 100755
--- a/c2x
+++ b/c2x
@@ -1,5 +1,5 @@
#!/bin/sh
-rsync -avz ./"${1}" ./"${1}_xhtml"
+rsync ./"${1}" ./"${1}_xhtml"
cd ./"${1}_xhtml" || exit
for file in $(find ./* | grep ".gmi" | sed 's/.gmi//'); do
g2x < "./${file}.gmi" > "./${file}.html"
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!
}