source: trunk/lib/html_utility.cc @ 179

Last change on this file since 179 was 179, checked in by Peter Johansson, 17 years ago

added support for åäöÅÄÖé in html generator

File size: 4.7 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2006 Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "utility.h"
25
26#include <fstream>
27#include <iostream> // remove this when 'blame' is removed
28#include <sstream>
29#include <stdexcept>
30#include <string>
31#include <sys/param.h>
32#include <unistd.h>
33
34namespace theplu{
35namespace svndigest{
36
37  void anchor(std::ostream& os, const std::string& href, 
38              const std::string& name, u_int level, 
39              const std::string& title)
40  {
41    os << "<a title=\"" << title << "\" href=\"" ;
42    for (size_t i=0; i<level; ++i)
43      os << "../";
44    os << href << "\">" << name << "</a>";
45  }
46
47
48 
49  void html(std::istream& is, std::ostream& os, char delim) 
50  {
51    char c;
52    while (true){
53      is.get(c);
54      if (c==delim || !is.good()){
55        return;
56      }
57      if (c=='"')
58        os << '\"';
59      else if (c=='\'')
60        os << "\'";
61      else if (c=='\n')
62        os << "<br/>";
63      else if (c=='<')
64        os << "&lt;";
65      else if (c=='>')
66        os << "&gt;";
67      else if (c=='&')
68        os << "&amp;";
69      else if (c=='\t')
70        os << "&nbsp;&nbsp;";
71      else if (c=='å')
72        os << "&aring;";
73      else if (c=='ä')
74        os << "&auml;";
75      else if (c=='ö')
76        os << "&ouml;";
77      else if (c=='Å')
78        os << "&Aring;";
79      else if (c=='Ä')
80        os << "&Auml;";
81      else if (c=='Ö')
82        os << "&Ouml;";
83      else if (c=='é')
84        os << "&eacute;";
85      else
86        os << c;
87    }
88  }
89 
90
91  void print_css(std::ostream& s)
92  {
93    s << "body {\n";
94    s << " background: #fff; \n";
95    s << " color: #000; \n";
96    s << " margin: 0px; \n";
97    s << " padding: 0; \n";
98    s << "} \n";
99    s << "\n";
100    s << "#menu {\n";
101    s << " background: #eee;\n";
102    s << " width: 100%;\n";
103    s << " margin: 0px;\n";
104    s << " padding: 0px;\n";
105    s << "}\n\n";
106    s << "#menu ul\n";
107    s << "{ \n";
108    s << "padding: 0px;\n";
109    s << "margin: 0px;list-style-type: none; text-align: center;"
110      << "border-bottom: 1px solid black;}\n";
111    s << "#menu ul li { display: inline; border-right: 1px solid black;}\n";
112    s << "#menu ul li a {text-decoration: none; padding-right: 1em;" 
113      << "padding-left: 1em; margin: 0px;}\n";
114    s << "#menu ul li a:hover{ color: #000; background: #ddd;}\n";
115    s << "\n";
116    s << "#main {\n";
117    s << " margin: 10px; \n";
118    s << "}\n";
119    s << "\n";
120    s << "body, th, td {\n";
121    s << " font: normal 13px verdana,arial,'Bitstream Vera Sans',"
122      << "helvetica,sans-serif;\n";
123    s << "}\n";
124    s << ":link, :visited {\n";
125    s << " text-decoration: none;\n";
126    s << " color: #b00;\n";
127    s << "}\n";
128    s << "\n";
129    s << "table.listings {\n";
130    s << " clear: both;\n";
131    s << " border-bottom: 1px solid #d7d7d7;\n";
132    s << " border-collapse: collapse;\n";
133    s << " border-spacing: 0;\n";
134    s << " margin-top: 1em;\n";
135    s << " width: 100%;\n";
136    s << "}\n";
137    s << "\n";
138    s << "table.listings th {\n";
139    s << " text-align: left;\n";
140    s << " padding: 0 1em .1em 0;\n";
141    s << " font-size: 12px\n";
142    s << "}\n";
143    s << "table.listings thead { background: #f7f7f0 }\n";
144    s << "table.listings thead th {\n";
145    s << " border: 1px solid #d7d7d7;\n";
146    s << " border-bottom-color: #999;\n";
147    s << " font-size: 11px;\n";
148    s << " font-wheight: bold;\n";
149    s << " padding: 2px .5em;\n";
150    s << " vertical-align: bottom;\n";
151    s << "}\n";
152    s << "\n";
153    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
154    s << " background-color: transparent;\n";
155    s << "}\n";
156    s << "\n";
157    s << "table.listings tbody td, table.listing tbody th {\n";
158    s << " border: 1px dotted #ddd;\n";
159    s << " padding: .33em .5em;\n";
160    s << " vertical-align: top;\n";
161    s << "}\n";
162    s << "\n";
163    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
164    s << " background-color: transparent;\n";
165    s << "}\n";
166    s << "table.listings tbody tr { border-top: 1px solid #ddd }\n";
167    s << "table.listings tbody tr.light { background-color: #fcfcfc }\n";
168    s << "table.listings tbody tr.dark { background-color: #f7f7f7 }\n";
169    s << "table.listings tbody tr:hover { background: #eed }\n";
170    s << "table.listings tbody td { text-align: left }\n";
171    s << "\n";
172    s << ".sep { color: #666}\n";
173    s << "\n";
174    s << "\n";
175  }
176
177
178}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.