summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-22 13:53:43 -0400
committerJune McEnroe <june@causal.agency>2020-04-22 13:53:43 -0400
commit949bc6fd1b2f34009ffb9f1fa951bbdd1b5b517c (patch)
treeb93038a6c27c71efd561f6fa4f368ad321b42423 /html.c
parentAdd parent links to message nav (diff)
downloadbubger-949bc6fd1b2f34009ffb9f1fa951bbdd1b5b517c.tar.gz
bubger-949bc6fd1b2f34009ffb9f1fa951bbdd1b5b517c.zip
Render id, description and language as <pre> attributes
Diffstat (limited to '')
-rw-r--r--html.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/html.c b/html.c
index 62376d5..bead159 100644
--- a/html.c
+++ b/html.c
@@ -167,25 +167,53 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
 	return error;
 }
 
-int htmlInline(FILE *file, const struct BodyPart *part, const char *content) {
-	// TODO: Include Content-Id as id?
-	// TODO: format=flowed.
-	// TODO: Process quoting.
-	// TODO: Highlight patches.
-	const char *template = TEMPLATE(
-		<pre lang="[lang]">[content]</pre>
-	);
-	const char *lang = "";
-	// FIXME: part->language should be more structured.
-	if (part->language.len && part->language.ptr[0].type == String) {
-		lang = part->language.ptr[0].string;
+int htmlInlineAttrs(FILE *file, const struct BodyPart *part) {
+	const char *template = " [attr]=\"[value]\"";
+	if (part->id) {
+		struct Variable vars[] = {
+			{ "attr", "id" },
+			{ "value", part->id },
+			{0},
+		};
+		int error = templateRender(file, template, vars, escapeXML);
+		if (error) return error;
 	}
-	struct Variable vars[] = {
-		{ "lang", lang },
-		{ "content", content },
-		{0},
-	};
-	return templateRender(file, template, vars, escapeXML);
+	if (part->description) {
+		struct Variable vars[] = {
+			{ "attr", "title" },
+			{ "value", part->description },
+			{0},
+		};
+		int error = templateRender(file, template, vars, escapeXML);
+		if (error) return error;
+	}
+	const char *language = NULL;
+	if (part->language.type == String) language = part->language.string;
+	if (part->language.type == List && part->language.list.len == 1) {
+		language = dataCheck(part->language.list.ptr[0], String).string;
+	}
+	if (language) {
+		struct Variable vars[] = {
+			{ "attr", "lang" },
+			{ "value", language },
+			{0},
+		};
+		int error = templateRender(file, template, vars, escapeXML);
+		if (error) return error;
+	}
+	return 0;
+}
+
+int htmlInline(FILE *file, const struct BodyPart *part, const char *content) {
+	// TODO: format=flowed
+	// TODO: Process quoting -> <blockquote>
+	// TODO: Process diffs -> <ins>, <del>
+	return 0
+		|| templateRender(file, TEMPLATE(<pre), NULL, NULL)
+		|| htmlInlineAttrs(file, part)
+		|| templateRender(file, TEMPLATE(>), NULL, NULL)
+		|| escapeXML(file, content)
+		|| templateRender(file, TEMPLATE(</pre>), NULL, NULL);
 }
 
 int htmlAttachmentOpen(FILE *file) {