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