From 1748f04aaada41f4d616df0750cdd55b18f9ff70 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 9 Feb 2019 18:08:48 -0500 Subject: Add tab option to HTML output of hi --- bin/hi.c | 32 ++++++++++++++++++++++++++------ bin/man1/hi.1 | 31 ++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 17 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("\n"); @@ -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 . -- cgit 1.4.1 103157df744fa9f37c4&follow=1'>Use xsel in up and add it do install.sh</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:41:06 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.xsession?id=0974c11b57f1adc99c45a253d3bff3d36c941c77&follow=1'>Swap root window colours</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:29:19 -0500'>2021-02-07</span></td><td><a href='/src/commit/install.sh?id=8fe997d768cd45893b51c91d90ef33cab35b3e9b&follow=1'>Add -X flag to install X stuff on OpenBSD</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:24:20 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=63b3a72f01b171bab78aed84cb96030f79f5260b&follow=1'>Adjust brightness by smaller increments</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:23:55 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=332b86693561ed3d7fb4e61cc7addc12842d7abd&follow=1'>Fix cwm window cycling, move big by default</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:23:02 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/X/resources?id=0c5cae773081392ea2fb58dcab70d777c45c403d&follow=1'>Use class names for Foreground, Background, BorderColor</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 22:21:59 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.xsession?id=0a054350dbedcae3618c92e8eb3a7d43836c4258&follow=1'>Add simple battery status and clock to xsession</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 20:31:15 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/X/resources?id=b9f26fe852fb0b98c272257c6045cf795f0b5e37&follow=1'>Set cursor theme and size</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 18:07:07 -0500'>2021-02-07</span></td><td><a href='/src/commit/bin/up.sh?id=8a637380b556760be922624584d3774c4952f8cf&follow=1'>Use scrot for up -s if no screencapture</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 17:55:55 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.xsession?id=12ffba1ec387633a2763d88602d97bfce9b4bc81&follow=1'>Enable mouse acceleration in X</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 17:35:57 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=15c361e449de20b0c07d74e764d0ced5eb1308a1&follow=1'>Set colours for Xt and cwm</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 17:35:57 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/X/resources?id=d5d5aed9442b8d883a257b73b2e0cced6c29576a&follow=1'>Set urgency on bell in xterm</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 17:35:57 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=bc9314aebda5e161c79da0309b555b8df80b2561&follow=1'>Add bindings for brightness control</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 16:32:14 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.xsession?id=6bc4b54f3df64b2948c8ed7c9b92ed1fde43369f&follow=1'>Set X key repeat rate</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 16:32:14 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=f4f7579347729f2ea19a92626bd9141cda4a50d0&follow=1'>Bump font size to 12</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 16:32:14 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/cwm/cwmrc?id=d249bd4693db0f5489b76985e4f873fee1ee098c&follow=1'>Fully configure and rebind cwm</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 13:36:10 -0500'>2021-02-07</span></td><td><a href='/src/commit/txt/books.txt?id=593699e0e795436fd08c50600df3418692e02c9d&follow=1'>Add Binti</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-07 00:06:34 -0500'>2021-02-07</span></td><td><a href='/src/commit/home/.config/X/resources?id=77a4606d6a531ab87a914047df38ebce3a543865&follow=1'>Finish configuring xterm</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-06 23:13:47 -0500'>2021-02-06</span></td><td><a href='/src/commit/etc/wsconsctl.conf?id=618a52c502dd8c418c98226bf2d9029bcecc08e7&follow=1'>Enable tapping, reverse scroll, set scaling in wsconsctl</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-06 23:02:02 -0500'>2021-02-06</span></td><td><a href='/src/commit/home/.xsession?id=f5da4ffc417212c71b5a3ae8ba5cf4de39aa865b&follow=1'>Set root window to black on purple snow</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-06 22:30:10 -0500'>2021-02-06</span></td><td><a href='/src/commit/home/.xsession?id=d310ac3ddb92c5fe18fc54bcbc66b0e0129f6bec&follow=1'>Add xmodmap configuration</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-06 20:23:45 -0500'>2021-02-06</span></td><td><a href='/src/commit/home/.xsession?id=1577ad23c4cd5417fbddbec457041823168ddbda&follow=1'>Add initial OpenBSD X configuration</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-06 19:48:14 -0500'>2021-02-06</span></td><td><a href='/src/commit/bin/scheme.c?id=0de28f7b4c5b1a2e1ece82043987c4f07b78a9ec&follow=1'>Add xterm output to scheme</a></td><td>June McEnroe