From 8f661c130b2c79761475f3f620e48a52fa53b2e0 Mon Sep 17 00:00:00 2001 From: Curtis 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(-) (limited to 'bin') diff --git a/bin/hi.c b/bin/hi.c index dcf725a3..d0609e55 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 298343e9c41d201af0808f425a&follow=1'>OpenBSD: Copy appropriate files for chroot</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-26 12:31:21 -0400'>2021-09-26</span></td><td><a href='/torus/commit/image.c?id=3e35eeb55dae066d6b616c0d7a84ade9d9df9c44&follow=1'>OpenBSD: pledge(2) image</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-26 12:16:57 -0400'>2021-09-26</span></td><td><a href='/torus/commit/client.c?id=b230d1909a493b92da855274e976b9f5b11baf97&follow=1'>OpenBSD: pledge(2) client</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-26 12:16:45 -0400'>2021-09-26</span></td><td><a href='/torus/commit/server.c?id=62a9ed3ab5f65c368b5b08d7e40d4d42426647ed&follow=1'>OpenBSD: pledge(2) server</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-24 19:36:33 -0400'>2021-09-24</span></td><td><a href='/torus/commit/Makefile?id=34d2cfc9a68503d47bb478ad2de4351adb501893&follow=1'>Link with -lncursesw</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-20 16:42:55 -0400'>2021-09-20</span></td><td><a href='/torus/commit/client.c?id=a00bea1fa1d542c3caa124436bb1ec9c1370ddee&follow=1'>Replace strlcpy with snprintf</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-09-20 16:32:59 -0400'>2021-09-20</span></td><td><a href='/torus/commit/torus.1?id=c16e3c46793b4fec5f76bf2a61b8877e5ba25e61&follow=1'>Replace kqueue with poll, remove libutil dependency</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-04 19:10:45 -0500'>2021-02-04</span></td><td><a href='/torus/commit/index.html?id=e68e19b02376c981bc6527baa84ec72a40e5a83f&follow=1'>Update play@ascii.town description</a></td><td>June McEnroe</td></tr> <tr><td><span title='2021-02-04 19:06:36 -0500'>2021-02-04</span></td><td><a href='/torus/commit/index.html?id=5576e5a34e87bec4d4f15fc83a8e77493b13a528&follow=1'>Replace donation button with Liberapay</a></td><td>June McEnroe</td></tr> <tr><td><span title='2020-06-25 00:37:59 -0400'>2020-06-25</span></td><td><a href='/torus/commit/sshd_config?id=e4a2b3ba36fac7457a6724712706b3f1a7be3f52&follow=1'>Use DisableForwarding in sshd_config</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-12-19 02:10:53 -0500'>2019-12-19</span></td><td><a href='/torus/commit/README?id=679d6561864782ab7751e9818b4b30480150a63d&follow=1'>Remove README</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-12-15 19:34:23 -0500'>2019-12-15</span></td><td><a href='/torus/commit/help.h?id=de21ce0c5d9e4fb872475b2f77f73ac3babbac25&follow=1'>Update git URLs</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-08-05 12:41:51 -0400'>2019-08-05</span></td><td><a href='/torus/commit/index.html?id=d6ea1dac1369fbb9237adf7fd17bc2dfd988a60a&follow=1'>Add buymeacoffee link</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-07-27 17:57:48 -0400'>2019-07-27</span></td><td><a href='/torus/commit/kcgi.mk?id=07689046a008544c9ccd91a8358c5b536002dc71&follow=1'>Use braces in Makefile</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-07-08 00:05:32 -0400'>2019-07-08</span></td><td><a href='/torus/commit/index.html?id=71deb466f0e9ac2f89fc60c9ec462f7a66e8468a&follow=1'>Remove NetHack from index</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-04-08 17:33:52 -0400'>2019-04-08</span></td><td><a href='/torus/commit/Makefile?id=ad529c9d488c6fbb40652f837c6d84715baf649f&follow=1'>Don't install rc.kfcgi either</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-03-28 15:49:06 -0400'>2019-03-28</span></td><td><a href='/torus/commit/rc.kfcgi?id=314f73c06db8b16375a8c48646417db75564f248&follow=1'>Remove rc.kfcgi</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-16 15:42:22 -0500'>2019-01-16</span></td><td><a href='/torus/commit/index.html?id=390c6d513ecaa8798d64309254222fdff9d3190b&follow=1'>Reformat index.html with explore link</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-16 15:39:33 -0500'>2019-01-16</span></td><td><a href='/torus/commit/explore.html?id=7a6ff732c92bb3ea5d1ddf6c26d33febd18ae040&follow=1'>Return false from keydown handler in explore</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-08 15:44:32 -0500'>2019-01-08</span></td><td><a href='/torus/commit/client.c?id=8de54b3a2bb69d168014bea0dd230e0b2235441d&follow=1'>Draw lines to tile edge</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-08 00:30:21 -0500'>2019-01-08</span></td><td><a href='/torus/commit/torus.h?id=643af427588de649b66717d9d7eed19d3d147f62&follow=1'>Factor out default paths</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-08 00:24:44 -0500'>2019-01-08</span></td><td><a href='/torus/commit/torus.1?id=afe63c2a8c71facf430c89c0dc4bd64a0a2929f2&follow=1'>Remove incorrect default coordinates</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 01:34:59 -0500'>2019-01-07</span></td><td><a href='/torus/commit/explore.html?id=2170945fab0904f7d631ab14d2e3c3192a6ddad4&follow=1'>Set img src when explore fragment changes</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 01:11:20 -0500'>2019-01-07</span></td><td><a href='/torus/commit/png.h?id=42fcb6656dd9b6c735b09ce61f8ce4e875329c43&follow=1'>Compress PNG data in image</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 00:33:52 -0500'>2019-01-07</span></td><td><a href='/torus/commit/image.c?id=966500b7c047c23b8dc0f729e7d2daba7700f11d&follow=1'>madvise MADV_NOCORE in image</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 00:22:34 -0500'>2019-01-07</span></td><td><a href='/torus/commit/explore.html?id=e4ec71ec942249d6d0f04d299032e0708484a11e&follow=1'>Add license notice to explore JavaScript</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 00:20:23 -0500'>2019-01-07</span></td><td><a href='/torus/commit/explore.html?id=9d0a9f16cffd135220970cd0ba944b88400a734e&follow=1'>Add Q/Home binding in explore</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 00:20:07 -0500'>2019-01-07</span></td><td><a href='/torus/commit/explore.html?id=b39ecb0854f35be2f87023b5f7aad348b148d9d0&follow=1'>Fix explore image URL</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-07 00:15:56 -0500'>2019-01-07</span></td><td><a href='/torus/commit/explore.html?id=69b075145417e93888b43209934ba369bb2db2eb&follow=1'>Add HOME button, ssh link, AGPL notice to explore</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-06 22:02:01 -0500'>2019-01-06</span></td><td><a href='/torus/commit/explore.html?id=08a34f0ea9d4b8412f178e1280cefbfd2a6c6438&follow=1'>Add meta viewport to explore</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-06 19:53:00 -0500'>2019-01-06</span></td><td><a href='/torus/commit/explore.html?id=1d17d4cdcf7d6e40c0222e1d1c8b8cf868ea3796&follow=1'>Set background and max-width in explore</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-06 19:40:04 -0500'>2019-01-06</span></td><td><a href='/torus/commit/image.c?id=bb13065c4542f9329e2be2c6c6a977e573d4cc0a&follow=1'>Swallow writes after the connection is closed</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-06 19:18:20 -0500'>2019-01-06</span></td><td><a href='/torus/commit/image.c?id=a3d7c647149dfbd694d43badef5cc704326dc45b&follow=1'>Handle KCGI_HUP</a></td><td>June McEnroe</td></tr> <tr><td><span title='2019-01-06 17:36:05 -0500'>2019-01-06</span></td><td><a href='/torus/commit/Makefile?id=c0726a7b84a95e39c9d2f1939b7daf76afe0275b&follow=1'>Install html files</a></td><td>June McEnroe