diff options
author | June McEnroe <june@causal.agency> | 2019-02-09 18:08:48 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-02-09 18:08:48 -0500 |
commit | bf079f455282b2e0b9984ce299faa8e309146ff7 (patch) | |
tree | f9a1fdbef4fb23a91fb3f6ffb1b37422ab3ae3c2 /bin | |
parent | Add css and inline HTML options to hi (diff) | |
download | src-bf079f455282b2e0b9984ce299faa8e309146ff7.tar.gz src-bf079f455282b2e0b9984ce299faa8e309146ff7.zip |
Add tab option to HTML output of hi
Diffstat (limited to '')
-rw-r--r-- | bin/hi.c | 32 | ||||
-rw-r--r-- | bin/man1/hi.1 | 31 |
2 files changed, 46 insertions, 17 deletions
diff --git a/bin/hi.c b/bin/hi.c index ecb4758f..383ad771 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[]) { diff --git a/bin/man1/hi.1 b/bin/man1/hi.1 index befb1a69..046b6384 100644 --- a/bin/man1/hi.1 +++ b/bin/man1/hi.1 @@ -71,17 +71,6 @@ classes. .Pp The options are as follows: .Bl -tag -width "title=..." -.It Cm document -Output an HTML document. -.It Cm title Ns = Ns Ar ... -With -.Cm document , -set the -.Sy <title> -element text. -The default title is the -.Ar file -name. .It Cm css Ns = Ns Ar url With .Cm document , @@ -93,10 +82,30 @@ If unset, output default styles in a .Sy <style> element. +.It Cm document +Output an HTML document. .It Cm inline Output inline .Sy style attributes rather than classes. +.It Cm tab Ns = Ns Ar n +With +.Cm document +or +.Cm inline , +set the +.Sy tab-size +property to +.Ar n . +.It Cm title Ns = Ns Ar ... +With +.Cm document , +set the +.Sy <title> +element text. +The default title is the +.Ar file +name. .El .El . |