]> git.lyx.org Git - lyx.git/blob - src/output_xhtml.h
Compil fix
[lyx.git] / src / output_xhtml.h
1 // -*- C++ -*-
2 /**
3  * \file output_xhtml.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Richard Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef OUTPUT_XHTML_H
13 #define OUTPUT_XHTML_H
14
15 #include "LayoutEnums.h"
16 #include "support/docstream.h"
17 #include "support/strfwd.h"
18
19 #include <deque>
20 #include <vector>
21
22 namespace lyx {
23
24 class Buffer;
25 class OutputParams;
26 class Text;
27
28 // Inspiration for the *Tag structs and for XHTMLStream
29 // came from MathStream and its cousins.
30
31 namespace html {
32 /// Attributes will be escaped automatically and so should NOT
33 /// be escaped before being passed to the constructor.
34 struct StartTag {
35         ///
36         explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
37         ///
38         explicit StartTag(std::string const & tag, std::string const & attr, 
39                 bool keepempty = false) 
40                 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
41         /// <tag_ attr_>
42         docstring asTag() const;
43         /// </tag_>
44         docstring asEndTag() const;
45         ///
46         std::string tag_;
47         ///
48         std::string attr_;
49         /// whether to keep things like "<tag></tag>" or discard them
50         /// you would want this for td, e.g, but maybe not for a div
51         bool keepempty_;
52 };
53
54
55 struct EndTag {
56         ///
57         explicit EndTag(std::string tag) : tag_(tag) {}
58         /// </tag_>
59         docstring asEndTag() const;
60         ///
61         std::string tag_;
62 };
63
64
65 // FIXME XHTML
66 // We need to allow these to be deferrable, which means it should
67 // inherit from StartTag. This is probably better, anyway, but we'll
68 // need to re-work a bit of code....
69 /// Tags like <img />
70 /// Attributes will be escaped automatically and so should NOT
71 /// be escaped before being passed to the constructor.
72 struct CompTag {
73         ///
74         explicit CompTag(std::string const & tag)
75                 : tag_(tag) {}
76         ///
77         explicit CompTag(std::string const & tag, std::string const & attr)
78                 : tag_(tag), attr_(attr) {}
79         /// <tag_ attr_ />
80         docstring asTag() const;
81         ///
82         std::string tag_;
83         ///
84         std::string attr_;
85 };
86
87 } // namespace html
88
89 class XHTMLStream {
90 public:
91         ///
92         explicit XHTMLStream(odocstream & os);
93         ///
94         void cr();
95         ///
96         odocstream & os() { return os_; }
97         ///
98         // int & tab() { return tab_; }
99         /// closes any font tags that are eligible to be closed,
100         /// i.e., last on the tag_stack_.
101         /// \return false if there are open font tags we could not close.
102         /// because they are "blocked" by open non-font tags on the stack.
103         bool closeFontTags();
104         ///
105         XHTMLStream & operator<<(docstring const &);
106         ///
107         XHTMLStream & operator<<(const char *);
108         ///
109         XHTMLStream & operator<<(char_type);
110         ///
111         XHTMLStream & operator<<(int);
112         ///
113         XHTMLStream & operator<<(char);
114         ///
115         XHTMLStream & operator<<(html::StartTag const &);
116         ///
117         XHTMLStream & operator<<(html::EndTag const &);
118         ///
119         XHTMLStream & operator<<(html::CompTag const &);
120         /// A trivial struct that functions as a stream modifier.
121         /// << NextRaw() causes the next string-like thing sent to the
122         /// stream not to be escaped.
123         struct NextRaw {};
124         ///
125         XHTMLStream & operator<<(NextRaw const &);
126 private:
127         ///
128         void clearTagDeque();
129         ///
130         bool isTagOpen(std::string const &);
131         ///
132         void writeError(std::string const &);
133         ///
134         odocstream & os_;
135         ///
136         // int tab_;
137         ///
138         typedef std::deque<html::StartTag> TagDeque;
139         ///
140         typedef std::vector<html::StartTag> TagStack;
141         /// holds start tags until we know there is content in them.
142         TagDeque pending_tags_;
143         /// remembers the history, so we can make sure we nest properly.
144         TagStack tag_stack_;
145         /// 
146         bool nextraw_;
147 };
148
149 ///
150 void xhtmlParagraphs(Text const & text,
151                        Buffer const & buf,
152                        XHTMLStream & xs,
153                        OutputParams const & runparams);
154
155 /// \return a string appropriate for setting alignment in CSS
156 /// Does NOT return "justify" for "block"
157 std::string alignmentToCSS(LyXAlignment align);
158
159 namespace html {
160 ///
161 docstring escapeChar(char_type c);
162 /// converts a string to a form safe for links, etc
163 docstring htmlize(docstring const & str);
164 /// cleans \param str for use as an atttribute by replacing
165 /// all non-alnum by "_"
166 docstring cleanAttr(docstring const & str);
167 ///
168 std::string escapeChar(char c);
169 /// 
170 std::string htmlize(std::string const & str);
171 /// 
172 std::string cleanAttr(std::string const & str);
173
174 } // namespace html
175 } // namespace lyx
176
177 #endif