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 // We need to allow these to be deferrable, which means it should
65 // inherit from StartTag. This is probably better, anyway, but we'll
66 // need to re-work a bit of code....
68 /// Attributes will be escaped automatically and so should NOT
69 /// be escaped before passing to the constructor.
72 explicit CompTag(std::string const & tag)
75 explicit CompTag(std::string const & tag, std::string const & attr)
76 : tag_(tag), attr_(attr) {}
78 docstring asTag() const;
89 explicit XHTMLStream(odocstream & os);
93 odocstream & os() { return os_; }
95 // int & tab() { return tab_; }
96 /// closes any font tags that are eligible to be closed,
97 /// i.e., last on the tag_stack_.
98 /// \return false if there are open font tags we could not close.
99 /// because they are "blocked" by open non-font tags on the stack.
100 bool closeFontTags();
102 XHTMLStream & operator<<(docstring const &);
104 XHTMLStream & operator<<(const char *);
106 XHTMLStream & operator<<(char_type);
108 XHTMLStream & operator<<(int);
110 XHTMLStream & operator<<(StartTag const &);
112 XHTMLStream & operator<<(EndTag const &);
114 XHTMLStream & operator<<(CompTag const &);
115 /// A trivial struct that functions as a stream modifier.
116 /// << NextRaw() causes the next string-like thing sent to the
117 /// stream not to be escaped.
120 XHTMLStream & operator<<(NextRaw const &);
123 void clearTagDeque();
125 bool isTagOpen(std::string const &);
127 void writeError(std::string const &);
133 typedef std::deque<StartTag> TagDeque;
135 typedef std::vector<StartTag> TagStack;
136 /// holds start tags until we know there is content in them.
137 TagDeque pending_tags_;
138 /// remembers the history, so we can make sure we nest properly.
145 void xhtmlParagraphs(Text const & text,
148 OutputParams const & runparams);
152 docstring escapeChar(char_type c);
153 /// converts a string to a form safe for links, etc
154 docstring htmlize(docstring const & str);
155 /// cleans \param str for use as an atttribute by replacing
156 /// all non-alnum by "_"
157 docstring cleanAttr(docstring const & str);
159 std::string escapeChar(char c);
161 std::string htmlize(std::string const & str);
163 std::string cleanAttr(std::string const & str);
166 /// \return true if tag was opened, false if not
167 bool openTag(odocstream & os, std::string const & tag,
168 std::string const & attr);
169 /// \return true if tag was opened, false if not
170 bool closeTag(odocstream & os, std::string const & tag);