]> git.lyx.org Git - features.git/commitdiff
Fix description paragraph. (docbook)
authorJosé Matox <jamatos@lyx.org>
Sun, 24 Oct 2004 23:53:42 +0000 (23:53 +0000)
committerJosé Matox <jamatos@lyx.org>
Sun, 24 Oct 2004 23:53:42 +0000 (23:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9119 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/output_docbook.C
src/paragraph.C
src/paragraph.h

index 74e1b5cdfc6021b62296860fd3e32865717a60ab..f1a5b67bd190623ddbd3f1186d274798d9f1b8ae 100644 (file)
@@ -1,3 +1,13 @@
+2004-10-24  José Matos  <jamatos@lyx.org>
+
+       * paragraph.[Ch] (getFirstWord): new function to get the first
+       word. Useful for description.
+       (simpleDocBookOnePar): remove depth argument, add another that
+       says where to start the paragraph.
+
+       * output_docbook.C (makeParagraph, makeEnvironment, makeCommand):
+       use the new functions to fix cleanly the support for descriptions.
+       
 2004-10-24  José Matos  <jamatos@lyx.org>
 
        * buffer.C (makeLinuxDocFile, makeDocBookFile):
index 1e2862cbf0c29e79a3ec38bf663ca9f83f0c4cec..62822e35aad80fc640202f042f7cb025e6121660 100644 (file)
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 #include "support/tostr.h"
+#include "support/types.h"
 
 #ifdef HAVE_LOCALE
 #endif
 
+using lyx::pos_type;
 using lyx::support::subst;
 
 using std::endl;
@@ -107,8 +109,7 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf,
                id = id.empty()? "": " id = \"" + id + "\"";
 
                sgml::openTag(buf, os, depth, true, style->latexname(), id);
-               par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
-       
+               par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
                sgml::closeTag(os, depth, true, style->latexname());
                os << '\n';
        }
@@ -143,6 +144,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
                string id = "";
                ParagraphList::const_iterator send;
                string wrapper = "";
+               pos_type sep = 0;
 
                // Opening inner tag
                switch (bstyle->latextype) {
@@ -154,11 +156,13 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
 
                case LATEX_ITEM_ENVIRONMENT:
                        if (!bstyle->labeltag().empty()) {
+                               sgml::openTag(buf, os, depth, true, bstyle->innertag());
                                sgml::openTag(buf, os, depth, true, bstyle->labeltag());
-                       } else {
-                               wrapper = defaultstyle->latexname();
-                               sgml::openTag(buf, os, depth, true, bstyle->itemtag());
+                               sep = par->getFirstWord(buf, os, runparams) + 1;
+                               sgml::closeTag(os, depth, true, bstyle->labeltag());
                        }
+                       wrapper = defaultstyle->latexname();
+                       sgml::openTag(buf, os, depth, true, bstyle->itemtag());
                default:
                        break;
                }
@@ -168,7 +172,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
                case LATEX_ITEM_ENVIRONMENT: {
                        if(par->params().depth() == pbegin->params().depth()) {
                                sgml::openTag(buf, os, depth, true, wrapper, id);
-                               par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs), runparams, depth);
+                               par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs), sep);
                                sgml::closeTag(os, depth, true, wrapper);
                                ++par;
                        }
@@ -196,6 +200,8 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
                        break;
                case LATEX_ITEM_ENVIRONMENT:
                        sgml::closeTag(os, depth, true, bstyle->itemtag());
+                       if (!bstyle->labeltag().empty())
+                               sgml::closeTag(os, depth, true, bstyle->innertag());
                        break;
                default:
                        break;
@@ -255,8 +261,7 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
        // Opend inner tag
        sgml::openTag(buf, os, depth, true, bstyle->innertag());
 
-       par->simpleDocBookOnePar(buf, os, outerFont(par - paragraphs.begin(), paragraphs),
-                                runparams, depth);
+       par->simpleDocBookOnePar(buf, os, runparams,  outerFont(par - paragraphs.begin(), paragraphs));
 
        // Close inner tags
        sgml::closeTag(os, depth, true, bstyle->innertag());
index fce394073b38d7ae6049afd45bde6a9aa3dfae22..72d73583033b0ce91ed46b8099d425093533fa38 100644 (file)
@@ -1347,42 +1347,62 @@ string Paragraph::getDocbookId() const
 }
 
 
+pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams const & runparams) const
+{
+       pos_type i;
+       LyXLayout_ptr const & style = layout();
+       for (i = 0; i < size(); ++i) {
+               if (isInset(i)) {
+                       InsetBase const * inset = getInset(i);
+                       inset->docbook(buf, os, runparams);
+               } else {
+                       char c = getChar(i);
+                       if (c == ' ')
+                               break;
+                       bool ws;
+                       string str;
+                       boost::tie(ws, str) = sgml::escapeChar(c);
+
+                       if (style->pass_thru)
+                               os << c;
+                       else
+                               os << str;
+               }
+       }
+       return i;
+}
+
 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                    ostream & os,
-                                   LyXFont const & outerfont,
                                    OutputParams const & runparams,
-                                   lyx::depth_type depth) const
+                                   LyXFont const & outerfont,
+                                   pos_type initial) const
 {
        bool emph_flag = false;
-       int char_line_count = 0;
 
        LyXLayout_ptr const & style = layout();
-       LyXLayout_ptr const & defaultstyle =
-               buf.params().getLyXTextClass().defaultLayout();
-
        LyXFont font_old =
                style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
 
-       bool label_closed = true;
-
+       bool cdata = (style->latexparam() == "CDATA");
        // parsing main loop
-       for (pos_type i = 0; i < size(); ++i) {
+       for (pos_type i = initial; i < size(); ++i) {
                LyXFont font = getFont(buf.params(), i, outerfont);
 
                // handle <emphasis> tag
                if (font_old.emph() != font.emph()) {
                        if (font.emph() == LyXFont::ON) {
-                               if (style->latexparam() == "CDATA")
+                               if (cdata)
                                        os << "]]>";
                                os << "<emphasis>";
-                               if (style->latexparam() == "CDATA")
+                               if (cdata)
                                        os << "<![CDATA[";
                                emph_flag = true;
-                       } else if (i) {
-                               if (style->latexparam() == "CDATA")
+                       } else if (i != initial) {
+                               if (cdata)
                                        os << "]]>";
                                os << "</emphasis>";
-                               if (style->latexparam() == "CDATA")
+                               if (cdata)
                                        os << "<![CDATA[";
                                emph_flag = false;
                        }
@@ -1390,10 +1410,10 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
-                       if (style->latexparam() == "CDATA")
+                       if (cdata)
                                os << "]]>";
                        inset->docbook(buf, os, runparams);
-                       if (style->latexparam() == "CDATA")
+                       if (cdata)
                                os << "<![CDATA[";
                } else {
                        char c = getChar(i);
@@ -1401,38 +1421,22 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                        string str;
                        boost::tie(ws, str) = sgml::escapeChar(c);
 
-                       if (style->pass_thru) {
+                       if (style->pass_thru)
                                os << c;
-                       } else if (isFreeSpacing() || c != ' ') {
-                                       os << str;
-                       } else if (!style->labeltag().empty() && !label_closed) {
-                               ++char_line_count;
-                               os << "\n</" << style->labeltag() << "><"
-                                  << style->itemtag() << "><"
-                                  << defaultstyle->latexname() << ">";
-                               label_closed = true;
-                       } else {
-                               os << ' ';
-                       }
+                       else
+                               os << str;
                }
                font_old = font;
        }
 
        if (emph_flag) {
-               if (style->latexparam() == "CDATA")
+               if (cdata)
                        os << "]]>";
                os << "</emphasis>";
-               if (style->latexparam() == "CDATA")
+               if (cdata)
                        os << "<![CDATA[";
        }
 
-       // resets description flag correctly
-       if (!label_closed) {
-               // <term> not closed...
-               os << "</" << style->labeltag() << ">\n<"
-                  << style->itemtag() << "><"
-                  << defaultstyle->latexname() << ">&nbsp;";
-       }
        if (style->free_spacing)
                os << '\n';
 }
index ded4888a9558c8e8e032b5ed3ccf2a7a9b25f8d6..f937fdbd07c438df08d2aec2145370c234b52b5b 100644 (file)
@@ -132,12 +132,17 @@ public:
        /// Get the id of the paragraph, usefull for docbook
        std::string getDocbookId() const;
 
-       ///
+       // Get the first word of a paragraph, return the position where it left
+       lyx::pos_type getFirstWord(Buffer const & buf,
+                                  std::ostream & os,
+                                  OutputParams const & runparams) const;
+
+       /// Writes to stream the docbook representation
        void simpleDocBookOnePar(Buffer const & buf,
                                 std::ostream &,
-                                LyXFont const & outerfont,
                                 OutputParams const & runparams,
-                                lyx::depth_type depth) const;
+                                LyXFont const & outerfont,
+                                lyx::pos_type initial = 0) const;
 
        ///
        bool hasSameLayout(Paragraph const & par) const;