4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef OUTPUT_XHTML_H
13 #define OUTPUT_XHTML_H
15 #include "support/docstream.h"
16 #include "support/strfwd.h"
27 // Inspiration for the *Tag structs and for XHTMLStream
28 // came from MathStream and its cousins.
30 /// Attributes will be escaped automatically and so should NOT
31 /// be escaped before passing to the constructor.
34 explicit StartTag(std::string const & tag) : tag_(tag) {}
36 explicit StartTag(std::string const & tag, std::string const & attr,
37 bool keepempty = false)
38 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
40 docstring asTag() const;
42 docstring asEndTag() const;
47 /// whether to keep things like "<tag></tag>" or discard them
48 /// you would want this for td, e.g, but maybe not for a div
55 explicit EndTag(std::string tag) : tag_(tag) {}
57 docstring asEndTag() const;
64 /// Attributes will be escaped automatically and so should NOT
65 /// be escaped before passing to the constructor.
68 explicit CompTag(std::string const & tag)
71 explicit CompTag(std::string const & tag, std::string const & attr)
72 : tag_(tag), attr_(attr) {}
74 docstring asTag() const;
85 explicit XHTMLStream(odocstream & os);
89 odocstream & os() { return os_; }
91 // int & tab() { return tab_; }
92 /// closes any font tags that are eligible to be closed,
93 /// i.e., last on the tag_stack_.
94 /// \return false if there are open font tags we could not close.
95 /// because they are "blocked" by open non-font tags on the stack.
98 XHTMLStream & operator<<(docstring const &);
100 XHTMLStream & operator<<(const char *);
102 XHTMLStream & operator<<(char_type);
104 XHTMLStream & operator<<(StartTag const &);
106 XHTMLStream & operator<<(EndTag const &);
108 XHTMLStream & operator<<(CompTag const &);
109 /// A trivial struct that functions as a stream modifier.
110 /// << NextRaw() causes the next string-like thing sent to the
111 /// stream not to be escaped.
114 XHTMLStream & operator<<(NextRaw const &);
117 void clearTagDeque();
119 bool isTagOpen(std::string const &);
121 void writeError(std::string const &);
127 typedef std::deque<StartTag> TagDeque;
129 typedef std::vector<StartTag> TagStack;
130 /// holds start tags until we know there is content in them.
131 TagDeque pending_tags_;
132 /// remembers the history, so we can make sure we nest properly.
139 void xhtmlParagraphs(Text const & text,
142 OutputParams const & runparams);
146 docstring escapeChar(char_type c);
147 /// converts a string to a form safe for links, etc
148 docstring htmlize(docstring const & str);
149 /// cleans \param str for use as an atttribute by replacing
150 /// all non-alnum by "_"
151 docstring cleanAttr(docstring const & str);
153 std::string escapeChar(char c);
155 std::string htmlize(std::string const & str);
157 std::string cleanAttr(std::string const & str);
160 /// \return true if tag was opened, false if not
161 bool openTag(odocstream & os, std::string const & tag,
162 std::string const & attr);
163 /// \return true if tag was opened, false if not
164 bool closeTag(odocstream & os, std::string const & tag);