diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 476d70bcd6..1509b5ba28 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3072,12 +3072,11 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, void Buffer::getSourceCode(odocstream & os, pit_type par_begin, - pit_type par_end, bool full_source) const + pit_type par_end, bool full_source) { OutputParams runparams(¶ms().encoding()); runparams.nice = true; - runparams.flavor = params().useNonTeXFonts ? - OutputParams::XETEX : OutputParams::LATEX; + runparams.flavor = getDefaultOutputFlavor(); runparams.linelen = lyxrc.plaintext_linelen; // No side effect of file copying and image conversion runparams.dryrun = true; @@ -3089,6 +3088,8 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin, d->texrow.newline(); if (isDocBook()) writeDocBookSource(os, absFileName(), runparams, false); + else if (runparams.flavor == OutputParams::HTML) + writeLyXHTMLSource(os, runparams, false); else // latex or literate writeLaTeXSource(os, string(), runparams, true, true); @@ -3113,7 +3114,10 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin, // output paragraphs if (isDocBook()) docbookParagraphs(text(), *this, os, runparams); - else + else if (runparams.flavor == OutputParams::HTML) { + XHTMLStream xs(os); + xhtmlParagraphs(text(), *this, xs, runparams); + } else // latex or literate latexParagraphs(*this, text(), os, texrow, runparams); } @@ -3384,6 +3388,42 @@ string Buffer::getDefaultOutputFormat() const } +OutputParams::FLAVOR Buffer::getDefaultOutputFlavor() +{ + string const dformat = getDefaultOutputFormat(); + DefaultFlavorCache::const_iterator it = + default_flavors_.find(dformat); + + if (it != default_flavors_.end()) + return it->second; + + OutputParams::FLAVOR result = OutputParams::LATEX; + + if (dformat == "xhtml") + result = OutputParams::HTML; + else { + // Try to determine flavor of default output format + vector backs = backends(); + if (find(backs.begin(), backs.end(), dformat) == backs.end()) { + // Get shortest path to format + Graph::EdgePath path; + for (vector::const_iterator it = backs.begin(); + it != backs.end(); ++it) { + Graph::EdgePath p = theConverters().getPath(*it, dformat); + if (!p.empty() && (path.empty() || p.size() < path.size())) { + path = p; + } + } + if (!path.empty()) + result = theConverters().getFlavor(path); + } + } + // cache this flavor + default_flavors_[dformat] = result; + return result; +} + + namespace { // helper class, to guarantee this gets reset properly class MarkAsExporting { diff --git a/src/Buffer.h b/src/Buffer.h index 3939514031..c9f82068b3 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -13,12 +13,14 @@ #define BUFFER_H #include "OutputEnums.h" +#include "OutputParams.h" #include "insets/InsetCode.h" #include "support/strfwd.h" #include "support/types.h" +#include #include #include #include @@ -552,7 +554,7 @@ public: /// get source code (latex/docbook) for some paragraphs, or all paragraphs /// including preamble void getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end, - bool full_source) const; + bool full_source); /// Access to error list. /// This method is used only for GUI visualisation of Buffer related @@ -600,6 +602,8 @@ public: std::string bufferFormat() const; /// return the default output format of the current backend std::string getDefaultOutputFormat() const; + /// return the default output flavor + OutputParams::FLAVOR getDefaultOutputFlavor(); /// bool doExport(std::string const & format, bool put_in_tempdir, @@ -662,6 +666,10 @@ private: void setFileName(support::FileName const & fname); /// std::vector backends() const; + /// A cache for the default flavors + typedef std::map DefaultFlavorCache; + /// + DefaultFlavorCache default_flavors_; /// void getLanguages(std::set &) const; /// Checks whether any of the referenced bibfiles have changed since the diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index a5beae5da6..1bfd7a2919 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -102,7 +102,8 @@ static bool getContent(BufferView const * view, bool fullSource, QString & qstr) if (par_begin > par_end) swap(par_begin, par_end); odocstringstream ostr; - view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource); + const_cast(view)->buffer().getSourceCode( + ostr, par_begin, par_end + 1, fullSource); docstring s = ostr.str(); static size_t crc = 0; size_t newcrc = crcCheck(s);