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