From 71f3af2a4eade059bc141a35ec80777aba9e6f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Matox?= Date: Sun, 24 Oct 2004 20:55:22 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 10 +++++++++- src/buffer.C | 6 +++--- src/output_docbook.C | 35 ++++++++++---------------------- src/output_linuxdoc.C | 14 ++++++------- src/sgml.C | 46 ++++++++++++++++++++++++++++++------------- src/sgml.h | 24 +++++++++------------- 6 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6544bd3abf..74e1b5cdfc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,12 @@ -2004-10-24 José Matos +2004-10-24 José Matos + + * 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 * output_docbook.C (makeEnvironment, searchEnvironment): place CDATA inside paragraphs and fix scope for listitems. diff --git a/src/buffer.C b/src/buffer.C index 7c624aaecf..dab77c8994 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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); diff --git a/src/output_docbook.C b/src/output_docbook.C index 7f57209a6d..1e2862cbf0 100644 --- a/src/output_docbook.C +++ b/src/output_docbook.C @@ -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 << "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); diff --git a/src/output_linuxdoc.C b/src/output_linuxdoc.C index 060593c0e5..52fda32310 100644 --- a/src/output_linuxdoc.C +++ b/src/output_linuxdoc.C @@ -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 << "

"; } - 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; } diff --git a/src/sgml.C b/src/sgml.C index 730eec1925..daab836cc1 100644 --- a/src/sgml.C +++ b/src/sgml.C @@ -11,12 +11,20 @@ #include -#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 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 << "'; + os << "'; } if (!mixcont) diff --git a/src/sgml.h b/src/sgml.h index e3f65c49e0..fb7b9cc63e 100644 --- a/src/sgml.h +++ b/src/sgml.h @@ -18,31 +18,25 @@ #include #include +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 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