diff options
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 64 |
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) { |