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