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"
26 // Inspiration for the *Tag structs and for XHTMLStream
27 // came from MathStream and its cousins.
31 StartTag(std::string const & tag) : tag_(tag) {}
33 StartTag(std::string const & tag, std::string const & attr,
34 bool keepempty = false)
35 : tag_(tag), attr_(attr), keepempty_(keepempty) {}
37 docstring asTag() const;
39 docstring asEndTag() const;
44 /// whether to keep things like "<tag></tag>" or discard them
45 /// you would want this for td, e.g, but maybe not for a div
52 EndTag(std::string tag) : tag_(tag) {}
54 docstring asEndTag() const;
63 CompTag(std::string const & tag)
66 CompTag(std::string const & tag, std::string const & attr)
67 : tag_(tag), attr_(attr) {}
69 docstring asTag() const;
80 explicit XHTMLStream(odocstream & os);
84 odocstream & os() { return os_; }
86 // int & tab() { return tab_; }
87 /// closes any font tags that are eligible to be closed,
88 /// i.e., last on the tag_stack_.
89 /// \return false if there are open font tags we could not close.
90 /// because they are "blocked" by open non-font tags on the stack.
93 XHTMLStream & operator<<(docstring const &);
95 XHTMLStream & operator<<(const char *);
97 XHTMLStream & operator<<(char_type);
99 XHTMLStream & operator<<(StartTag const &);
101 XHTMLStream & operator<<(EndTag const &);
103 XHTMLStream & operator<<(CompTag const &);
104 /// A trivial struct that functions as a stream modifier.
105 /// << NextRaw() causes the next string-like thing sent to the
106 /// stream not to be escaped.
109 XHTMLStream & operator<<(NextRaw const &);
112 void clearTagDeque();
114 bool isTagOpen(std::string const &);
116 void writeError(std::string const &);
122 typedef std::deque<StartTag> TagDeque;
124 typedef std::vector<StartTag> TagStack;
125 /// holds start tags until we know there is content in them.
126 TagDeque pending_tags_;
127 /// remembers the history, so we can make sure we nest properly.
134 void xhtmlParagraphs(Text const & text,
137 OutputParams const & runparams);
141 docstring escapeChar(char_type c);
142 /// converts a string to a form safe for links, etc
143 docstring htmlize(docstring const & str);
146 /// \return true if tag was opened, false if not
147 bool openTag(odocstream & os, std::string const & tag,
148 std::string const & attr);
149 /// \return true if tag was opened, false if not
150 bool closeTag(odocstream & os, std::string const & tag);