+bool Buffer::importString(string const & format, docstring const & contents, ErrorList & errorList)
+{
+ Format const * fmt = formats.getFormat(format);
+ if (!fmt)
+ return false;
+ // It is important to use the correct extension here, since some
+ // converters create a wrong output file otherwise (e.g. html2latex)
+ TempFile const tempfile("Buffer_importStringXXXXXX." + fmt->extension());
+ FileName const name(tempfile.name());
+ ofdocstream os(name.toFilesystemEncoding().c_str());
+ // Do not convert os implicitly to bool, since that is forbidden in C++11.
+ bool const success = !(os << contents).fail();
+ os.close();
+
+ bool converted = false;
+ if (success) {
+ params().compressed = false;
+
+ // remove dummy empty par
+ paragraphs().clear();
+
+ converted = importFile(format, name, errorList);
+ }
+
+ if (name.exists())
+ name.removeFile();
+ return converted;
+}
+
+
+bool Buffer::importFile(string const & format, FileName const & name, ErrorList & errorList)
+{
+ if (!theConverters().isReachable(format, "lyx"))
+ return false;
+
+ TempFile const tempfile("Buffer_importFileXXXXXX.lyx");
+ FileName const lyx(tempfile.name());
+ if (theConverters().convert(0, name, lyx, name, format, "lyx", errorList))
+ return readFile(lyx) == ReadSuccess;
+
+ return false;
+}
+
+