]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetInclude.cpp
DocBook: actually include files that are not properly understood (with automatic...
[features.git] / src / insets / InsetInclude.cpp
index 6eba05abde51d319d7ab81cc6cd49e3c4df05c76..5400d5f739ab86d46f9c817456124af7b25c1a1c 100644 (file)
@@ -987,12 +987,11 @@ docstring InsetInclude::xhtml(XMLStream & xs, OutputParams const & rp) const
                op.par_begin = 0;
                op.par_end = 0;
                ibuf->writeLyXHTMLSource(xs.os(), op, Buffer::IncludedFile);
-       } else
-               xs << XMLStream::ESCAPE_NONE
-                  << "<!-- Included file: "
-                  << from_utf8(included_file.absFileName())
-                  << XMLStream::ESCAPE_NONE
-                        << " -->";
+       } else {
+               xs << XMLStream::ESCAPE_NONE << "<!-- Included file: ";
+               xs << from_utf8(included_file.absFileName());
+               xs << XMLStream::ESCAPE_NONE << " -->";
+       }
        
        return docstring();
 }
@@ -1037,56 +1036,78 @@ int InsetInclude::plaintext(odocstringstream & os,
 }
 
 
-int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
+void InsetInclude::docbook(XMLStream & xs, OutputParams const & rp) const
 {
-       string incfile = ltrim(to_utf8(params()["filename"]));
-
-       // Do nothing if no file name has been specified
-       if (incfile.empty())
-               return 0;
-
-       string const included_file = includedFileName(buffer(), params()).absFileName();
-       string exppath = incfile;
-       if (!runparams.export_folder.empty()) {
-               exppath = makeAbsPath(exppath, runparams.export_folder).realPath();
-               FileName(exppath).onlyPath().createPath();
-       }
+       if (rp.inComment)
+               return;
 
-       // write it to a file (so far the complete file)
-       string const exportfile = changeExtension(exppath, ".sgml");
-       DocFileName writefile(changeExtension(included_file, ".sgml"));
+       // For verbatim and listings, we just include the contents of the file as-is.
+       bool const verbatim = isVerbatim(params());
+       bool const listing = isListings(params());
+       if (listing || verbatim) {
+               if (listing)
+                       xs << xml::StartTag("programlisting");
+               else if (verbatim)
+                       xs << xml::StartTag("literallayout");
 
-       Buffer * tmp = loadIfNeeded();
-       if (tmp) {
-               if (recursion_error_)
-                       return 0;
+               // FIXME: We don't know the encoding of the file, default to UTF-8.
+               xs << includedFileName(buffer(), params()).fileContents("UTF-8");
 
-               string const mangled = writefile.mangledFileName();
-               writefile = makeAbsPath(mangled,
-                                       buffer().masterBuffer()->temppath());
-               if (!runparams.nice)
-                       incfile = mangled;
+               if (listing)
+                       xs << xml::EndTag("programlisting");
+               else if (verbatim)
+                       xs << xml::EndTag("literallayout");
 
-               LYXERR(Debug::LATEX, "incfile:" << incfile);
-               LYXERR(Debug::LATEX, "exportfile:" << exportfile);
-               LYXERR(Debug::LATEX, "writefile:" << writefile);
+               return;
+       }
 
-               tmp->makeDocBookFile(writefile, runparams, Buffer::OnlyBody);
+       // We don't know how to input or include non-LyX files. Input it as a comment.
+       FileName const included_file = includedFileName(buffer(), params());
+       if (!isLyXFileName(included_file.absFileName())) {
+               if (!rp.silent)
+                       frontend::Alert::warning(_("Unsupported Inclusion"),
+                                                bformat(_("LyX does not know how to process included non-LyX files when "
+                                                          "generating DocBook output. The content of the file will be output as a "
+                                                                                  "comment. Offending file:\n%1$s"),
+                                                        ltrim(params()["filename"])));
+
+               // Read the file, output it wrapped into comments.
+               xs << XMLStream::ESCAPE_NONE << "<!-- Included file: ";
+               xs << from_utf8(included_file.absFileName());
+               xs << XMLStream::ESCAPE_NONE << " -->";
+
+               xs << XMLStream::ESCAPE_NONE << "<!-- ";
+               xs << included_file.fileContents("UTF-8");
+               xs << XMLStream::ESCAPE_NONE << " -->";
+
+               xs << XMLStream::ESCAPE_NONE << "<!-- End of included file: ";
+               xs << from_utf8(included_file.absFileName());
+               xs << XMLStream::ESCAPE_NONE << " -->";
        }
 
-       runparams.exportdata->addExternalFile("docbook", writefile,
-                                             exportfile);
-       runparams.exportdata->addExternalFile("docbook-xml", writefile,
-                                             exportfile);
+       // In the other cases, we generate the DocBook version and include it.
+       Buffer const * const ibuf = loadIfNeeded();
+       if (!ibuf)
+               return;
 
-       if (isVerbatim(params()) || isListings(params())) {
-               os << "<inlinegraphic fileref=\""
-                  << '&' << include_label << ';'
-                  << "\" format=\"linespecific\">";
-       } else
-               os << '&' << include_label << ';';
+       if (recursion_error_)
+               return;
 
-       return 0;
+       // are we generating only some paragraphs, or all of them?
+       bool const all_pars = !rp.dryrun ||
+                             (rp.par_begin == 0 &&
+                              rp.par_end == (int) buffer().text().paragraphs().size());
+
+       OutputParams op = rp;
+       if (all_pars) {
+               op.par_begin = 0;
+               op.par_end = 0;
+               ibuf->writeDocBookSource(xs.os(), op, Buffer::IncludedFile);
+       } else {
+               xs << XMLStream::ESCAPE_NONE << "<!-- Included file: ";
+               xs << from_utf8(included_file.absFileName());
+               xs << XMLStream::ESCAPE_NONE << " -->";
+       }
 }