]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Fix #1736
[lyx.git] / src / paragraph.C
index 95d8bbfb9777f8145fb5eaa8e6bb269f634c7074..5e02c66dd232ca71270e53cf31566983f262c4ca 100644 (file)
@@ -1331,7 +1331,32 @@ void Paragraph::simpleLinuxDocOnePar(Buffer const & buf,
 }
 
 
-string Paragraph::getID() const
+bool Paragraph::emptyTag() const
+{
+       for (pos_type i = 0; i < size(); ++i) {
+               if (isInset(i)) {
+                       InsetBase const * inset = getInset(i);
+                       InsetBase::Code lyx_code = inset->lyxCode();
+                       if (lyx_code != InsetBase::TOC_CODE and
+                           lyx_code != InsetBase::INCLUDE_CODE and
+                           lyx_code != InsetBase::GRAPHICS_CODE and
+                           lyx_code != InsetBase::ERT_CODE and
+                           lyx_code != InsetBase::FLOAT_CODE and
+                           lyx_code != InsetBase::TABULAR_CODE) {
+                               return false;
+                       }
+               } else {
+                       char c = getChar(i);
+                       if(c!= ' ' and c!= '\t')
+                               return false;
+               }
+
+       }
+       return true;
+}
+
+
+string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const
 {
        for (pos_type i = 0; i < size(); ++i) {
                if (isInset(i)) {
@@ -1339,7 +1364,7 @@ string Paragraph::getID() const
                        InsetBase::Code lyx_code = inset->lyxCode();
                        if (lyx_code == InsetBase::LABEL_CODE) {
                                string const id = static_cast<InsetCommand const *>(inset)->getContents();
-                               return "id=\"" + sgml::cleanID(id) + "\"";
+                               return "id=\"" + sgml::cleanID(buf, runparams, id) + "\"";
                        }
                }
 
@@ -1351,7 +1376,6 @@ string Paragraph::getID() 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);
@@ -1364,15 +1388,31 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, ostream & os, OutputParams
                        string str;
                        boost::tie(ws, str) = sgml::escapeChar(c);
 
-                       if (style->pass_thru)
-                               os << c;
-                       else
-                               os << str;
+                       os << str;
                }
        }
        return i;
 }
 
+
+bool Paragraph::onlyText(Buffer const & buf, LyXFont const & outerfont, pos_type initial) const
+{
+       LyXLayout_ptr const & style = layout();
+       LyXFont font_old;
+
+       for (pos_type i = initial; i < size(); ++i) {
+               LyXFont font = getFont(buf.params(), i, outerfont);
+               if (isInset(i))
+                       return false;
+               if ( i != initial and font != font_old)
+                       return false;
+               font_old = font;
+       }
+
+       return true;
+}
+
+
 void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                                    ostream & os,
                                    OutputParams const & runparams,
@@ -1385,7 +1425,8 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        LyXFont font_old =
                style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
 
-       bool cdata = (style->latexparam() == "CDATA");
+       if (style->pass_thru and not onlyText(buf, outerfont, initial))
+               os << "]]>";
        // parsing main loop
        for (pos_type i = initial; i < size(); ++i) {
                LyXFont font = getFont(buf.params(), i, outerfont);
@@ -1393,29 +1434,17 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                // handle <emphasis> tag
                if (font_old.emph() != font.emph()) {
                        if (font.emph() == LyXFont::ON) {
-                               if (cdata)
-                                       os << "]]>";
                                os << "<emphasis>";
-                               if (cdata)
-                                       os << "<![CDATA[";
                                emph_flag = true;
                        } else if (i != initial) {
-                               if (cdata)
-                                       os << "]]>";
                                os << "</emphasis>";
-                               if (cdata)
-                                       os << "<![CDATA[";
                                emph_flag = false;
                        }
                }
 
                if (isInset(i)) {
                        InsetBase const * inset = getInset(i);
-                       if (cdata)
-                               os << "]]>";
                        inset->docbook(buf, os, runparams);
-                       if (cdata)
-                               os << "<![CDATA[";
                } else {
                        char c = getChar(i);
                        bool ws;
@@ -1431,15 +1460,13 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
        }
 
        if (emph_flag) {
-               if (cdata)
-                       os << "]]>";
                os << "</emphasis>";
-               if (cdata)
-                       os << "<![CDATA[";
        }
 
        if (style->free_spacing)
                os << '\n';
+       if (style->pass_thru and not onlyText(buf, outerfont, initial))
+               os << "<![CDATA[";
 }