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