summary refs log tree commit diff
path: root/bin/hi.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-09 18:08:48 -0500
committerJune McEnroe <june@causal.agency>2019-02-09 18:08:48 -0500
commit1748f04aaada41f4d616df0750cdd55b18f9ff70 (patch)
tree6ee1185d7fb4528304f78a061b2f0e988fb0e19b /bin/hi.c
parentAdd css and inline HTML options to hi (diff)
downloadsrc-1748f04aaada41f4d616df0750cdd55b18f9ff70.tar.gz
src-1748f04aaada41f4d616df0750cdd55b18f9ff70.zip
Add tab option to HTML output of hi
Diffstat (limited to 'bin/hi.c')
-rw-r--r--bin/hi.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/bin/hi.c b/bin/hi.c
index d0609e55..23b3cb3a 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -284,11 +284,12 @@ static void check(void) {
 }
 
 #define ENUM_OPTION \
-	X(Monospace, "monospace") \
-	X(Document, "document") \
-	X(Title, "title") \
 	X(CSS, "css") \
-	X(Inline, "inline")
+	X(Document, "document") \
+	X(Inline, "inline") \
+	X(Monospace, "monospace") \
+	X(Tab, "tab") \
+	X(Title, "title")
 
 enum Option {
 #define X(option, _) option,
@@ -475,6 +476,14 @@ static const char *HTMLStyle[ClassLen] = {
 	[Todo]     = "color: navy; font-weight: bold;",
 };
 
+static void htmlTabSize(const char *tab) {
+	printf("-moz-tab-size: ");
+	htmlEscape(tab, strlen(tab));
+	printf("; tab-size: ");
+	htmlEscape(tab, strlen(tab));
+	printf(";");
+}
+
 static void htmlHeader(const char *opts[]) {
 	if (!opts[Document]) goto pre;
 	printf("<!DOCTYPE html>\n<title>");
@@ -486,14 +495,25 @@ static void htmlHeader(const char *opts[]) {
 		printf("\">\n");
 	} else if (!opts[Inline]) {
 		printf("<style>\n");
+		if (opts[Tab]) {
+			printf("pre.hi { ");
+			htmlTabSize(opts[Tab]);
+			printf(" }\n");
+		}
 		for (enum Class class = 0; class < ClassLen; ++class) {
 			if (!HTMLStyle[class]) continue;
-			printf(".hi.%s { %s }\n", ClassName[class], HTMLStyle[class]);
+			printf("span.hi.%s { %s }\n", ClassName[class], HTMLStyle[class]);
 		}
 		printf("</style>\n");
 	}
 pre:
-	printf("<pre class=\"hi\">");
+	if (opts[Inline] && opts[Tab]) {
+		printf("<pre class=\"hi\" style=\"");
+		htmlTabSize(opts[Tab]);
+		printf("\">");
+	} else {
+		printf("<pre class=\"hi\">");
+	}
 }
 
 static void htmlFooter(const char *opts[]) {