]> git.lyx.org Git - lyx.git/blobdiff - src/output_plaintext.cpp
InsetIndex: enable escaping for terms in the index
[lyx.git] / src / output_plaintext.cpp
index 3ff3771049b5b49a31f18b2f5cd08abd7568b9fa..b0450bda9f3a731d68b19e8953f183e996cba7b7 100644 (file)
@@ -21,6 +21,8 @@
 #include "ParagraphList.h"
 #include "ParagraphParameters.h"
 
+#include "insets/Inset.h"
+
 #include "support/debug.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -34,9 +36,15 @@ namespace lyx {
 void writePlaintextFile(Buffer const & buf, FileName const & fname,
        OutputParams const & runparams)
 {
-       odocfstream ofs;
+       ofdocstream ofs;
        if (!openFileWrite(ofs, fname))
                return;
+
+       // make sure we are ready to export
+       buf.updateBuffer();
+       buf.updateMacroInstances(OutputUpdate);
+       buf.makeCitationLabels();
+
        writePlaintextFile(buf, ofs, runparams);
 }
 
@@ -50,9 +58,11 @@ void writePlaintextFile(Buffer const & buf, odocstream & os,
        ParagraphList::const_iterator end = par.end();
        ParagraphList::const_iterator it = beg;
        for (; it != end; ++it) {
+               bool const merged_par = (*it).parEndChange().deleted();
                writePlaintextParagraph(buf, *it, os, runparams, ref_printed);
-               os << "\n";
-               if (runparams.linelen > 0)
+               if (!merged_par)
+                       os << "\n";
+               if (runparams.linelen > 0 && !merged_par)
                        os << "\n";
        }
 }
@@ -66,11 +76,12 @@ static pair<int, docstring> addDepth(int depth, int ldepth)
        return make_pair(d, docstring(d, ' '));
 }
 
+
 void writePlaintextParagraph(Buffer const & buf,
                    Paragraph const & par,
-                   odocstream & os,
+                   odocstream & ods,
                    OutputParams const & runparams,
-                   bool & ref_printed)
+                   bool & ref_printed, size_t max_length)
 {
        int ltype = 0;
        depth_type ltype_depth = 0;
@@ -114,6 +125,7 @@ void writePlaintextParagraph(Buffer const & buf,
 
        string::size_type currlinelen = 0;
 
+       odocstringstream os;
        os << docstring(depth * 2, ' ');
        currlinelen += depth * 2;
 
@@ -177,7 +189,10 @@ void writePlaintextParagraph(Buffer const & buf,
                if (par.isDeleted(i))
                        continue;
 
-               char_type c = par.getUChar(buf.params(), i);
+               if (os.str().size() > max_length)
+                       break;
+
+               char_type c = par.getUChar(buf.params(), runparams, i);
 
                if (par.isInset(i) || c == ' ') {
                        if (runparams.linelen > 0 &&
@@ -195,7 +210,7 @@ void writePlaintextParagraph(Buffer const & buf,
                if (par.isInset(i)) {
                        OutputParams rp = runparams;
                        rp.depth = par.params().depth();
-                       int len = par.getInset(i)->plaintext(os, rp);
+                       int len = par.getInset(i)->plaintext(os, rp, max_length);
                        if (len >= Inset::PLAINTEXT_NEWLINE)
                                currlinelen = len - Inset::PLAINTEXT_NEWLINE;
                        else
@@ -206,7 +221,7 @@ void writePlaintextParagraph(Buffer const & buf,
                switch (c) {
                case ' ':
                        os << ' ';
-                       currlinelen++;
+                       ++currlinelen;
                        break;
 
                case '\0':
@@ -231,6 +246,7 @@ void writePlaintextParagraph(Buffer const & buf,
                }
                os << word;
        }
+       ods << os.str();
 }