summaryrefslogtreecommitdiff
path: root/src/smlrendererhtml.cpp
blob: 372d1e3287ea590b7b60587b3832df8bb8541c46 (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
#include "smlrendererhtml.h"
#include "smlnode.h"

SmlRendererHtml::SmlRendererHtml()
{
}

SmlRendererHtml::~SmlRendererHtml()
{
}

void SmlRendererHtml::render( Bu::Formatter &f, const SmlNode *pSml )
{
	switch( pSml->getType() )
	{
		case SmlNode::typeRoot:
			f << "<p>";
			for( SmlNode::SmlNodeList::const_iterator i =
				 pSml->getChildren().begin(); i; i++ )
			{
				render( f, *i );
			}
			f << "</p>";
			break;

		case SmlNode::typeText:
			f << pSml->getText();
			break;

		case SmlNode::typeTag:
			if( pSml->getChildren().isEmpty() )
			{
				if( pSml->getText() == "break" )
					f << "</p><p>";
			}
			else
			{
				if( pSml->getText() == "red" )
				{
					f << "<span style=\"color: red;\">";
					for( SmlNode::SmlNodeList::const_iterator i =
						 pSml->getChildren().begin(); i; i++ )
					{
						render( f, *i );
					}
					f << "</span>";
				}
				else if( pSml->getText() == "green" )
				{
					f << "<span style=\"color: green;\">";
					for( SmlNode::SmlNodeList::const_iterator i =
						 pSml->getChildren().begin(); i; i++ )
					{
						render( f, *i );
					}
					f << "</span>";
				}
			}
			break;
	}
}