summaryrefslogtreecommitdiff
path: root/src/html.cpp
blob: 68a880050039039a3d1e41caed59604b57c2c696 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "html.hpp"


TexoProducerHTML::TexoProducerHTML(TexoExporter & exporter):
    TexoProducerStrict(exporter)
{}


bool TexoProducerHTML::TruePut(char c)
{
    switch (c) {
    case '<': return exporter.Put("&lt;");
    case '>': return exporter.Put("&gt;");
    case '&': return exporter.Put("&amp;");
    default:  return exporter.Put(c);
    }
}


bool TexoProducerHTML::StartHeader(int level)
{
    switch (level) {
    case 1:  return exporter.Put("\n<h6>\n");
    case 2:  return exporter.Put("\n<h5>\n");
    case 3:  return exporter.Put("\n<h4>\n");
    case 4:  return exporter.Put("\n<h3>\n");
    case 5:  return exporter.Put("\n<h2>\n");
    default: return exporter.Put("\n<h1>\n");
    }
}

bool TexoProducerHTML::CloseHeader(int level)
{
    switch (level) {
    case 1:  return exporter.Put("\n</h6>\n");
    case 2:  return exporter.Put("\n</h5>\n");
    case 3:  return exporter.Put("\n</h4>\n");
    case 4:  return exporter.Put("\n</h3>\n");
    case 5:  return exporter.Put("\n</h2>\n");
    default: return exporter.Put("\n</h1>\n");
    }
}

bool TexoProducerHTML::StartQuote()
{
    return exporter.Put("\n<blockquote><p>\n");
}

bool TexoProducerHTML::CloseQuote()
{
    return exporter.Put("\n</p></blockquote>\n");
}

bool TexoProducerHTML::StartCode()       { return exporter.Put("\n<pre>\n"); }
bool TexoProducerHTML::CloseCode()       { return exporter.Put("\n</pre>\n"); }

bool TexoProducerHTML::StartParagraph()  { return exporter.Put("\n<p>\n"); }
bool TexoProducerHTML::CloseParagraph()  { return exporter.Put("\n</p>\n"); }


bool TexoProducerHTML::StartBold()       { return exporter.Put("<b>"); }
bool TexoProducerHTML::CloseBold()       { return exporter.Put("</b>"); }

bool TexoProducerHTML::StartItalic()     { return exporter.Put("<i>"); }
bool TexoProducerHTML::CloseItalic()     { return exporter.Put("</i>"); }

bool TexoProducerHTML::StartMono()       { return exporter.Put("<code>"); }
bool TexoProducerHTML::CloseMono()       { return exporter.Put("</code>"); }

bool TexoProducerHTML::StartStrike()     { return exporter.Put("<del>"); }
bool TexoProducerHTML::CloseStrike()     { return exporter.Put("</del>"); }

bool TexoProducerHTML::StartUnderline()  { return exporter.Put("<ins>"); }
bool TexoProducerHTML::CloseUnderline()  { return exporter.Put("</ins>"); }

bool TexoProducerHTML::StartLink(const char *link, const char *title)
{
    if (!link) {
        return true;
    }
    bool ok = exporter.Put("<a href='") && exporter.Put(link);
    if (title) {
        ok = ok && exporter.Put("' title='") && exporter.Put(title);
    }
    return ok && exporter.Put("'>");
}

bool TexoProducerHTML::CloseLink(const char *link, const char *title)
{
    if (!link) {
        return true;
    }
    return exporter.Put("</a>");
}


bool TexoProducerHTML::TruePutImage(const char *src,
                                    const char *alt,
                                    const char *title)
{
    if (!src) {
        return true;
    }
    bool ok = exporter.Put("<img src='") && exporter.Put(src);
    if (alt) {
        ok = ok && exporter.Put("' alt='") && exporter.Put(alt);
    }
    if (title) {
        ok = ok && exporter.Put("' title='") && exporter.Put(title);
    }
    return ok && exporter.Put("'/>");
}

bool TexoProducerHTML::TruePutHorizontalRule()
{
    return exporter.Put("\n<hr/>\n");
}