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 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:25:28 +00:00
|
|
|
|
for(unsigned int 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-24 20:55:22 +00:00
|
|
|
|
int openTag(Buffer const & buf, ostream & os, Paragraph::depth_type depth,
|
|
|
|
|
bool mixcont, string const & name, string const & param)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
{
|
2004-10-24 20:55:22 +00:00
|
|
|
|
Counters & counters = buf.params().getLyXTextClass().counters();
|
|
|
|
|
LyXLayout_ptr const & defaultstyle = buf.params().getLyXTextClass().defaultLayout();
|
|
|
|
|
|
|
|
|
|
string attribute = param;
|
|
|
|
|
// code for paragraphs like the standard paragraph in AGU.
|
|
|
|
|
if ( defaultstyle->latexname() == name and !defaultstyle->latexparam().empty()) {
|
|
|
|
|
counters.step(name);
|
|
|
|
|
int i = counters.value(name);
|
|
|
|
|
attribute += "" + subst(defaultstyle->latexparam(), "#", tostr(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!name.empty() && name != "!-- --") {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
if (!mixcont)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << string(depth, ' ');
|
2004-10-24 20:55:22 +00:00
|
|
|
|
os << '<' << name;
|
|
|
|
|
if (!attribute.empty())
|
|
|
|
|
os << " " << attribute;
|
2003-11-25 17:23:36 +00:00
|
|
|
|
os << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int closeTag(ostream & os, Paragraph::depth_type depth,
|
2004-10-24 20:55:22 +00:00
|
|
|
|
bool mixcont, string const & name)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
{
|
2004-10-24 20:55:22 +00:00
|
|
|
|
if (!name.empty() && name != "!-- --") {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
if (!mixcont)
|
2004-10-24 00:02:39 +00:00
|
|
|
|
os << '\n' << string(depth, ' ');
|
2004-10-24 20:55:22 +00:00
|
|
|
|
os << "</" << name << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixcont)
|
2004-10-24 00:02:39 +00:00
|
|
|
|
os << '\n';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
} // namespace sgml
|