summaryrefslogtreecommitdiff
path: root/src/backend/filters/bt_plainhtml.cpp
blob: 4ee98b4835a5633e8e2b4f4d46c1299758c134e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "bt_plainhtml.h"

Filters::BT_PLAINHTML::BT_PLAINHTML() : sword::SWFilter() {
}

/** No descriptions */
char Filters::BT_PLAINHTML::processText(sword::SWBuf& text, const sword::SWKey* /*key*/, const sword::SWModule* /*module*/) {
	int count = 0;

	sword::SWBuf orig = text;
	const char *from = orig.c_str();
	for (text = ""; *from; from++) 
	{
		if ((*from == '\n') && (from[1] == '\n')) // two newlinea are a paragraph
		{
			text += "<P>";
			from++;
			continue;
		}
		//This is a special case: Newlines in the plaintext editor are stored as <br />, not as \n
		//we need to let them through
		else if ((*from == '<') && (from[1] == 'b') && (from[2] == 'r') && (from[3] == ' ') && (from[4] == '/') && (from[5] == '>')){
			text += "<br />";
			from += 5;
			continue;
		}
		else if ((*from == '\n')){ // only one new line
			text += "<BR>";
			continue;
		}
		else if (*from == '<') {
			text += "&lt;";
			continue;
		}
		else if (*from == '>') {
			text += "&gt;";
			continue;
		}
		else if (*from == '&'){
			text += "&amp;";
			continue;
		}
		else if (*from == '{') { //footnote start
            text += "<FONT COLOR=\"#800000\"><SMALL> ("; /// \bug Possible color conflict
			continue;
		}
		else if (*from == '}') //footnote end
		{
			text += ") </SMALL></FONT>";
			continue;
		}
		else if ((*from == ' ') && (count > 5000))
		{
			text += "<WBR>";
			count = 0;
			continue;
		}

		text += *from;
		count++;
	}
	return 0;
}