+
+ // we will use pasteSelectionHelper to copy the paragraphs into the
+ // temporary Buffer, since it does a lot of things to fix them up.
+ DocIterator dit = doc_iterator_begin(buffer, &buffer->inset());
+ ErrorList el;
+ pasteSelectionHelper(dit, paragraphs, docclass, cap::BRANCH_ADD, el);
+
+ return buffer;
+}
+
+
+void putClipboard(ParagraphList const & paragraphs,
+ DocInfoPair docinfo, docstring const & plaintext,
+ BufferParams const & bp)
+{
+ Buffer * buffer = copyToTempBuffer(paragraphs, docinfo.first);
+ if (!buffer) // already asserted in copyToTempBuffer()
+ return;
+
+ // We don't want to produce images that are not used. Therefore,
+ // output formulas as MathML. Even if this is not understood by all
+ // applications, the number that can parse it should go up in the future.
+ buffer->params().html_math_output = BufferParams::MathML;
+
+ // Copy authors to the params. We need those pointers.
+ for (Author const & a : bp.authors())
+ buffer->params().authors().record(a);
+
+ // Make sure MarkAsExporting is deleted before buffer is
+ {
+ // The Buffer is being used to export. This is necessary so that the
+ // updateMacros call will record the needed information.
+ MarkAsExporting mex(buffer);
+
+ buffer->updateBuffer(Buffer::UpdateMaster, OutputUpdate);
+ buffer->updateMacros();
+ buffer->updateMacroInstances(OutputUpdate);
+
+ // LyX's own format
+ string lyx;
+ ostringstream oslyx;
+ if (buffer->write(oslyx))
+ lyx = oslyx.str();
+
+ // XHTML format
+ odocstringstream oshtml;
+ OutputParams runparams(encodings.fromLyXName("utf8"));
+ // We do not need to produce images, etc.
+ runparams.dryrun = true;
+ // We are not interested in errors (bug 8866)
+ runparams.silent = true;
+ buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
+
+ theClipboard().put(lyx, oshtml.str(), plaintext);
+ }
+