3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
17 #include "bufferparams.h"
20 #include "paragraph.h"
22 #include "support/lstrings.h"
23 #include "support/std_ostream.h"
24 #include "support/tostr.h"
26 #include <boost/tuple/tuple.hpp>
30 using lyx::support::subst;
35 using std::ostringstream;
41 pair<bool, string> escapeChar(char c)
47 return make_pair(true, string(" "));
49 case '\0': // Ignore :-)
97 return make_pair(false, str);
101 string escapeString(string const & raw)
105 for(string::size_type i = 0; i < raw.size(); ++i) {
108 boost::tie(ws, str) = sgml::escapeChar(raw[i]);
115 void openTag(ostream & os, string const & name, string const & attribute)
117 if (!name.empty() && name != "!-- --") {
119 if (!attribute.empty())
120 os << " " << attribute;
126 void closeTag(ostream & os, string const & name)
128 if (!name.empty() && name != "!-- --")
129 os << "</" << name << '>';
133 void openTag(Buffer const & buf, ostream & os, Paragraph const & par)
135 LyXLayout_ptr const & style = par.layout();
136 string const & name = style->latexname();
137 string param = style->latexparam();
138 Counters & counters = buf.params().getLyXTextClass().counters();
140 string id = par.getDocbookId();
141 id = id.empty()? "" : " id = \"" + id + "\"";
145 if (param.find('#') != string::npos) {
146 string::size_type pos = param.find("id=<");
147 string::size_type end = param.find(">");
148 if( pos != string::npos and end != string::npos)
149 param.erase(pos, end-pos + 1);
151 attribute = id + ' ' + param;
153 if (param.find('#') != string::npos) {
154 if(!style->counter.empty())
155 counters.step(style->counter);
157 counters.step(style->latexname());
158 int i = counters.value(name);
159 attribute = subst(param, "#", tostr(i));
160 attribute = subst(attribute, "<", "\"");
161 attribute = subst(attribute, ">", "\"");
166 openTag(os, name, attribute);
170 void closeTag(ostream & os, Paragraph const & par)
172 LyXLayout_ptr const & style = par.layout();
173 closeTag(os, style->latexname());