From bf079f455282b2e0b9984ce299faa8e309146ff7 Mon Sep 17 00:00:00 2001 From: June 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 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("\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 9-09-05 20:09:34 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/title.c?id=f0bbb49d1cf6d0f6d2544ca6a88828c00a2f6b18&follow=1'>Handle lack of Content-Type</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-09-05 20:04:48 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/title.c?id=8fd1b7e8e3e79f2746dd551eb3ae10cd1880e883&follow=1'>Use CURLINFO_CONTENT_TYPE</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> Oops, didn't see this. </td></tr> <tr class='logheader'><td><span title='2019-09-05 13:51:08 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/title.c?id=f8abaa1316fd075b46262951b223e8a2fa12349b&follow=1'>Decode entities in titles</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-09-05 13:36:58 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/title.c?id=aadee09d292ced6d04ace5b22e5214ad70f5365a&follow=1'>Print title as soon as it's available</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-09-05 02:39:41 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/Makefile?id=72c34c298ea65c3b4c495d563fa43427602d17ea&follow=1'>Use CURL_PREFIX to set flags</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-09-05 01:49:01 -0400'>2019-09-05</span></td><td class='logsubject'><a href='/src/commit/bin/title.c?id=8dddcdeb41e01736b14f415a0adf60819ed8594f&follow=1'>Add title</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-09-04 23:25:44 -0400'>2019-09-04</span></td><td class='logsubject'><a href='/src/commit/txt/music.md?id=2b88a06b9018c1a05f6272ddd5b5769bfe5e5ab4&follow=1'>Add Avorter n'est pas tuer</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-08-29 19:02:54 -0400'>2019-08-29</span></td><td class='logsubject'><a href='/src/commit/prune.sh?id=b55506a5d7850cab1db7c3458852b876a62be92d&follow=1'>Unset executable on shell scripts</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-08-29 18:52:06 -0400'>2019-08-29</span></td><td class='logsubject'><a href='/src/commit/bin/man1/setopt.1?id=40d3e95e80e4f975eb6840bdb626fae80f5d2fab&follow=1'>Add long-missing setopt to bin.7</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> </td></tr> <tr class='logheader'><td><span title='2019-08-29 01:20:23 -0400'>2019-08-29</span></td><td class='logsubject'><a href='/src/commit/bin/man1/edit.1?id=21cd659d201d1e862008aa5ef99eb0df17e5dee1&follow=1'>Add edit</a></td><td>June McEnroe