From 949bc6fd1b2f34009ffb9f1fa951bbdd1b5b517c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 22 Apr 2020 13:53:43 -0400 Subject: Render id, description and language as
 attributes

---
 archive.h |  2 +-
 html.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++------------------
 parse.c   |  8 ++++----
 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(
-		
[content]
- ); - 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 ->
+ // TODO: Process diffs -> , + return 0 + || templateRender(file, TEMPLATE(), NULL, NULL) + || escapeXML(file, content) + || templateRender(file, TEMPLATE(
), 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; -- cgit 1.4.1