]> git.lyx.org Git - features.git/blob - src/output_xhtml.h
bed9971a30c209a215f04cff3361de5c2782b869
[features.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
17 #include <deque>
18 #include <vector>
19
20 namespace lyx {
21
22 class Buffer;
23 class OutputParams;
24 class Text;
25
26 // Inspiration for the *Tag structs and for XHTMLStream
27 // came from MathStream and its cousins.
28
29 struct StartTag {
30         ///
31         StartTag(std::string const & tag) : tag_(tag) {}
32         ///
33         StartTag(std::string const & tag, std::string const & attr, 
34                 bool keepempty = false) 
35                 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
36         /// <tag_ attr_>
37         docstring asTag() const;
38         /// </tag_>
39         docstring asEndTag() const;
40         ///
41         std::string tag_;
42         ///
43         std::string attr_;
44         /// whether to keep things like "<tag></tag>" or discard them
45         /// you would want this for td, e.g, but maybe not for a div
46         bool keepempty_;
47 };
48
49
50 struct EndTag {
51         ///
52         EndTag(std::string tag) : tag_(tag) {}
53         /// </tag_>
54         docstring asEndTag() const;
55         ///
56         std::string tag_;
57 };
58
59
60 // Tags like <img />
61 struct CompTag {
62         ///
63         CompTag(std::string const & tag)
64                 : tag_(tag) {}
65         ///
66         CompTag(std::string const & tag, std::string const & attr)
67                 : tag_(tag), attr_(attr) {}
68         /// <tag_ attr_ />
69         docstring asTag() const;
70         ///
71         std::string tag_;
72         ///
73         std::string attr_;
74 };
75
76
77 class XHTMLStream {
78 public:
79         ///
80         explicit XHTMLStream(odocstream & os);
81         ///
82         void cr();
83         ///
84         odocstream & os() { return os_; }
85         ///
86         // int & tab() { return tab_; }
87         /// closes any font tags that are eligible to be closed,
88         /// i.e., last on the tag_stack_.
89         /// \return false if there are open font tags we could not close.
90         /// because they are "blocked" by open non-font tags on the stack.
91         bool closeFontTags();
92         ///
93         XHTMLStream & operator<<(docstring const &);
94         ///
95         XHTMLStream & operator<<(const char *);
96         ///
97         XHTMLStream & operator<<(char_type);
98         ///
99         XHTMLStream & operator<<(StartTag const &);
100         ///
101         XHTMLStream & operator<<(EndTag const &);
102         ///
103         XHTMLStream & operator<<(CompTag const &);
104 private:
105         ///
106         void clearTagDeque();
107         ///
108         bool isTagOpen(std::string const &);
109         ///
110         void writeError(std::string const &);
111         ///
112         odocstream & os_;
113         ///
114         // int tab_;
115         ///
116         typedef std::deque<StartTag> TagDeque;
117         ///
118         typedef std::vector<StartTag> TagStack;
119         /// holds start tags until we know there is content in them.
120         TagDeque pending_tags_;
121         /// remembers the history, so we can make sure we nest properly.
122         TagStack tag_stack_;
123 };
124
125 ///
126 void xhtmlParagraphs(Text const & text,
127                        Buffer const & buf,
128                        XHTMLStream & xs,
129                        OutputParams const & runparams);
130
131 namespace html {
132 ///
133 docstring escapeChar(char_type c);
134 /// converts a string to a form safe for links, etc
135 docstring htmlize(docstring const & str);
136
137 // to be removed
138 /// \return true if tag was opened, false if not 
139 bool openTag(odocstream & os, std::string const & tag, 
140                                                  std::string const & attr);
141 /// \return true if tag was opened, false if not 
142 bool closeTag(odocstream & os, std::string const & tag);
143 }
144 } // namespace lyx
145
146 #endif