From cc1cb6c36ecb93e7b9b458f4ea24d1f00480503b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 29 Dec 2020 00:55:47 -0500 Subject: Add hilex HTML output --- bin/hilex/Makefile | 1 + bin/hilex/hilex.1 | 54 +++++++++++++++++++++ bin/hilex/hilex.c | 2 + bin/hilex/hilex.h | 9 +++- bin/hilex/html.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 bin/hilex/html.c (limited to 'bin') diff --git a/bin/hilex/Makefile b/bin/hilex/Makefile index aeaa36d4..5f6c1d80 100644 --- a/bin/hilex/Makefile +++ b/bin/hilex/Makefile @@ -3,6 +3,7 @@ CFLAGS += -std=c11 -Wall -Wextra -Wpedantic OBJS += ansi.o OBJS += c.o OBJS += hilex.o +OBJS += html.o OBJS += irc.o OBJS += mdoc.o OBJS += text.o diff --git a/bin/hilex/hilex.1 b/bin/hilex/hilex.1 index 8b8e0ec7..bc345fe1 100644 --- a/bin/hilex/hilex.1 +++ b/bin/hilex/hilex.1 @@ -65,6 +65,60 @@ input lexer if one cannot be inferred. .It Cm ansi Output ANSI terminal control sequences. . +.It Cm html +Output HTML +.Sy +elements +within a +.Sy
+element.
+The options are as follows:
+.Bl -tag -width "title=..."
+.It Cm anchor
+Output tags as anchor links.
+.
+.It Cm css Ns = Ns Ar url
+With
+.Cm document ,
+output a
+.Sy 
+element for the external stylesheet
+.Ar url .
+If unset,
+output default styles in a
+.Sy \n");
+	}
+
+body:
+	if (opts[Inline] && opts[Tab]) {
+		printf("
");
+	} else {
+		printf("
");
+	}
+}
+
+static void htmlFooter(const char *opts[]) {
+	printf("
"); + if (opts[Document]) printf("\n"); +} + +static void htmlAnchor(const char *opts[], const char *text) { + if (opts[Inline]) { + printf(""); + htmlEscape(text); + printf(""); +} + +static void htmlFormat(const char *opts[], enum Class class, const char *text) { + if (opts[Anchor] && class == Tag) { + htmlAnchor(opts, text); + } else if (class == Normal) { + htmlEscape(text); + } else { + if (opts[Inline]) { + printf("", Style[class] ? Style[class] : ""); + } else { + printf("", Class[class]); + } + htmlEscape(text); + printf(""); + } +} + +const struct Formatter FormatHTML = { htmlHeader, htmlFormat, htmlFooter }; -- cgit 1.4.1