mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Move paragraph counting to a single place. (SGML/XML)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9118 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f0c7ef825b
commit
71f3af2a4e
@ -1,4 +1,12 @@
|
||||
2004-10-24 José Matos <jamatos@lyx.org>
|
||||
2004-10-24 José Matos <jamatos@lyx.org>
|
||||
|
||||
* buffer.C (makeLinuxDocFile, makeDocBookFile):
|
||||
* output_docbook.C (makeParagraph, makeEnvironment, makeCommand):
|
||||
* output_linuxdoc.C (linuxdocParagraphs):
|
||||
* sgml.[Ch] (openTag): )move paragraph counting code to openTag, and
|
||||
add buffer as argument.
|
||||
|
||||
2004-10-24 José Matos <jamatos@lyx.org>
|
||||
|
||||
* output_docbook.C (makeEnvironment, searchEnvironment): place
|
||||
CDATA inside paragraphs and fix scope for listitems.
|
||||
|
@ -1032,12 +1032,12 @@ void Buffer::makeLinuxDocFile(string const & fname,
|
||||
ofs << ">\n\n";
|
||||
|
||||
if (params().options.empty())
|
||||
sgml::openTag(ofs, 0, false, top_element);
|
||||
sgml::openTag(*this, ofs, 0, false, top_element);
|
||||
else {
|
||||
string top = top_element;
|
||||
top += ' ';
|
||||
top += params().options;
|
||||
sgml::openTag(ofs, 0, false, top);
|
||||
sgml::openTag(*this, ofs, 0, false, top);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1126,7 +1126,7 @@ void Buffer::makeDocBookFile(string const & fname,
|
||||
|
||||
params().getLyXTextClass().counters().reset();
|
||||
|
||||
sgml::openTag(ofs, 0, false, top);
|
||||
sgml::openTag(*this, ofs, 0, false, top);
|
||||
ofs << '\n';
|
||||
docbookParagraphs(paragraphs(), *this, ofs, runparams);
|
||||
sgml::closeTag(ofs, 0, false, top_element);
|
||||
|
@ -100,21 +100,13 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf,
|
||||
ParagraphList::const_iterator const & pbegin,
|
||||
ParagraphList::const_iterator const & pend) {
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
Counters & counters = buf.params().getLyXTextClass().counters();
|
||||
const int depth = 0;
|
||||
|
||||
for(; par != pend; ++par) {
|
||||
LyXLayout_ptr const & style = par->layout();
|
||||
string id = par->getDocbookId();
|
||||
|
||||
if (!style->latexparam().empty()) {
|
||||
counters.step("para");
|
||||
int i = counters.value("para");
|
||||
id = subst(style->latexparam(), "#", tostr(i));
|
||||
}
|
||||
|
||||
id = id.empty()? "": " id = \"" + id + "\"";
|
||||
sgml::openTag(os, depth, true, style->latexname(), id);
|
||||
|
||||
sgml::openTag(buf, os, depth, true, style->latexname(), id);
|
||||
par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
|
||||
|
||||
sgml::closeTag(os, depth, true, style->latexname());
|
||||
@ -132,7 +124,6 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
ParagraphList::const_iterator const & pend) {
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
|
||||
Counters & counters = buf.params().getLyXTextClass().counters();
|
||||
LyXLayout_ptr const & defaultstyle = buf.params().getLyXTextClass().defaultLayout();
|
||||
const int depth = 0;
|
||||
|
||||
@ -142,7 +133,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
string id = par->getDocbookId();
|
||||
string env_name = bstyle->latexname();
|
||||
// Opening outter tag
|
||||
sgml::openTag(os, depth, false, env_name, bstyle->latexparam() + id);
|
||||
sgml::openTag(buf, os, depth, false, env_name, bstyle->latexparam() + id);
|
||||
os << '\n';
|
||||
if (bstyle->latextype == LATEX_ENVIRONMENT and bstyle->innertag() == "CDATA")
|
||||
os << "<![CDATA[";
|
||||
@ -157,21 +148,16 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
switch (bstyle->latextype) {
|
||||
case LATEX_ENVIRONMENT:
|
||||
if (!bstyle->innertag().empty() and bstyle->innertag() != "CDATA") {
|
||||
sgml::openTag(os, depth, true, bstyle->innertag());
|
||||
sgml::openTag(buf, os, depth, true, bstyle->innertag());
|
||||
}
|
||||
break;
|
||||
|
||||
case LATEX_ITEM_ENVIRONMENT:
|
||||
if (!bstyle->labeltag().empty()) {
|
||||
sgml::openTag(os, depth, true, bstyle->labeltag());
|
||||
sgml::openTag(buf, os, depth, true, bstyle->labeltag());
|
||||
} else {
|
||||
if (!defaultstyle->latexparam().empty()) {
|
||||
counters.step("para");
|
||||
id = tostr(counters.value("para"));
|
||||
id = " id=\""+ subst(defaultstyle->latexparam(), "#", id) + '"';
|
||||
}
|
||||
wrapper = defaultstyle->latexname();
|
||||
sgml::openTag(os, depth, true, bstyle->itemtag());
|
||||
sgml::openTag(buf, os, depth, true, bstyle->itemtag());
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@ -181,7 +167,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
||||
case LATEX_ENVIRONMENT:
|
||||
case LATEX_ITEM_ENVIRONMENT: {
|
||||
if(par->params().depth() == pbegin->params().depth()) {
|
||||
sgml::openTag(os, depth, true, wrapper, id);
|
||||
sgml::openTag(buf, os, depth, true, wrapper, id);
|
||||
par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
|
||||
sgml::closeTag(os, depth, true, wrapper);
|
||||
++par;
|
||||
@ -236,7 +222,6 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
|
||||
Paragraph::depth_type depth = 0; // paragraph depth
|
||||
|
||||
ParagraphList::const_iterator par = pbegin;
|
||||
|
||||
Counters & counters = buf.params().getLyXTextClass().counters();
|
||||
LyXLayout_ptr const & bstyle = par->layout();
|
||||
|
||||
@ -257,18 +242,18 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
|
||||
}
|
||||
|
||||
//Open outter tag
|
||||
sgml::openTag(os, depth, false, bstyle->latexname(), id);
|
||||
sgml::openTag(buf, os, depth, false, bstyle->latexname(), id);
|
||||
os << '\n';
|
||||
|
||||
// Label around sectioning number:
|
||||
if (!bstyle->labeltag().empty()) {
|
||||
sgml::openTag(os, depth, false, bstyle->labeltag());
|
||||
sgml::openTag(buf, os, depth, false, bstyle->labeltag());
|
||||
os << expandLabel(buf.params().getLyXTextClass(), bstyle, false);
|
||||
sgml::closeTag(os, depth, false, bstyle->labeltag());
|
||||
}
|
||||
|
||||
// Opend inner tag
|
||||
sgml::openTag(os, depth, true, bstyle->innertag());
|
||||
sgml::openTag(buf, os, depth, true, bstyle->innertag());
|
||||
|
||||
par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs),
|
||||
runparams, depth);
|
||||
|
@ -47,7 +47,7 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
InsetBase const * inset = pit->getInset(0);
|
||||
if (inset->lyxCode() == InsetOld::TOC_CODE) {
|
||||
string const temp = "toc";
|
||||
sgml::openTag(os, depth, false, temp);
|
||||
sgml::openTag(buf, os, depth, false, temp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
else
|
||||
os << "</p>";
|
||||
}
|
||||
sgml::openTag(os, depth, false, style->latexname());
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
break;
|
||||
|
||||
case LATEX_COMMAND:
|
||||
@ -84,7 +84,7 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
}
|
||||
|
||||
environment_stack[depth].erase();
|
||||
sgml::openTag(os, depth, false, style->latexname());
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
break;
|
||||
|
||||
case LATEX_ENVIRONMENT:
|
||||
@ -104,9 +104,9 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
}
|
||||
if (environment_stack[depth] != latexname) {
|
||||
if (depth == 0) {
|
||||
sgml::openTag(os, depth, false, "p");
|
||||
sgml::openTag(buf, os, depth, false, "p");
|
||||
}
|
||||
sgml::openTag(os, depth, false, latexname);
|
||||
sgml::openTag(buf, os, depth, false, latexname);
|
||||
|
||||
if (environment_stack.size() == depth + 1)
|
||||
environment_stack.push_back("!-- --");
|
||||
@ -123,12 +123,12 @@ void linuxdocParagraphs(Buffer const & buf,
|
||||
else
|
||||
item_name = "item";
|
||||
|
||||
sgml::openTag(os, depth + 1, false, item_name);
|
||||
sgml::openTag(buf, os, depth + 1, false, item_name);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
sgml::openTag(os, depth, false, style->latexname());
|
||||
sgml::openTag(buf, os, depth, false, style->latexname());
|
||||
break;
|
||||
}
|
||||
|
||||
|
46
src/sgml.C
46
src/sgml.C
@ -11,12 +11,20 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
#include "paragraph.h"
|
||||
#include "sgml.h"
|
||||
|
||||
using std::endl;
|
||||
#include "buffer.h"
|
||||
#include "bufferparams.h"
|
||||
#include "counters.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/std_ostream.h"
|
||||
#include "support/tostr.h"
|
||||
|
||||
using lyx::support::subst;
|
||||
|
||||
using std::make_pair;
|
||||
|
||||
using std::ostream;
|
||||
@ -86,16 +94,26 @@ pair<bool, string> escapeChar(char c)
|
||||
}
|
||||
|
||||
|
||||
int openTag(ostream & os, Paragraph::depth_type depth,
|
||||
bool mixcont, string const & latexname,
|
||||
string const & latexparam)
|
||||
int openTag(Buffer const & buf, ostream & os, Paragraph::depth_type depth,
|
||||
bool mixcont, string const & name, string const & param)
|
||||
{
|
||||
if (!latexname.empty() && latexname != "!-- --") {
|
||||
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 << '<' << latexname;
|
||||
if (!latexparam.empty())
|
||||
os << " " << latexparam;
|
||||
os << '<' << name;
|
||||
if (!attribute.empty())
|
||||
os << " " << attribute;
|
||||
os << '>';
|
||||
}
|
||||
|
||||
@ -104,12 +122,12 @@ int openTag(ostream & os, Paragraph::depth_type depth,
|
||||
|
||||
|
||||
int closeTag(ostream & os, Paragraph::depth_type depth,
|
||||
bool mixcont, string const & latexname)
|
||||
bool mixcont, string const & name)
|
||||
{
|
||||
if (!latexname.empty() && latexname != "!-- --") {
|
||||
if (!name.empty() && name != "!-- --") {
|
||||
if (!mixcont)
|
||||
os << '\n' << string(depth, ' ');
|
||||
os << "</" << latexname << '>';
|
||||
os << "</" << name << '>';
|
||||
}
|
||||
|
||||
if (!mixcont)
|
||||
|
24
src/sgml.h
24
src/sgml.h
@ -18,31 +18,25 @@
|
||||
#include <iosfwd>
|
||||
#include <utility>
|
||||
|
||||
class Buffer;
|
||||
|
||||
namespace sgml {
|
||||
|
||||
/**
|
||||
* Escape the given character if necessary
|
||||
* Escape the given character, if necessary,
|
||||
* to an SGML entity. Returns true
|
||||
* if it was a whitespace character.
|
||||
*/
|
||||
std::pair<bool, std::string> escapeChar(char c);
|
||||
|
||||
/// FIXME
|
||||
int openTag(std::ostream & os, lyx::depth_type depth,
|
||||
bool mixcont, std::string const & latexname,
|
||||
std::string const & latexparam = std::string());
|
||||
/// 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());
|
||||
|
||||
/// FIXME
|
||||
/// Close tag
|
||||
int closeTag(std::ostream & os, lyx::depth_type depth,
|
||||
bool mixcont, std::string const & latexname);
|
||||
|
||||
///
|
||||
unsigned int closeEnvTags(std::ostream & os,
|
||||
bool mixcont,
|
||||
std::string const & environment_inner_depth,
|
||||
std::string const & item_tag,
|
||||
lyx::depth_type total_depth);
|
||||
bool mixcont, std::string const & name);
|
||||
|
||||
}
|
||||
|
||||
#endif // SGML_H
|
||||
|
Loading…
Reference in New Issue
Block a user