* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
#include "Buffer.h"
#include "BufferParams.h"
-#include "support/debug.h"
-#include "support/gettext.h"
#include "Layout.h"
#include "output.h"
#include "OutputParams.h"
#include "ParagraphList.h"
#include "ParagraphParameters.h"
+#include "support/debug.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
+using namespace std;
+using namespace lyx::support;
namespace lyx {
-using support::ascii_lowercase;
-using support::compare_ascii_no_case;
-using support::contains;
-using support::FileName;
-
-using std::endl;
-using std::ostream;
-using std::pair;
-using std::string;
-
void writePlaintextFile(Buffer const & buf, FileName const & fname,
OutputParams const & runparams)
{
- odocfstream ofs("UTF-8");
+ 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);
}
OutputParams const & runparams)
{
bool ref_printed = false;
- ParagraphList const par = buf.paragraphs();
+ ParagraphList const & par = buf.paragraphs();
ParagraphList::const_iterator beg = par.begin();
ParagraphList::const_iterator end = par.end();
ParagraphList::const_iterator it = beg;
}
-namespace {
-
-pair<int, docstring> const addDepth(int depth, int ldepth)
+static pair<int, docstring> addDepth(int depth, int ldepth)
{
int d = depth * 2;
if (ldepth > depth)
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;
depth_type depth = par.params().depth();
// First write the layout
- string const tmp = to_utf8(par.layout()->name());
+ string const tmp = to_utf8(par.layout().name());
if (compare_ascii_no_case(tmp, "itemize") == 0) {
ltype = 1;
ltype_depth = depth + 1;
string::size_type currlinelen = 0;
+ odocstringstream os;
os << docstring(depth * 2, ' ');
currlinelen += depth * 2;
if (par.isDeleted(i))
continue;
+ if (os.str().size() > max_length)
+ break;
+
char_type c = par.getUChar(buf.params(), i);
if (par.isInset(i) || c == ' ') {
if (par.isInset(i)) {
OutputParams rp = runparams;
rp.depth = par.params().depth();
- int len = par.getInset(i)->plaintext(buf, os, rp);
+ int len = par.getInset(i)->plaintext(os, rp, max_length);
if (len >= Inset::PLAINTEXT_NEWLINE)
currlinelen = len - Inset::PLAINTEXT_NEWLINE;
else
break;
case '\0':
- LYXERR(Debug::INFO, "writePlaintextFile: NULL char in structure.");
+ LYXERR(Debug::INFO, "writePlaintextFile: NUL char in structure.");
break;
default:
}
os << word;
}
+ ods << os.str();
}