From 16f119cab5419dabc52f0e40cc876c391edc41cd Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 19 Jun 2009 15:11:33 +0000 Subject: [PATCH] XHTML output for InsetInclude. Here's the deal: * With verbatim, we include it verbatim. This would allow the inclusion of other HTML files. * With listings, we include it verbatim, wrapped in
.
* With Input and Include, we check if it's a LyX file. If not, we don't do
  anything, since we don't know how to include (say) a TeX file in the HTML
  output. (Wanna call tex4ht, anyone?) If it is a LyX file, we let it write
  itself as HTML, and include it.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30191 a592a061-630c-0410-9148-cb99ea01b6c8
---
 development/HTML/HTML.notes |  8 ++---
 src/insets/InsetInclude.cpp | 59 +++++++++++++++++++++++++++++++++----
 src/insets/InsetInclude.h   |  2 ++
 3 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/development/HTML/HTML.notes b/development/HTML/HTML.notes
index 133fe6cafb..2bc429a079 100644
--- a/development/HTML/HTML.notes
+++ b/development/HTML/HTML.notes
@@ -14,8 +14,9 @@ Known issues:
 
 These insets are basically done, though there are probably issues here and there,
 	and there are even some FIXMEs:
-	Bibitem, Branch, Caption, Collapsable, Footnote, Hyperlink, Info, Label, Line, 
-	Listings, Marginal, Note, Newline, Newpage, Quotes, Space, SpecialChar, Wrap
+	Bibitem, Branch, Caption, Collapsable, Footnote, Hyperlink, Include, Info, 
+	Label, Line,  Listings, Marginal, Note, Newline, Newpage, Quotes, Space, 
+	SpecialChar, Wrap
 
 These insets do nothing for XHTML:
 	ERT, OptArg, Phantom
@@ -63,9 +64,6 @@ These do not yet work and need some attention:
 		about export formats, etc, to get it completely right. We'll also want to make
 		some use of the params, eg, on width and height. I guess there is also some
 		issue about converting the graphics formats?
-	InsetInclude: I think we just want to include it, straightforwardly. Probably will
-		base this more on the latex() routine, then. Another possibility, maybe with a
-		flag of some sort, would be to do it as a separate file, to which we link.
 	InsetRef: Presumably, this is an internal link. But what should the text be, and how
 		should we get it? Probably some validation thing again, where labels tell us where 
 		they are. Alternatively, we could parse the aux file.
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 64e01e8739..d5621f6618 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -377,7 +377,7 @@ Buffer * InsetInclude::getChildBuffer() const
 Buffer * InsetInclude::loadIfNeeded() const
 {
 	// Don't try to load it again if we failed before.
-	if (failedtoload_)
+	if (failedtoload_ || isVerbatim(params()) || isListings(params()))
 		return 0;
 
 	// Use cached Buffer if possible.
@@ -388,13 +388,9 @@ Buffer * InsetInclude::loadIfNeeded() const
 		child_buffer_ = 0;
 	}
 
-	InsetCommandParams const & p = params();
-	if (isVerbatim(p) || isListings(p))
-		return 0;
-
 	string const parent_filename = buffer().absFileName();
 	FileName const included_file = 
-		makeAbsPath(to_utf8(p["filename"]), onlyPath(parent_filename));
+		makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
 
 	if (!isLyXFilename(included_file.absFilename()))
 		return 0;
@@ -626,6 +622,57 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
 }
 
 
+docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
+{
+	if (rp.inComment)
+		 return docstring();
+
+	// For verbatim and listings, we just include the contents of the file as-is.
+	// In the case of listings, we wrap it in 
.
+	bool const listing = isListings(params();
+	if (listing || isVerbatim(params())) {
+		if (listing)
+			os << "
\n";
+		// FIXME: We don't know the encoding of the file, default to UTF-8.
+		os << includedFilename(buffer(), params()).fileContents("UTF-8");
+		if (listing)
+			os << "
\n"; + return docstring(); + } + + // We don't (yet) know how to Input or Include non-LyX files. + // (If we wanted to get really arcane, we could run some tex2html + // converter on the included file. But that's just masochistic.) + if (!isLyXFilename(included_file.absFilename())) { + frontend::Alert::warning(_("Unsupported Inclusion"), + _("LyX does not know how to include non-LyX files when" + "generating HTML output. Offending file: ") + + params()["filename"]); + return docstring(); + } + + // In the other cases, we will generate the HTML and include it. + + // Check we're not trying to include ourselves. + // FIXME RECURSIVE INCLUDE + string const parent_filename = buffer().absFileName(); + FileName const included_file = + makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename)); + if (buffer().absFileName() == included_file.absFilename()) { + Alert::error(_("Recursive input"), + bformat(_("Attempted to include file %1$s in itself! " + "Ignoring inclusion."), params()["filename"])); + return docstring(); + } + + Buffer const * const ibuf = loadIfNeeded(); + if (!ibuf) + return docstring(); + ibuf->writeLyXHTMLSource(os, rp, true); + return docstring(); +} + + int InsetInclude::plaintext(odocstream & os, OutputParams const &) const { if (isVerbatim(params()) || isListings(params())) { diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 0e14405a8a..b302a9e31b 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -80,6 +80,8 @@ public: /// int docbook(odocstream &, OutputParams const &) const; /// + docstring xhtml(odocstream &, OutputParams const &) const; + /// void validate(LaTeXFeatures &) const; /// void addPreview(graphics::PreviewLoader &) const; -- 2.39.5