diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-04-25 19:50:47 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2019-04-25 19:53:38 +0200 |
commit | 48372db7f6d048e77e169c520bdb51e43f9c1702 (patch) | |
tree | e093e7aacc079df3e7bc309005dc3064d755dc7c | |
parent | 5a5f26540bf525d23b4650e0b558e0cdaedcd396 (diff) |
sfeed_atom: add content too (for completeness)
-rw-r--r-- | sfeed_atom.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sfeed_atom.c b/sfeed_atom.c index 3040b8c..69d946d 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -14,6 +14,29 @@ static char *line; static size_t linesize; static void +printcontent(const char *s) +{ + for (; *s; ++s) { + switch (*s) { + case '<': fputs("<", stdout); break; + case '>': fputs(">", stdout); break; + case '\'': fputs("'", stdout); break; + case '&': fputs("&", stdout); break; + case '"': fputs(""", stdout); break; + case '\\': + s++; + switch (*s) { + case 'n': putchar('\n'); break; + case '\\': putchar('\\'); break; + case 't': putchar('\t'); break; + } + break; + default: putchar(*s); + } + } +} + +static void printfeed(FILE *fp, const char *feedname) { char *fields[FieldLast]; @@ -59,6 +82,18 @@ printfeed(FILE *fp, const char *feedname) xmlencode(fields[FieldAuthor], stdout); fputs("</name></author>\n", stdout); } + if (fields[FieldContent][0]) { + if (!strcmp(fields[FieldContentType], "html")) { + fputs("\t<content type=\"html\">", stdout); + } else { + /* NOTE: an RSS/Atom viewer may or may not format + whitespace such as newlines. + Workaround: type="html" and <![CDATA[<pre></pre>]]> */ + fputs("\t<content type=\"text\">", stdout); + } + printcontent(fields[FieldContent]); + fputs("</content>\n", stdout); + } fputs("</entry>\n", stdout); } } |