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.
31 /// Attributes will be escaped automatically and so should NOT
32 /// be escaped before being passed to the constructor.
35 explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
37 explicit StartTag(std::string const & tag, std::string const & attr,
38 bool keepempty = false)
39 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
41 docstring asTag() const;
43 docstring asEndTag() const;
48 /// whether to keep things like "<tag></tag>" or discard them
49 /// you would want this for td, e.g, but maybe not for a div
56 explicit EndTag(std::string tag) : tag_(tag) {}
58 docstring asEndTag() const;
65 // We need to allow these to be deferrable, which means it should
66 // inherit from StartTag. This is probably better, anyway, but we'll
67 // need to re-work a bit of code....
69 /// Attributes will be escaped automatically and so should NOT
70 /// be escaped before being passed to the constructor.
73 explicit CompTag(std::string const & tag)
76 explicit CompTag(std::string const & tag, std::string const & attr)
77 : tag_(tag), attr_(attr) {}
79 docstring asTag() const;
91 explicit XHTMLStream(odocstream & os);
95 odocstream & os() { return os_; }
97 // int & tab() { return tab_; }
98 /// closes any font tags that are eligible to be closed,
99 /// i.e., last on the tag_stack_.
100 /// \return false if there are open font tags we could not close.
101 /// because they are "blocked" by open non-font tags on the stack.
102 bool closeFontTags();
104 XHTMLStream & operator<<(docstring const &);
106 XHTMLStream & operator<<(const char *);
108 XHTMLStream & operator<<(char_type);
110 XHTMLStream & operator<<(int);
112 XHTMLStream & operator<<(html::StartTag const &);
114 XHTMLStream & operator<<(html::EndTag const &);
116 XHTMLStream & operator<<(html::CompTag const &);
117 /// A trivial struct that functions as a stream modifier.
118 /// << NextRaw() causes the next string-like thing sent to the
119 /// stream not to be escaped.
122 XHTMLStream & operator<<(NextRaw const &);
125 void clearTagDeque();
127 bool isTagOpen(std::string const &);
129 void writeError(std::string const &);
135 typedef std::deque<html::StartTag> TagDeque;
137 typedef std::vector<html::StartTag> TagStack;
138 /// holds start tags until we know there is content in them.
139 TagDeque pending_tags_;
140 /// remembers the history, so we can make sure we nest properly.
147 void xhtmlParagraphs(Text const & text,
150 OutputParams const & runparams);
154 docstring escapeChar(char_type c);
155 /// converts a string to a form safe for links, etc
156 docstring htmlize(docstring const & str);
157 /// cleans \param str for use as an atttribute by replacing
158 /// all non-alnum by "_"
159 docstring cleanAttr(docstring const & str);
161 std::string escapeChar(char c);
163 std::string htmlize(std::string const & str);
165 std::string cleanAttr(std::string const & str);