git.strcat.st

/strcat/sgit.git/ - summarytreelogarchive

subject
rm patches/*
commit
e02e0adeb2177a4660388d4d443ee8f9e7588fac
date
2026-05-28T12:37:02Z
message
diff
 patches/markdown.patch | 315 -------------------------------------------------
 1 file changed, 315 deletions(-)

diff --git a/patches/markdown.patch b/patches/markdown.patch
deleted file mode 100644
index 5f12ed4..0000000
--- a/patches/markdown.patch
+++ /dev/null
@@ -1,315 +0,0 @@
---- a/sgit.c
-+++ b/sgit.c
-@@ -4,6 +4,7 @@
- #include <sys/stat.h>
- 
- #include <dirent.h>
-+#include <ctype.h>
- #include <errno.h>
- #include <limits.h>
- #include <stdarg.h>
-@@ -62,16 +63,19 @@
- static void	 make_files_page(const struct repo *, const char *);
- static char	*read_git_meta_file(const struct repo *, const char *);
- static void	 make_index(const char *, struct repo *, size_t);
--static void	 make_readme_page(const struct repo *, const char *);
-+static void	 make_readme_page(const struct repo *, const char *, int);
- static void	 make_repo_page(const struct repo *);
- static char	*file_page_name(const char *);
-+static int	 has_suffix_ci(const char *, const char *);
-+static void	 render_markdown(FILE *, const char *);
-+static void	 render_markdown_inline(FILE *, const char *);
- static void	 render_tree(FILE *, const struct repo *, struct tree_node *,
- 	        int);
- static int	 repo_cmp(const void *, const void *);
- static char	*read_cache_head(const char *);
- static char	*read_cmd_output(const char *, ...);
- static char	*read_file_head(const struct repo *, const char *);
--static char	*read_readme(const struct repo *);
-+static char	*read_readme(const struct repo *, int *);
- static char	*repo_basename(const char *);
- static int	 repo_changed(struct repo *);
- static int	 repo_has_git(const char *);
-@@ -87,6 +91,7 @@
- static void	 usage(void);
- static void	 write_cache_head(const char *, const char *);
- static void	 write_html_escaped(FILE *, const char *);
-+static void	 write_html_escaped_len(FILE *, const char *, size_t);
- static char	*write_shell_quoted(const char *);
- 
- int
-@@ -642,7 +647,15 @@
- static void
- write_html_escaped(FILE *fp, const char *s)
- {
--	for (; *s != '\0'; s++) {
-+	write_html_escaped_len(fp, s, strlen(s));
-+}
-+
-+static void
-+write_html_escaped_len(FILE *fp, const char *s, size_t len)
-+{
-+	size_t i;
-+
-+	for (i = 0; i < len; i++) {
- 	    switch (*s) {
- 	    case '&':
- 	        fputs("&amp;", fp);
-@@ -660,6 +673,7 @@
- 	        fputc((unsigned char)*s, fp);
- 	        break;
- 	    }
-+	    s++;
- 	}
- }
- 
-@@ -735,13 +749,14 @@
- }
- 
- static char *
--read_readme(const struct repo *r)
-+read_readme(const struct repo *r, int *is_md)
- {
- 	const char *names[] = { "README.md", "README", "README.txt", "readme.md",
- 	    "readme", NULL };
- 	char *out, *qname, *qpath;
- 	size_t i;
- 
-+	*is_md = 0;
- 	qpath = write_shell_quoted(r->path);
- 	if (qpath == NULL)
- 	    err(1, "malloc");
-@@ -755,6 +770,7 @@
- 	    if (out == NULL)
- 	        continue;
- 	    if (out[0] != '\0') {
-+	        *is_md = has_suffix_ci(names[i], ".md");
- 	        free(qpath);
- 	        return out;
- 	    }
-@@ -764,6 +780,177 @@
- 	return str_dup("");
- }
- 
-+static int
-+has_suffix_ci(const char *s, const char *suffix)
-+{
-+	size_t i, ls, lsf;
-+
-+	ls = strlen(s);
-+	lsf = strlen(suffix);
-+	if (lsf > ls)
-+	    return 0;
-+	for (i = 0; i < lsf; i++) {
-+	    if (tolower((unsigned char)s[ls - lsf + i]) !=
-+	        tolower((unsigned char)suffix[i]))
-+	        return 0;
-+	}
-+	return 1;
-+}
-+
-+static void
-+render_markdown_inline(FILE *fp, const char *line)
-+{
-+	const char *code_end, *link_close, *link_end, *p, *url_start;
-+	size_t n;
-+
-+	p = line;
-+	while (*p != '\0') {
-+	    if (*p == '`') {
-+	        code_end = strchr(p + 1, '`');
-+	        if (code_end != NULL) {
-+	            fputs("<code>", fp);
-+	            write_html_escaped_len(fp, p + 1,
-+	                (size_t)(code_end - (p + 1)));
-+	            fputs("</code>", fp);
-+	            p = code_end + 1;
-+	            continue;
-+	        }
-+	    }
-+	    if (*p == '[') {
-+	        link_close = strchr(p + 1, ']');
-+	        if (link_close != NULL && *(link_close + 1) == '(') {
-+	            url_start = link_close + 2;
-+	            link_end = strchr(url_start, ')');
-+	            if (link_end != NULL) {
-+	                fputs("<a href=\"", fp);
-+	                write_html_escaped_len(fp, url_start,
-+	                    (size_t)(link_end - url_start));
-+	                fputs("\">", fp);
-+	                write_html_escaped_len(fp, p + 1,
-+	                    (size_t)(link_close - (p + 1)));
-+	                fputs("</a>", fp);
-+	                p = link_end + 1;
-+	                continue;
-+	            }
-+	        }
-+	    }
-+	    n = strcspn(p, "`[");
-+	    if (n == 0) {
-+	        write_html_escaped_len(fp, p, 1);
-+	        p++;
-+	    } else {
-+	        write_html_escaped_len(fp, p, n);
-+	        p += n;
-+	    }
-+	}
-+}
-+
-+static void
-+render_markdown(FILE *fp, const char *md)
-+{
-+	char *line;
-+	char *save;
-+	int in_code, in_list, in_p, level;
-+
-+	save = str_dup(md);
-+	if (save == NULL)
-+	    err(1, "malloc");
-+	in_code = 0;
-+	in_list = 0;
-+	in_p = 0;
-+	line = strtok(save, "\n");
-+	while (line != NULL) {
-+	    while (*line == ' ' || *line == '\t')
-+	        line++;
-+	    if (strncmp(line, "```", 3) == 0) {
-+	        if (in_p) {
-+	            fputs("</p>\n", fp);
-+	            in_p = 0;
-+	        }
-+	        if (in_list) {
-+	            fputs("</ul>\n", fp);
-+	            in_list = 0;
-+	        }
-+	        if (!in_code)
-+	            fputs("<pre>", fp);
-+	        else
-+	            fputs("</pre>\n", fp);
-+	        in_code = !in_code;
-+	        line = strtok(NULL, "\n");
-+	        continue;
-+	    }
-+	    if (in_code) {
-+	        write_html_escaped(fp, line);
-+	        fputc('\n', fp);
-+	        line = strtok(NULL, "\n");
-+	        continue;
-+	    }
-+	    if (*line == '\0') {
-+	        if (in_p) {
-+	            fputs("</p>\n", fp);
-+	            in_p = 0;
-+	        }
-+	        if (in_list) {
-+	            fputs("</ul>\n", fp);
-+	            in_list = 0;
-+	        }
-+	        line = strtok(NULL, "\n");
-+	        continue;
-+	    }
-+	    if (*line == '#') {
-+	        if (in_p) {
-+	            fputs("</p>\n", fp);
-+	            in_p = 0;
-+	        }
-+	        if (in_list) {
-+	            fputs("</ul>\n", fp);
-+	            in_list = 0;
-+	        }
-+	        level = 0;
-+	        while (*line == '#' && level < 6) {
-+	            level++;
-+	            line++;
-+	        }
-+	        while (*line == ' ')
-+	            line++;
-+	        fprintf(fp, "<h%d>", level == 0 ? 1 : level);
-+	        render_markdown_inline(fp, line);
-+	        fprintf(fp, "</h%d>\n", level == 0 ? 1 : level);
-+	        line = strtok(NULL, "\n");
-+	        continue;
-+	    }
-+	    if ((line[0] == '-' || line[0] == '*') && line[1] == ' ') {
-+	        if (in_p) {
-+	            fputs("</p>\n", fp);
-+	            in_p = 0;
-+	        }
-+	        if (!in_list) {
-+	            fputs("<ul>\n", fp);
-+	            in_list = 1;
-+	        }
-+	        fputs("<li>", fp);
-+	        render_markdown_inline(fp, line + 2);
-+	        fputs("</li>\n", fp);
-+	        line = strtok(NULL, "\n");
-+	        continue;
-+	    }
-+	    if (!in_p) {
-+	        fputs("<p>", fp);
-+	        in_p = 1;
-+	    } else
-+	        fputs("<br>\n", fp);
-+	    render_markdown_inline(fp, line);
-+	    line = strtok(NULL, "\n");
-+	}
-+	if (in_code)
-+	    fputs("</pre>\n", fp);
-+	if (in_p)
-+	    fputs("</p>\n", fp);
-+	if (in_list)
-+	    fputs("</ul>\n", fp);
-+	free(save);
-+}
-+
- static char *
- read_git_meta_file(const struct repo *r, const char *name)
- {
-@@ -799,7 +986,7 @@
- }
- 
- static void
--make_readme_page(const struct repo *r, const char *readme)
-+make_readme_page(const struct repo *r, const char *readme, int readme_md)
- {
- 	char *html;
- 	FILE *fp;
-@@ -842,9 +1029,13 @@
- 
- 	if (readme[0] != '\0') {
- 	    fputs("<h2>readme</h2>\n", fp);
--	    fputs("<pre>", fp);
--	    write_html_escaped(fp, readme);
--	    fputs("</pre>\n", fp);
-+	    if (readme_md)
-+	        render_markdown(fp, readme);
-+	    else {
-+	        fputs("<pre>", fp);
-+	        write_html_escaped(fp, readme);
-+	        fputs("</pre>\n", fp);
-+	    }
- 	}
- 	fputs("</body>\n</html>\n", fp);
- 
-@@ -1146,6 +1337,7 @@
- 	char *commits, *files, *full_hash, *history, *line, *qpath, *readme;
- 	char *short_hash, *author, *date, *subject;
- 	FILE *fp;
-+	int readme_md;
- 
- 	qpath = write_shell_quoted(r->path);
- 	if (qpath == NULL)
-@@ -1163,11 +1355,11 @@
- 	    err(1, "malloc");
- 	free(qpath);
- 
--	readme = read_readme(r);
-+	readme = read_readme(r, &readme_md);
- 	if (readme == NULL)
- 	    err(1, "malloc");
- 
--	make_readme_page(r, readme);
-+	make_readme_page(r, readme, readme_md);
- 	make_files_page(r, files);
- 
- 	history = join3(r->outdir, "/", "history.html");