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 "LayoutEnums.h"
16 #include "support/docstream.h"
17 #include "support/strfwd.h"
28 // Inspiration for the *Tag structs and for XHTMLStream
29 // came from MathStream and its cousins.
32 /// Attributes will be escaped automatically and so should NOT
33 /// be escaped before being passed to the constructor.
36 explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
38 explicit StartTag(std::string const & tag, std::string const & attr,
39 bool keepempty = false)
40 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
42 docstring asTag() const;
44 docstring asEndTag() const;
49 /// whether to keep things like "<tag></tag>" or discard them
50 /// you would want this for td, e.g, but maybe not for a div
57 explicit EndTag(std::string tag) : tag_(tag) {}
59 docstring asEndTag() const;
66 // We need to allow these to be deferrable, which means it should
67 // inherit from StartTag. This is probably better, anyway, but we'll
68 // need to re-work a bit of code....
70 /// Attributes will be escaped automatically and so should NOT
71 /// be escaped before being passed to the constructor.
74 explicit CompTag(std::string const & tag)
77 explicit CompTag(std::string const & tag, std::string const & attr)
78 : tag_(tag), attr_(attr) {}
80 docstring asTag() const;
92 explicit XHTMLStream(odocstream & os);
96 odocstream & os() { return os_; }
98 // int & tab() { return tab_; }
99 /// closes any font tags that are eligible to be closed,
100 /// i.e., last on the tag_stack_.
101 /// \return false if there are open font tags we could not close.
102 /// because they are "blocked" by open non-font tags on the stack.
103 bool closeFontTags();
105 XHTMLStream & operator<<(docstring const &);
107 XHTMLStream & operator<<(const char *);
109 XHTMLStream & operator<<(char_type);
111 XHTMLStream & operator<<(int);
113 XHTMLStream & operator<<(char);
115 XHTMLStream & operator<<(html::StartTag const &);
117 XHTMLStream & operator<<(html::EndTag const &);
119 XHTMLStream & operator<<(html::CompTag const &);
120 /// A trivial struct that functions as a stream modifier.
121 /// << NextRaw() causes the next string-like thing sent to the
122 /// stream not to be escaped.
125 XHTMLStream & operator<<(NextRaw const &);
128 void clearTagDeque();
130 bool isTagOpen(std::string const &);
132 void writeError(std::string const &);
138 typedef std::deque<html::StartTag> TagDeque;
140 typedef std::vector<html::StartTag> TagStack;
141 /// holds start tags until we know there is content in them.
142 TagDeque pending_tags_;
143 /// remembers the history, so we can make sure we nest properly.
150 void xhtmlParagraphs(Text const & text,
153 OutputParams const & runparams);
155 /// \return a string appropriate for setting alignment in CSS
156 /// Does NOT return "justify" for "block"
157 std::string alignmentToCSS(LyXAlignment align);
161 docstring escapeChar(char_type c);
162 /// converts a string to a form safe for links, etc
163 docstring htmlize(docstring const & str);
164 /// cleans \param str for use as an atttribute by replacing
165 /// all non-alnum by "_"
166 docstring cleanAttr(docstring const & str);
168 std::string escapeChar(char c);
170 std::string htmlize(std::string const & str);
172 std::string cleanAttr(std::string const & str);