From d82d1577dd0e8bbd8cc67962841ad77144ce2fb1 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 9 Feb 2019 16:50:41 -0500 Subject: Add css and inline HTML options to hi --- bin/hi.c | 68 ++++++++++++++++++++++++++++++++++++----------------------- bin/man1/hi.1 | 26 +++++++++++++++++++---- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/bin/hi.c b/bin/hi.c index 0ce34a74..ecb4758f 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -285,8 +285,10 @@ static void check(void) { #define ENUM_OPTION \ X(Monospace, "monospace") \ - X(Document, "document") \ - X(Title, "title") + X(Document, "document") \ + X(Title, "title") \ + X(CSS, "css") \ + X(Inline, "inline") enum Option { #define X(option, _) option, @@ -446,6 +448,7 @@ static void htmlEscape(const char *str, size_t len) { size_t run = strcspn(str, "&<>"); if (run > len) run = len; switch (str[0]) { + break; case '"': run = 1; printf("""); break; case '&': run = 1; printf("&"); break; case '<': run = 1; printf("<"); break; case '>': run = 1; printf(">"); @@ -456,24 +459,40 @@ static void htmlEscape(const char *str, size_t len) { } } +static const char *ClassName[ClassLen] = { +#define X(class) [class] = #class, + ENUM_CLASS +#undef X +}; + +static const char *HTMLStyle[ClassLen] = { + [Keyword] = "color: dimgray;", + [Macro] = "color: green;", + [String] = "color: teal;", + [Format] = "color: teal; font-weight: bold;", + [Interp] = "color: green;", + [Comment] = "color: navy;", + [Todo] = "color: navy; font-weight: bold;", +}; + static void htmlHeader(const char *opts[]) { - if (opts[Document]) { - printf("\n"); - if (opts[Title]) htmlEscape(opts[Title], strlen(opts[Title])); - printf("\n"); - printf( - "\n" - ); + if (!opts[Document]) goto pre; + printf("\n"); + if (opts[Title]) htmlEscape(opts[Title], strlen(opts[Title])); + printf("\n"); + if (opts[CSS]) { + printf("\n"); + } else if (!opts[Inline]) { + printf("\n"); } +pre: printf("
");
 }
 
@@ -482,16 +501,13 @@ static void htmlFooter(const char *opts[]) {
 	printf("
\n"); } -static const char *ClassName[ClassLen] = { -#define X(class) [class] = #class, - ENUM_CLASS -#undef X -}; - static void htmlOutput(const char *opts[], enum Class class, const char *str, size_t len) { - (void)opts; - printf("", ClassName[class]); + if (opts[Inline]) { + printf("", HTMLStyle[class] ? HTMLStyle[class] : ""); + } else { + printf("", ClassName[class]); + } htmlEscape(str, len); printf(""); } diff --git a/bin/man1/hi.1 b/bin/man1/hi.1 index e1ab5b5b..befb1a69 100644 --- a/bin/man1/hi.1 +++ b/bin/man1/hi.1 @@ -1,4 +1,4 @@ -.Dd February 7, 2019 +.Dd February 9, 2019 .Dt HI 1 .Os . @@ -72,13 +72,31 @@ classes. The options are as follows: .Bl -tag -width "title=..." .It Cm document -Output an HTML document -with inline CSS. +Output an HTML document. .It Cm title Ns = Ns Ar ... -Set the title of the HTML document. +With +.Cm document , +set the +.Sy +element text. The default title is the .Ar file name. +.It Cm css Ns = Ns Ar url +With +.Cm document , +output a +.Sy <link> +element for the external stylesheet +.Ar url . +If unset, +output default styles in a +.Sy <style> +element. +.It Cm inline +Output inline +.Sy style +attributes rather than classes. .El .El . -- cgit 1.4.1 2c38f2568055cb886c&follow=1'>Add -w to up</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='2022-07-13 16:27:22 -0400'>2022-07-13</span></td><td class='logsubject'><a href='/src/commit/home/.config/git/config?id=f7af3791d661fd780b8da773499c10ee05d03569&follow=1'>Set push.autoSetupRemote</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='2022-07-08 17:22:36 -0400'>2022-07-08</span></td><td class='logsubject'><a href='/src/commit/TOUR.7?id=f1e82f57838bb337478b255682bc3a33c035e94a&follow=1'>Remove TOUR</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> There is not that much distinct stuff here anymore. </td></tr> <tr class='logheader'><td><span title='2022-07-03 08:21:05 -0400'>2022-07-03</span></td><td class='logsubject'><a href='/src/commit/txt/books.txt?id=a37fc29df3d52e5cabc693292840016171c92217&follow=1'>Add The Bone Shard Emperor</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. </td></tr> <tr class='logheader'><td><span title='2022-06-25 17:39:13 -0400'>2022-06-25</span></td><td class='logsubject'><a href='/src/commit/home/.config/X/resources?id=f7e8b61cdc5033afbcf0198b9a3b58c7a397cc3a&follow=1'>Bump xterm font size to 12</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='2022-06-10 21:57:20 -0400'>2022-06-10</span></td><td class='logsubject'><a href='/src/commit/bin/sh.l?id=9298fe810211ea3cd5bf6fdbb76b115f28ae2491&follow=1'>Handle subshells (and functions) inside substitutions</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='2022-06-10 15:41:21 -0400'>2022-06-10</span></td><td class='logsubject'><a href='/src/commit/install.sh?id=1e9ed406a664ad0cae0973b31f8abe878e017813&follow=1'>Switch to jorts Install script</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='2022-06-08 15:01:08 -0400'>2022-06-08</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=c1fe77108117eb95b5960e765bdbdd6a21a8caf9&follow=1'>Indicate if still reading or no results</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='2022-06-08 09:07:06 -0400'>2022-06-08</span></td><td class='logsubject'><a href='/src/commit/txt/books.txt?id=77a6a77700a79a8f0859934b900e0c8ad76f2707&follow=1'>Add Maiden, Mother, Crone</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. </td></tr> <tr class='logheader'><td><span title='2022-06-05 00:44:07 -0400'>2022-06-05</span></td><td class='logsubject'><a href='/src/commit/txt/shows.txt?id=4f405376ae6b5d46b37b7a7ada4e0dd70d08f652&follow=1'>FIRST SHOW IN 2.5 YEARS BABEY!!!</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='2022-06-03 11:03:24 -0400'>2022-06-03</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=90b47ca285a6fa0b970e338afa723606cfe68c53&follow=1'>Set line number on File lines</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='2022-06-03 10:34:51 -0400'>2022-06-03</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=ae064a619bb3972f0c12840e7d8950ac025fea1c&follow=1'>Stop polling stdin after EOF</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='2022-06-02 23:17:38 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=956c25d98c3c7af4ff78c3175630b281c780b3c7&follow=1'>Set TABSIZE=4</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> Absolutely indiscriminately. </td></tr> <tr class='logheader'><td><span title='2022-06-02 22:40:41 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=07596633a2d95ff24de1a7a6b9df64534cd9e82e&follow=1'>Do basic match highlighting</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='2022-06-02 21:45:47 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=557f1deb2b1a18ede48950b5421b71f662ea309d&follow=1'>Clean up parsing a little</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='2022-06-02 21:30:03 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=77113cf667e1f4fbccc337b508d0f81b1f4b7563&follow=1'>Don't duplicate path string</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='2022-06-02 20:53:17 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=1da6e2b522a624c1056f4f6cd61f977fded83a37&follow=1'>Use stderr instead of /dev/tty, realloc buffer if lines too long</a></td><td>June McEnroe</td></tr> <tr class='nohover-highlight'><td/><td colspan='3' class='logmsg'> For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. </td></tr> <tr class='logheader'><td><span title='2022-06-02 20:14:26 -0400'>2022-06-02</span></td><td class='logsubject'><a href='/src/commit/bin/qf.c?id=a8ca43a9dd52ba36aae52fa4345aa0af942803d7&follow=1'>Add initial working version of qf</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='2022-05-29 22:20:51 -0400'>2022-05-29</span></td><td class='logsubject'><a href='/src/commit/home/.shrc?id=282a40a8ecedc78b87dc74672fde9e0f50d36ba7&follow=1'>Set prompt for oksh</a></td><td>June McEnroe