]> git.lyx.org Git - lyx.git/commitdiff
Move paragraph counting to a single place. (SGML/XML)
authorJosé Matox <jamatos@lyx.org>
Sun, 24 Oct 2004 20:55:22 +0000 (20:55 +0000)
committerJosé Matox <jamatos@lyx.org>
Sun, 24 Oct 2004 20:55:22 +0000 (20:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9118 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/buffer.C
src/output_docbook.C
src/output_linuxdoc.C
src/sgml.C
src/sgml.h

index 6544bd3abf91a423560792725edd9429e1685c03..74e1b5cdfc6021b62296860fd3e32865717a60ab 100644 (file)
@@ -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.
index 7c624aaecf726cb9e26f2c9f8565dee222d0037e..dab77c8994fa160c83bf38f807ddb019f279b6cb 100644 (file)
@@ -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);
index 7f57209a6dc6511590399e47827e0727689a2c29..1e2862cbf0c29e79a3ec38bf663ca9f83f0c4cec 100644 (file)
@@ -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);
index 060593c0e506b756fa8f6facc38ced0628852d64..52fda32310586cc10e5c5c24796307a0bdb5b262 100644 (file)
@@ -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;
                }
 
index 730eec1925b73ade995fc3a81fbd709dfc9836ff..daab836cc107259090b6517b6e6db2cf57139e59 100644 (file)
 
 #include <config.h>
 
-#include "support/std_ostream.h"
+#include "sgml.h"
 
+#include "buffer.h"
+#include "bufferparams.h"
+#include "counters.h"
+#include "lyxtext.h"
 #include "paragraph.h"
-#include "sgml.h"
 
-using std::endl;
+#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)
index e3f65c49e01cbce991ee0012d8d48a77b152356e..fb7b9cc63efb76e2bc31328a0ace8a9c38db79ef 100644 (file)
 #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