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 // This should be fixed in layout files later.
118 string param = subst(attribute, "<", "\"");
119 param = subst(param, ">", "\"");
121 if (!name.empty() && name != "!-- --") {
130 void closeTag(ostream & os, string const & name)
132 if (!name.empty() && name != "!-- --")
133 os << "</" << name << '>';
137 void openTag(Buffer const & buf, ostream & os, Paragraph const & par)
139 LyXLayout_ptr const & style = par.layout();
140 string const & name = style->latexname();
141 string param = style->latexparam();
142 Counters & counters = buf.params().getLyXTextClass().counters();
144 string id = par.getDocbookId();
145 id = id.empty()? "" : " id = \"" + id + "\"";
149 if (param.find('#') != string::npos) {
150 string::size_type pos = param.find("id=<");
151 string::size_type end = param.find(">");
152 if( pos != string::npos and end != string::npos)
153 param.erase(pos, end-pos + 1);
155 attribute = id + ' ' + param;
157 if (param.find('#') != string::npos) {
158 if(!style->counter.empty())
159 counters.step(style->counter);
161 counters.step(style->latexname());
162 int i = counters.value(name);
163 attribute = subst(param, "#", tostr(i));
168 openTag(os, name, attribute);
172 void closeTag(ostream & os, Paragraph const & par)
174 LyXLayout_ptr const & style = par.layout();
175 closeTag(os, style->latexname());