2002-08-09 00:42:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file sgml.C
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-08-09 00:42:12 +00:00
|
|
|
|
*
|
|
|
|
|
* \author Jos<EFBFBD> Matos
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-08-09 00:42:12 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include <config.h>
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2004-10-24 20:55:22 +00:00
|
|
|
|
#include "sgml.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2004-10-24 20:55:22 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
|
#include "counters.h"
|
|
|
|
|
#include "lyxtext.h"
|
2002-08-09 00:42:12 +00:00
|
|
|
|
#include "paragraph.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2004-10-24 20:55:22 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/std_ostream.h"
|
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
|
2004-10-25 08:25:28 +00:00
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
2004-10-25 08:30:51 +00:00
|
|
|
|
|
2004-10-25 00:26:05 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2004-10-24 20:55:22 +00:00
|
|
|
|
using lyx::support::subst;
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
using std::make_pair;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
using std::ostream;
|
2004-10-25 00:26:05 +00:00
|
|
|
|
using std::ostringstream;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
namespace sgml {
|
|
|
|
|
|
|
|
|
|
pair<bool, string> escapeChar(char c)
|
|
|
|
|
{
|
|
|
|
|
string str;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
switch (c) {
|
|
|
|
|
case ' ':
|
|
|
|
|
return make_pair(true, string(" "));
|
|
|
|
|
break;
|
|
|
|
|
case '\0': // Ignore :-)
|
|
|
|
|
str.erase();
|
|
|
|
|
break;
|
|
|
|
|
case '&':
|
|
|
|
|
str = "&";
|
|
|
|
|
break;
|
|
|
|
|
case '<':
|
|
|
|
|
str = "<";
|
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
str = ">";
|
|
|
|
|
break;
|
2004-05-14 15:47:35 +00:00
|
|
|
|
#if 0
|
2002-08-09 00:42:12 +00:00
|
|
|
|
case '$':
|
|
|
|
|
str = "$";
|
|
|
|
|
break;
|
|
|
|
|
case '#':
|
|
|
|
|
str = "#";
|
|
|
|
|
break;
|
|
|
|
|
case '%':
|
|
|
|
|
str = "%";
|
|
|
|
|
break;
|
|
|
|
|
case '[':
|
|
|
|
|
str = "[";
|
|
|
|
|
break;
|
|
|
|
|
case ']':
|
|
|
|
|
str = "]";
|
|
|
|
|
break;
|
|
|
|
|
case '{':
|
|
|
|
|
str = "{";
|
|
|
|
|
break;
|
|
|
|
|
case '}':
|
|
|
|
|
str = "}";
|
|
|
|
|
break;
|
|
|
|
|
case '~':
|
|
|
|
|
str = "˜";
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
str = """;
|
|
|
|
|
break;
|
|
|
|
|
case '\\':
|
|
|
|
|
str = "\";
|
|
|
|
|
break;
|
2004-05-14 15:47:35 +00:00
|
|
|
|
#endif
|
2002-08-09 00:42:12 +00:00
|
|
|
|
default:
|
|
|
|
|
str = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return make_pair(false, str);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2004-10-25 00:26:05 +00:00
|
|
|
|
string escapeString(string const & raw)
|
|
|
|
|
{
|
|
|
|
|
ostringstream bin;
|
|
|
|
|
|
2004-10-25 08:30:51 +00:00
|
|
|
|
for(string::size_type i = 0; i < raw.size(); ++i) {
|
2004-10-25 00:26:05 +00:00
|
|
|
|
bool ws;
|
|
|
|
|
string str;
|
|
|
|
|
boost::tie(ws, str) = sgml::escapeChar(raw[i]);
|
|
|
|
|
bin << str;
|
|
|
|
|
}
|
|
|
|
|
return bin.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-28 13:07:45 +00:00
|
|
|
|
void openTag(ostream & os, string const & name, string const & attribute)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
{
|
2004-10-24 20:55:22 +00:00
|
|
|
|
if (!name.empty() && name != "!-- --") {
|
|
|
|
|
os << '<' << name;
|
|
|
|
|
if (!attribute.empty())
|
|
|
|
|
os << " " << attribute;
|
2003-11-25 17:23:36 +00:00
|
|
|
|
os << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-28 13:07:45 +00:00
|
|
|
|
void closeTag(ostream & os, string const & name)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
{
|
2004-10-28 13:07:45 +00:00
|
|
|
|
if (!name.empty() && name != "!-- --")
|
2004-10-24 20:55:22 +00:00
|
|
|
|
os << "</" << name << '>';
|
2004-10-28 13:07:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void openTag(Buffer const & buf, ostream & os, Paragraph const & par)
|
|
|
|
|
{
|
|
|
|
|
LyXLayout_ptr const & style = par.layout();
|
|
|
|
|
string const & name = style->latexname();
|
|
|
|
|
string param = style->latexparam();
|
|
|
|
|
Counters & counters = buf.params().getLyXTextClass().counters();
|
|
|
|
|
|
|
|
|
|
string id = par.getDocbookId();
|
|
|
|
|
id = id.empty()? "" : " id = \"" + id + "\"";
|
|
|
|
|
|
|
|
|
|
string attribute;
|
|
|
|
|
if(!id.empty()) {
|
|
|
|
|
if (param.find('#') != string::npos) {
|
|
|
|
|
string::size_type pos = param.find("id=<");
|
|
|
|
|
string::size_type end = param.find(">");
|
|
|
|
|
if( pos != string::npos and end != string::npos)
|
|
|
|
|
param.erase(pos, end-pos + 1);
|
|
|
|
|
}
|
|
|
|
|
attribute = id + ' ' + param;
|
|
|
|
|
} else {
|
|
|
|
|
if (param.find('#') != string::npos) {
|
|
|
|
|
if(!style->counter.empty())
|
|
|
|
|
counters.step(style->counter);
|
|
|
|
|
else
|
|
|
|
|
counters.step(style->latexname());
|
|
|
|
|
int i = counters.value(name);
|
|
|
|
|
attribute = subst(param, "#", tostr(i));
|
|
|
|
|
attribute = subst(attribute, "<", "\"");
|
|
|
|
|
attribute = subst(attribute, ">", "\"");
|
|
|
|
|
} else {
|
|
|
|
|
attribute = param;
|
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
2004-10-28 13:07:45 +00:00
|
|
|
|
openTag(os, name, attribute);
|
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
|
|
|
|
|
|
2004-10-28 13:07:45 +00:00
|
|
|
|
void closeTag(ostream & os, Paragraph const & par)
|
|
|
|
|
{
|
|
|
|
|
LyXLayout_ptr const & style = par.layout();
|
|
|
|
|
closeTag(os, style->latexname());
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
} // namespace sgml
|