2 * Convert text/plain to text/html
4 * Copyright (c) 2017-2018 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
19 * Convert a text/plain message to text/html
21 StrBuf *text2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source)
30 StrBufAppendPrintf(sj, "<pre>");
31 StrEscAppend(sj, Source, NULL, 0, 0); // FIXME - add code here to activate links
32 StrBufAppendPrintf(sj, "</pre>\n");
39 * Convert a text/x-citadel-variformat message to text/html
41 StrBuf *variformat2html(StrBuf *Source)
43 StrBuf *Target = NULL;
50 const char *ptr, *pte;
51 const char *BufPtr = NULL;
52 StrBuf *Line = NewStrBufPlain(NULL, SIZ);
53 StrBuf *Line1 = NewStrBufPlain(NULL, SIZ);
54 StrBuf *Line2 = NewStrBufPlain(NULL, SIZ);
61 if (StrLength(Source) > 0)
64 StrBufSipLine(Line, Source, &BufPtr);
68 len = StrLength(Line);
71 if ((intext == 1) && (isspace(*ptr))) {
72 StrBufAppendBufPlain(Target, HKEY("<br>"), 0);
76 while ((ptr < pte) && ((*ptr == '>') || isspace(*ptr))) {
86 * Quoted text should be displayed in italics and in a
87 * different colour. This code understands Citadel-style
88 * " >" quotes and will convert to <BLOCKQUOTE> tags.
90 if (i > 0) StrBufCutLeft(Line, i);
92 for (i = bn; i < bq; i++)
93 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
94 for (i = bq; i < bn; i++)
95 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
98 if (StrLength(Line) == 0)
101 /* Activate embedded URL's */
102 UrlizeText(Line1, Line, Line2);
104 StrEscAppend(Target, Line1, NULL, 0, 0);
106 StrBufAppendBufPlain(Target, HKEY("\n"), 0);
108 while ((BufPtr != StrBufNOTNULL) &&
111 for (i = 0; i < bn; i++) {
112 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
114 StrBufAppendBufPlain(Target, HKEY("<br>\n"), 0);