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
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
#include "paragraph.h"
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include "sgml.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
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;
|
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-11-04 02:12:42 +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;
|
|
|
|
|
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;
|
|
|
|
|
default:
|
|
|
|
|
str = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return make_pair(false, str);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
int openTag(ostream & os, Paragraph::depth_type depth,
|
2003-11-25 17:23:36 +00:00
|
|
|
|
bool mixcont, string const & latexname,
|
|
|
|
|
string const & latexparam)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (!latexname.empty() && latexname != "!-- --") {
|
|
|
|
|
if (!mixcont)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << string(depth, ' ');
|
2003-11-25 17:23:36 +00:00
|
|
|
|
os << '<' << latexname;
|
|
|
|
|
if (!latexparam.empty())
|
|
|
|
|
os << " " << latexparam;
|
|
|
|
|
os << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixcont)
|
|
|
|
|
os << endl;
|
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int closeTag(ostream & os, Paragraph::depth_type depth,
|
|
|
|
|
bool mixcont, string const & latexname)
|
|
|
|
|
{
|
|
|
|
|
if (!latexname.empty() && latexname != "!-- --") {
|
|
|
|
|
if (!mixcont)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << endl << string(depth, ' ');
|
|
|
|
|
os << "</" << latexname << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixcont)
|
|
|
|
|
os << endl;
|
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-29 13:48:21 +00:00
|
|
|
|
|
2003-11-21 17:31:46 +00:00
|
|
|
|
unsigned int closeEnvTags(ostream & os, bool mixcont,
|
2003-10-29 13:48:21 +00:00
|
|
|
|
string const & environment_inner_depth,
|
2003-11-25 17:23:36 +00:00
|
|
|
|
string const & itemtag,
|
2003-10-29 13:48:21 +00:00
|
|
|
|
lyx::depth_type total_depth)
|
|
|
|
|
{
|
2003-11-21 17:31:46 +00:00
|
|
|
|
unsigned int lines = 0;
|
2003-10-29 13:48:21 +00:00
|
|
|
|
if (environment_inner_depth != "!-- --") {
|
2003-11-25 17:23:36 +00:00
|
|
|
|
lines += closeTag(os, total_depth, mixcont, itemtag);
|
|
|
|
|
if (!environment_inner_depth.empty())
|
2003-11-21 17:31:46 +00:00
|
|
|
|
lines += closeTag(os, total_depth, mixcont,
|
2003-10-29 13:48:21 +00:00
|
|
|
|
environment_inner_depth);
|
|
|
|
|
}
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
} // namespace sgml
|