]> git.lyx.org Git - lyx.git/blob - src/output_xhtml.h
Shortcut for LyX HTML output. (Makes my life easier!)
[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 // 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, std::string const & attr)
64                 : tag_(tag), attr_(attr) {}
65         /// <tag_ attr_ />
66         docstring asTag() const;
67         ///
68         std::string tag_;
69         ///
70         std::string attr_;
71 };
72
73
74 class XHTMLStream {
75 public:
76         ///
77         explicit XHTMLStream(odocstream & os);
78         ///
79         void cr();
80         ///
81         odocstream & os() { return os_; }
82         ///
83         // int & tab() { return tab_; }
84         /// closes any font tags that are eligible to be closed,
85         /// i.e., last on the tag_stack_.
86         /// \return false if there are open font tags we could not close.
87         /// because they are "blocked" by open non-font tags on the stack.
88         bool closeFontTags();
89         ///
90         XHTMLStream & operator<<(docstring const &);
91         ///
92         XHTMLStream & operator<<(const char *);
93         ///
94         XHTMLStream & operator<<(char_type);
95         ///
96         XHTMLStream & operator<<(StartTag const &);
97         ///
98         XHTMLStream & operator<<(EndTag const &);
99         ///
100         XHTMLStream & operator<<(CompTag const &);
101 private:
102         ///
103         void clearTagDeque();
104         ///
105         bool isTagOpen(std::string const &);
106         ///
107         void writeError(std::string const &);
108         ///
109         odocstream & os_;
110         ///
111         // int tab_;
112         ///
113         typedef std::deque<StartTag> TagDeque;
114         ///
115         typedef std::vector<StartTag> TagStack;
116         /// holds start tags until we know there is content in them.
117         TagDeque pending_tags_;
118         /// remembers the history, so we can make sure we nest properly.
119         TagStack tag_stack_;
120 };
121
122 ///
123 void xhtmlParagraphs(Text const & text,
124                        Buffer const & buf,
125                        XHTMLStream & xs,
126                        OutputParams const & runparams);
127
128 namespace html {
129 ///
130 docstring escapeChar(char_type c);
131 /// converts a string to a form safe for links, etc
132 docstring htmlize(docstring const & str);
133
134 // to be removed
135 /// \return true if tag was opened, false if not 
136 bool openTag(odocstream & os, std::string const & tag, 
137                                                  std::string const & attr);
138 /// \return true if tag was opened, false if not 
139 bool closeTag(odocstream & os, std::string const & tag);
140 }
141 } // namespace lyx
142
143 #endif