]> git.lyx.org Git - lyx.git/blobdiff - src/output_docbook.C
fix crash after removing a table row (again due to uncorrected cursor
[lyx.git] / src / output_docbook.C
index 8602b672830d0a4b7ba59c5978b541ef2c71225b..a5285e51b185fe7a670f2972e2f9b85ea606a4ba 100644 (file)
@@ -16,6 +16,7 @@
 #include "buffer.h"
 #include "bufferparams.h"
 #include "counters.h"
+#include "debug.h"
 #include "lyxtext.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
@@ -63,18 +64,18 @@ void docbookParagraphs(Buffer const & buf,
 
        string item_tag;
 
-       ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
-       ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
+       ParagraphList::const_iterator par = paragraphs.begin();
+       ParagraphList::const_iterator pend = paragraphs.end();
+
+       Counters & counters = buf.params().getLyXTextClass().counters();
 
-    Counters & counters = buf.params().getLyXTextClass().counters();
-       
        for (; par != pend; ++par) {
 
                LyXLayout_ptr const & style = par->layout();
 
                // environment tag closing
                for (; depth > par->params().depth(); --depth) {
-                       sgml::closeEnvTags(os, false, environment_inner[depth], 
+                       sgml::closeEnvTags(os, false, environment_inner[depth],
                                item_tag, command_depth + depth);
                        sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]);
                        environment_stack[depth].erase();
@@ -84,24 +85,27 @@ void docbookParagraphs(Buffer const & buf,
                if (depth == par->params().depth()
                   && environment_stack[depth] != style->latexname()
                   && !environment_stack[depth].empty()) {
-                               sgml::closeEnvTags(os, false, environment_inner[depth], 
+                               sgml::closeEnvTags(os, false, environment_inner[depth],
                                        item_tag, command_depth + depth);
                        sgml::closeTag(os, depth + command_depth, false, environment_stack[depth]);
 
                        environment_stack[depth].erase();
                        environment_inner[depth].erase();
                }
-               
-               string ls = "";
-               bool labelid = false;
+
+               string ls = par->getDocbookId();
+               if (!ls.empty())
+                       ls = " id = \"" + ls + "\"";
+
                // Write opening SGML tags.
                switch (style->latextype) {
                case LATEX_PARAGRAPH:
                        if (!style->latexparam().empty()) {
                                counters.step("para");
                                int i = counters.value("para");
-                               ls = "id=\"" + subst(style->latexparam(), "#", tostr(i)) + '"';
+                               ls = subst(style->latexparam(), "#", tostr(i));
                        }
+
                        sgml::openTag(os, depth + command_depth,
                                    false, style->latexname(), ls);
                        break;
@@ -110,11 +114,11 @@ void docbookParagraphs(Buffer const & buf,
                        if (depth != 0)
                                //error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
                                ;
-                       
+
                        command_name = style->latexname();
 
                        cmd_depth = style->commanddepth;
-                       
+
                        if (command_flag) {
                                if (cmd_depth < command_base) {
                                        for (Paragraph::depth_type j = command_depth;
@@ -140,42 +144,32 @@ void docbookParagraphs(Buffer const & buf,
                                command_stack.push_back(string());
                        command_stack[command_depth] = command_name;
 
-                       if (!style->latexparam().empty()) {
+                       if (style->latexparam().find('#') != string::npos) {
                                counters.step(style->counter);
                        }
-                       // treat label as a special case for
-                       // more WYSIWYM handling.
-                       // This is a hack while paragraphs can't have
-                       // attributes, like id in this case.
-                       if (par->isInset(0)) {
-                               InsetOld * inset = par->getInset(0);
-                               InsetOld::Code lyx_code = inset->lyxCode();
-                               if (lyx_code == InsetOld::LABEL_CODE) {
-                                       command_name += " id=\"";
-                                       command_name += (static_cast<InsetCommand *>(inset))->getContents();
-                                       command_name += '"';
-                                       labelid = true;
-                               }
-                       } else {
-                               if (!style->latexparam().empty()) {
-                                       ls = expandLabel(buf.params().getLyXTextClass(), style, false);
-                                       ls = "id=\"" + subst(style->latexparam(), "#", ls) + '"';
+
+                       if (!style->latexparam().empty()) {
+                               ls = style->latexparam();
+                               if (ls.find('#') != string::npos) {
+                                       string el = expandLabel(buf.params().getLyXTextClass(),
+                                               style, false);
+                                       ls = subst(ls, "#", el);
                                }
                        }
-                       
+
                        sgml::openTag(os, depth + command_depth, false, command_name, ls);
 
                        // Label around sectioning number:
                        if (!style->labeltag().empty()) {
-                               sgml::openTag(os, depth + 1 + command_depth, false, 
+                               sgml::openTag(os, depth + 1 + command_depth, false,
                                        style->labeltag());
                                os << expandLabel(buf.params().getLyXTextClass(), style, false);
-                               sgml::closeTag(os, depth + 1 + command_depth, false, 
+                               sgml::closeTag(os, depth + 1 + command_depth, false,
                                        style->labeltag());
                        }
 
                        // Inner tagged header text, e.g. <title> for sectioning:
-                       sgml::openTag(os, depth + 1 + command_depth, false, 
+                       sgml::openTag(os, depth + 1 + command_depth, false,
                                style->innertag());
                        break;
 
@@ -194,10 +188,10 @@ void docbookParagraphs(Buffer const & buf,
                                environment_stack[depth] = style->latexname();
                                environment_inner[depth] = "!-- --";
                                // outputs <environment_stack[depth] latexparam()>
-                               sgml::openTag(os, depth + command_depth, false, 
-                                               environment_stack[depth], style->latexparam());
+                               sgml::openTag(os, depth + command_depth, false,
+                                               environment_stack[depth], style->latexparam() + ls);
                        } else {
-                               sgml::closeEnvTags(os, false, environment_inner[depth], 
+                               sgml::closeEnvTags(os, false, environment_inner[depth],
                                        style->itemtag(), command_depth + depth);
                        }
 
@@ -206,7 +200,7 @@ void docbookParagraphs(Buffer const & buf,
                                        if (style->innertag() == "CDATA")
                                                os << "<![CDATA[";
                                        else
-                                               sgml::openTag(os, depth + command_depth, false, 
+                                               sgml::openTag(os, depth + command_depth, false,
                                                        style->innertag());
                                }
                                break;
@@ -220,17 +214,18 @@ void docbookParagraphs(Buffer const & buf,
                        break;
                default:
                        sgml::openTag(os, depth + command_depth,
-                                   false, style->latexname());
+                                   false, style->latexname(), ls);
                        break;
                }
 
-               par->simpleDocBookOnePar(buf, os, outerFont(par, paragraphs),
-                                        runparams, depth + 1 + command_depth, labelid);
+               par->simpleDocBookOnePar(buf, os,
+                       outerFont(par - paragraphs.begin(), paragraphs),
+                       runparams, depth + 1 + command_depth);
 
                // write closing SGML tags
                switch (style->latextype) {
                case LATEX_COMMAND:
-                       sgml::closeTag(os, depth + command_depth, false, 
+                       sgml::closeTag(os, depth + command_depth, false,
                                style->innertag());
                        break;
                case LATEX_ENVIRONMENT:
@@ -238,7 +233,7 @@ void docbookParagraphs(Buffer const & buf,
                                if (style->innertag() == "CDATA")
                                        os << "]]>";
                                else
-                                       sgml::closeTag(os, depth + command_depth, false, 
+                                       sgml::closeTag(os, depth + command_depth, false,
                                                style->innertag());
                        }
                        break;
@@ -257,8 +252,8 @@ void docbookParagraphs(Buffer const & buf,
        // Close open tags
        for (int d = depth; d >= 0; --d) {
                if (!environment_stack[depth].empty()) {
-                               sgml::closeEnvTags(os, false, environment_inner[depth], 
-                                       item_tag, command_depth + depth);
+                       sgml::closeEnvTags(os, false, environment_inner[d], item_tag, command_depth + d);
+                       sgml::closeTag(os, d + command_depth, false, environment_stack[d]);
                }
        }
 
@@ -268,4 +263,3 @@ void docbookParagraphs(Buffer const & buf,
                        os << endl;
                }
 }
-