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;
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<<(char);
114 XHTMLStream & operator<<(html::StartTag const &);
116 XHTMLStream & operator<<(html::EndTag const &);
118 XHTMLStream & operator<<(html::CompTag const &);
120 enum EscapeSettings {
122 ESCAPE_AND, // meaning &
123 ESCAPE_ALL // meaning <, >, &, at present
125 /// Sets what we are going to escape on the NEXT write.
126 /// Everything is reset for the next time.
127 XHTMLStream & operator<<(EscapeSettings);
130 void clearTagDeque();
132 bool isTagOpen(std::string const &);
134 void writeError(std::string const &);
138 typedef std::deque<html::StartTag> TagStack;
139 /// holds start tags until we know there is content in them.
140 TagStack pending_tags_;
141 /// remembers the history, so we can make sure we nest properly.
144 EscapeSettings escape_;
148 void xhtmlParagraphs(Text const & text,
151 OutputParams const & runparams);
153 /// \return a string appropriate for setting alignment in CSS
154 /// Does NOT return "justify" for "block"
155 std::string alignmentToCSS(LyXAlignment align);
159 docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e);
160 /// converts a string to a form safe for links, etc
161 docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e);
162 /// cleans \param str for use as an atttribute by replacing
163 /// all non-alnum by "_"
164 docstring cleanAttr(docstring const & str);
166 std::string escapeChar(char c, XHTMLStream::EscapeSettings e);
168 std::string htmlize(std::string const & str, XHTMLStream::EscapeSettings e);
170 std::string cleanAttr(std::string const & str);