about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--archive.h2
-rw-r--r--html.c64
-rw-r--r--parse.c8
3 files changed, 51 insertions, 23 deletions
diff --git a/archive.h b/archive.h
index 03ee4f2..23f27f1 100644
--- a/archive.h
+++ b/archive.h
@@ -96,7 +96,7 @@ struct BodyPart {
 		const char *type;
 		struct List params;
 	} disposition;
-	struct List language;
+	struct Data language;
 	struct List location;
 };
 
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) {
diff --git a/parse.c b/parse.c
index 808852a..e2f2a99 100644
--- a/parse.c
+++ b/parse.c
@@ -182,8 +182,8 @@ static void parseNonMultipart(struct BodyPart *part, struct List list) {
 	if (Disposition < list.len && list.ptr[Disposition].type == List) {
 		parseDisposition(part, list.ptr[Disposition].list);
 	}
-	if (Language < list.len && list.ptr[Language].type == List) {
-		part->language = list.ptr[Language].list;
+	if (Language < list.len) {
+		part->language = list.ptr[Language];
 	}
 	if (Location < list.len && list.ptr[Location].type == List) {
 		part->location = list.ptr[Location].list;
@@ -218,8 +218,8 @@ static void parseMultipart(struct BodyPart *part, struct List list) {
 	if (Disposition < list.len && list.ptr[Disposition].type == List) {
 		parseDisposition(part, list.ptr[Disposition].list);
 	}
-	if (Language < list.len && list.ptr[Language].type == List) {
-		part->language = list.ptr[Language].list;
+	if (Language < list.len) {
+		part->language = list.ptr[Language];
 	}
 	if (Location < list.len && list.ptr[Location].type == List) {
 		part->location = list.ptr[Location].list;