mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
more code uniffied for handling paragraph ids. (docbook)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9137 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c984a235eb
commit
24b6402897
@ -1,3 +1,12 @@
|
||||
2004-10-25 José Matos <jamatos@lyx.org>
|
||||
|
||||
* buffer.C (makeLinuxDocFile, makeDocBookFile):
|
||||
* output_docbook.C (makeParagraph, makeEnvironment, makeCommand):
|
||||
* output_linuxdoc.C (linuxdocParagraphs): use new openTag and closeTag.
|
||||
|
||||
* sgml.[Ch]: new version for open and closeTag for paragraph and
|
||||
for strings. Now they handle the ids of paragraphs.
|
||||
|
||||
2004-10-26 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* Makefile.am: add mover.[Ch].
|
||||
|
10
src/buffer.C
10
src/buffer.C
@ -1032,12 +1032,12 @@ void Buffer::makeLinuxDocFile(string const & fname,
|
||||
ofs << ">\n\n";
|
||||
|
||||
if (params().options.empty())
|
||||
sgml::openTag(*this, ofs, 0, false, top_element);
|
||||
sgml::openTag(ofs, top_element);
|
||||
else {
|
||||
string top = top_element;
|
||||
top += ' ';
|
||||
top += params().options;
|
||||
sgml::openTag(*this, ofs, 0, false, top);
|
||||
sgml::openTag(ofs, top);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1049,7 +1049,7 @@ void Buffer::makeLinuxDocFile(string const & fname,
|
||||
|
||||
if (!body_only) {
|
||||
ofs << "\n\n";
|
||||
sgml::closeTag(ofs, 0, false, top_element);
|
||||
sgml::closeTag(ofs, top_element);
|
||||
}
|
||||
|
||||
ofs.close();
|
||||
@ -1126,10 +1126,10 @@ void Buffer::makeDocBookFile(string const & fname,
|
||||
|
||||
params().getLyXTextClass().counters().reset();
|
||||
|
||||
sgml::openTag(*this, ofs, 0, false, top);
|
||||
sgml::openTag(ofs, top);
|
||||
ofs << '\n';
|
||||
docbookParagraphs(paragraphs(), *this, ofs, runparams);
|
||||
sgml::closeTag(ofs, 0, false, top_element);
|
||||
sgml::closeTag(ofs, top_element);
|
||||
|
||||
ofs.close();
|
||||
if (ofs.fail())
|
||||
|
@ -100,17 +100,12 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf,
|
||||
OutputParams const & runparams,
|
||||
ParagraphList const & paragraphs,
|
||||
ParagraphList::const_iterator const & pbegin,
|
||||
ParagraphList::const_iterator const & pend) {
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
const int depth = 0;
|
||||
for(; par != pend; ++par) {
|
||||
LyXLayout_ptr const & style = par->layout();
|
||||
string id = par->getDocbookId();
|
||||
id = id.empty()? "": " id = \"" + id + "\"";
|
||||
|
||||
sgml::openTag(buf, os, depth, true, style->latexname(), id);
|
||||
ParagraphList::const_iterator const & pend)
|
||||
{
|
||||
for(ParagraphList::const_iterator par = pbegin; par != pend; ++par) {
|
||||
sgml::openTag(buf, os, *par);
|
||||
par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
|
||||
sgml::closeTag(os, depth, true, style->latexname());
|
||||
sgml::closeTag(os, *par);
|
||||
os << '\n';
|
||||
}
|
||||
return pend;
|
||||
@ -126,23 +121,20 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
|
||||
LyXLayout_ptr const & defaultstyle = buf.params().getLyXTextClass().defaultLayout();
|
||||
const int depth = 0;
|
||||
|
||||
LyXLayout_ptr const & bstyle = par->layout();
|
||||
string item_tag;
|
||||
|
||||
string id = par->getDocbookId();
|
||||
string env_name = bstyle->latexname();
|
||||
// Opening outter tag
|
||||
sgml::openTag(buf, os, depth, false, env_name, bstyle->latexparam() + id);
|
||||
sgml::openTag(buf, os, *pbegin);
|
||||
os << '\n';
|
||||
if (bstyle->latextype == LATEX_ENVIRONMENT and bstyle->innertag() == "CDATA")
|
||||
os << "<![CDATA[";
|
||||
|
||||
while (par != pend) {
|
||||
LyXLayout_ptr const & style = par->layout();
|
||||
string id = "";
|
||||
ParagraphList::const_iterator send;
|
||||
string id = par->getDocbookId();
|
||||
id = id.empty()? "" : " id = \"" + id + "\"";
|
||||
string wrapper = "";
|
||||
pos_type sep = 0;
|
||||
|
||||
@ -150,19 +142,19 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
switch (bstyle->latextype) {
|
||||
case LATEX_ENVIRONMENT:
|
||||
if (!bstyle->innertag().empty() and bstyle->innertag() != "CDATA") {
|
||||
sgml::openTag(buf, os, depth, true, bstyle->innertag());
|
||||
sgml::openTag(os, bstyle->innertag());
|
||||
}
|
||||
break;
|
||||
|
||||
case LATEX_ITEM_ENVIRONMENT:
|
||||
if (!bstyle->labeltag().empty()) {
|
||||
sgml::openTag(buf, os, depth, true, bstyle->innertag());
|
||||
sgml::openTag(buf, os, depth, true, bstyle->labeltag());
|
||||
sgml::openTag(os, bstyle->innertag());
|
||||
sgml::openTag(os, bstyle->labeltag());
|
||||
sep = par->getFirstWord(buf, os, runparams) + 1;
|
||||
sgml::closeTag(os, depth, true, bstyle->labeltag());
|
||||
sgml::closeTag(os, bstyle->labeltag());
|
||||
}
|
||||
wrapper = defaultstyle->latexname();
|
||||
sgml::openTag(buf, os, depth, true, bstyle->itemtag());
|
||||
sgml::openTag(os, bstyle->itemtag());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -171,9 +163,9 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
case LATEX_ENVIRONMENT:
|
||||
case LATEX_ITEM_ENVIRONMENT: {
|
||||
if(par->params().depth() == pbegin->params().depth()) {
|
||||
sgml::openTag(buf, os, depth, true, wrapper, id);
|
||||
sgml::openTag(os, wrapper, id);
|
||||
par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs), sep);
|
||||
sgml::closeTag(os, depth, true, wrapper);
|
||||
sgml::closeTag(os, wrapper);
|
||||
++par;
|
||||
}
|
||||
else {
|
||||
@ -194,14 +186,14 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
switch (bstyle->latextype) {
|
||||
case LATEX_ENVIRONMENT:
|
||||
if (!bstyle->innertag().empty() and bstyle->innertag() != "CDATA") {
|
||||
sgml::closeTag(os, depth, true, bstyle->innertag());
|
||||
sgml::closeTag(os, bstyle->innertag());
|
||||
os << '\n';
|
||||
}
|
||||
break;
|
||||
case LATEX_ITEM_ENVIRONMENT:
|
||||
sgml::closeTag(os, depth, true, bstyle->itemtag());
|
||||
sgml::closeTag(os, bstyle->itemtag());
|
||||
if (!bstyle->labeltag().empty())
|
||||
sgml::closeTag(os, depth, true, bstyle->innertag());
|
||||
sgml::closeTag(os, bstyle->innertag());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -212,7 +204,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
os << "]]>";
|
||||
|
||||
// Closing outter tag
|
||||
sgml::closeTag(os, depth, false, env_name);
|
||||
sgml::closeTag(os, *pbegin);
|
||||
|
||||
return pend;
|
||||
}
|
||||
@ -225,43 +217,24 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
|
||||
ParagraphList::const_iterator const & pbegin,
|
||||
ParagraphList::const_iterator const & pend)
|
||||
{
|
||||
Paragraph::depth_type depth = 0; // paragraph depth
|
||||
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
Counters & counters = buf.params().getLyXTextClass().counters();
|
||||
LyXLayout_ptr const & bstyle = par->layout();
|
||||
|
||||
string id = par->getDocbookId();
|
||||
id = id.empty()? "" : " id = \"" + id + "\"";
|
||||
|
||||
if (!bstyle->latexparam().empty()) {
|
||||
counters.step(bstyle->counter);
|
||||
id = bstyle->latexparam();
|
||||
if (id.find('#') != string::npos) {
|
||||
string el = expandLabel(buf.params().getLyXTextClass(),
|
||||
bstyle, false);
|
||||
id = subst(id, "#", el);
|
||||
}
|
||||
}
|
||||
|
||||
//Open outter tag
|
||||
sgml::openTag(buf, os, depth, false, bstyle->latexname(), id);
|
||||
sgml::openTag(buf, os, *pbegin);
|
||||
os << '\n';
|
||||
|
||||
// Label around sectioning number:
|
||||
if (!bstyle->labeltag().empty()) {
|
||||
sgml::openTag(buf, os, depth, false, bstyle->labeltag());
|
||||
sgml::openTag(os, bstyle->labeltag());
|
||||
os << expandLabel(buf.params().getLyXTextClass(), bstyle, false);
|
||||
sgml::closeTag(os, depth, false, bstyle->labeltag());
|
||||
sgml::closeTag(os, bstyle->labeltag());
|
||||
}
|
||||
|
||||
// Opend inner tag
|
||||
sgml::openTag(buf, os, depth, true, bstyle->innertag());
|
||||
|
||||
// Opend inner tag and close inner tags
|
||||
sgml::openTag(os, bstyle->innertag());
|
||||
par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
|
||||
|
||||
// Close inner tags
|
||||
sgml::closeTag(os, depth, true, bstyle->innertag());
|
||||
sgml::closeTag(os, bstyle->innertag());
|
||||
os << '\n';
|
||||
|
||||
++par;
|
||||
@ -289,9 +262,8 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Close outter tag
|
||||
sgml::closeTag(os, depth, false, bstyle->latexname());
|
||||
sgml::closeTag(os, *pbegin);
|
||||
|
||||
return pend;
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
InsetBase const * inset = pit->getInset(0);
|
||||
if (inset->lyxCode() == InsetOld::TOC_CODE) {
|
||||
string const temp = "toc";
|
||||
sgml::openTag(buf, os, depth, false, temp);
|
||||
sgml::openTag(os, temp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// environment tag closing
|
||||
for (; depth > pit->params().depth(); --depth) {
|
||||
sgml::closeTag(os, depth, false, environment_stack[depth]);
|
||||
sgml::closeTag(os, environment_stack[depth]);
|
||||
environment_stack[depth].erase();
|
||||
}
|
||||
|
||||
@ -63,14 +63,14 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
case LATEX_PARAGRAPH:
|
||||
if (depth == pit->params().depth()
|
||||
&& !environment_stack[depth].empty()) {
|
||||
sgml::closeTag(os, depth, false, environment_stack[depth]);
|
||||
sgml::closeTag(os, environment_stack[depth]);
|
||||
environment_stack[depth].erase();
|
||||
if (depth)
|
||||
--depth;
|
||||
else
|
||||
os << "</p>";
|
||||
}
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
sgml::openTag(os, style->latexname());
|
||||
break;
|
||||
|
||||
case LATEX_COMMAND:
|
||||
@ -79,12 +79,12 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
;
|
||||
|
||||
if (!environment_stack[depth].empty()) {
|
||||
sgml::closeTag(os, depth, false, environment_stack[depth]);
|
||||
sgml::closeTag(os, environment_stack[depth]);
|
||||
os << "</p>";
|
||||
}
|
||||
|
||||
environment_stack[depth].erase();
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
sgml::openTag(os, style->latexname());
|
||||
break;
|
||||
|
||||
case LATEX_ENVIRONMENT:
|
||||
@ -94,8 +94,7 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
|
||||
if (depth == pit->params().depth()
|
||||
&& environment_stack[depth] != latexname) {
|
||||
sgml::closeTag(os, depth, false,
|
||||
environment_stack[depth]);
|
||||
sgml::closeTag(os, environment_stack[depth]);
|
||||
environment_stack[depth].erase();
|
||||
}
|
||||
if (depth < pit->params().depth()) {
|
||||
@ -104,9 +103,9 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
}
|
||||
if (environment_stack[depth] != latexname) {
|
||||
if (depth == 0) {
|
||||
sgml::openTag(buf, os, depth, false, "p");
|
||||
sgml::openTag(os, "p");
|
||||
}
|
||||
sgml::openTag(buf, os, depth, false, latexname);
|
||||
sgml::openTag(os, latexname);
|
||||
|
||||
if (environment_stack.size() == depth + 1)
|
||||
environment_stack.push_back("!-- --");
|
||||
@ -123,12 +122,12 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
else
|
||||
item_name = "item";
|
||||
|
||||
sgml::openTag(buf, os, depth + 1, false, item_name);
|
||||
sgml::openTag(os, item_name);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
sgml::openTag(os, style->latexname());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -148,12 +147,12 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
os << "]]>";
|
||||
break;
|
||||
default:
|
||||
sgml::closeTag(os, depth, false, style->latexname());
|
||||
sgml::closeTag(os, style->latexname());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Close open tags
|
||||
for (int i = depth; i >= 0; --i)
|
||||
sgml::closeTag(os, depth, false, environment_stack[i]);
|
||||
sgml::closeTag(os, environment_stack[i]);
|
||||
}
|
||||
|
69
src/sgml.C
69
src/sgml.C
@ -112,46 +112,65 @@ string escapeString(string const & raw)
|
||||
}
|
||||
|
||||
|
||||
int openTag(Buffer const & buf, ostream & os, Paragraph::depth_type depth,
|
||||
bool mixcont, string const & name, string const & param)
|
||||
void openTag(ostream & os, string const & name, string const & attribute)
|
||||
{
|
||||
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 != "!-- --") {
|
||||
if (!mixcont)
|
||||
os << string(depth, ' ');
|
||||
os << '<' << name;
|
||||
if (!attribute.empty())
|
||||
os << " " << attribute;
|
||||
os << '>';
|
||||
}
|
||||
|
||||
return !mixcont;
|
||||
}
|
||||
|
||||
|
||||
int closeTag(ostream & os, Paragraph::depth_type depth,
|
||||
bool mixcont, string const & name)
|
||||
void closeTag(ostream & os, string const & name)
|
||||
{
|
||||
if (!name.empty() && name != "!-- --") {
|
||||
if (!mixcont)
|
||||
os << '\n' << string(depth, ' ');
|
||||
if (!name.empty() && name != "!-- --")
|
||||
os << "</" << name << '>';
|
||||
}
|
||||
|
||||
if (!mixcont)
|
||||
os << '\n';
|
||||
|
||||
return !mixcont;
|
||||
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;
|
||||
}
|
||||
}
|
||||
openTag(os, name, attribute);
|
||||
}
|
||||
|
||||
|
||||
void closeTag(ostream & os, Paragraph const & par)
|
||||
{
|
||||
LyXLayout_ptr const & style = par.layout();
|
||||
closeTag(os, style->latexname());
|
||||
}
|
||||
|
||||
} // namespace sgml
|
||||
|
14
src/sgml.h
14
src/sgml.h
@ -20,6 +20,7 @@
|
||||
#include <utility>
|
||||
|
||||
class Buffer;
|
||||
class Paragraph;
|
||||
|
||||
namespace sgml {
|
||||
|
||||
@ -34,13 +35,16 @@ std::pair<bool, std::string> escapeChar(char c);
|
||||
std::string escapeString(std::string const & raw);
|
||||
|
||||
/// Opens tag
|
||||
int openTag(Buffer const & buf, std::ostream & os, lyx::depth_type depth,
|
||||
bool mixcont, std::string const & name,
|
||||
std::string const & param = std::string());
|
||||
void openTag(std::ostream & os, std::string const & name,
|
||||
std::string const & attribute = std::string());
|
||||
|
||||
/// Open tag
|
||||
void openTag(Buffer const & buf, std::ostream & os, Paragraph const & par);
|
||||
|
||||
/// Close tag
|
||||
int closeTag(std::ostream & os, lyx::depth_type depth,
|
||||
bool mixcont, std::string const & name);
|
||||
void closeTag(std::ostream & os, std::string const & name);
|
||||
|
||||
/// Close tag
|
||||
void closeTag(std::ostream & os, Paragraph const & par);
|
||||
}
|
||||
#endif // SGML_H
|
||||
|
Loading…
Reference in New Issue
Block a user