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"
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;
86 // trivial struct for output of newlines
94 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();
104 /// call at start of paragraph. sets a mark so we know what tags
105 /// to close at the end.
106 void startParagraph();
107 /// call at end of paragraph to clear that mark. note that this
108 /// will also close any tags still open.
111 XHTMLStream & operator<<(docstring const &);
113 XHTMLStream & operator<<(const char *);
115 XHTMLStream & operator<<(char_type);
117 XHTMLStream & operator<<(int);
119 XHTMLStream & operator<<(char);
121 XHTMLStream & operator<<(html::StartTag const &);
123 XHTMLStream & operator<<(html::EndTag const &);
125 XHTMLStream & operator<<(html::CompTag const &);
127 XHTMLStream & operator<<(html::CR const &);
129 enum EscapeSettings {
131 ESCAPE_AND, // meaning &
132 ESCAPE_ALL // meaning <, >, &, at present
134 /// Sets what we are going to escape on the NEXT write.
135 /// Everything is reset for the next time.
136 XHTMLStream & operator<<(EscapeSettings);
139 void clearTagDeque();
141 bool isTagOpen(std::string const &);
143 void writeError(std::string const &);
147 typedef std::deque<html::StartTag> TagStack;
148 /// holds start tags until we know there is content in them.
149 TagStack pending_tags_;
150 /// remembers the history, so we can make sure we nest properly.
153 EscapeSettings escape_;
157 void xhtmlParagraphs(Text const & text,
160 OutputParams const & runparams);
162 /// \return a string appropriate for setting alignment in CSS
163 /// Does NOT return "justify" for "block"
164 std::string alignmentToCSS(LyXAlignment align);
168 docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e);
169 /// converts a string to a form safe for links, etc
170 docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e);
171 /// cleans \param str for use as an atttribute by replacing
172 /// all non-alnum by "_"
173 docstring cleanAttr(docstring const & str);
175 std::string escapeChar(char c, XHTMLStream::EscapeSettings e);
177 std::string htmlize(std::string const & str, XHTMLStream::EscapeSettings e);
179 std::string cleanAttr(std::string const & str);