On 12/03/2011 08:23 PM, Rob Oakes wrote: > Dear LyX Developers, > > I've spent some time today working on a patch to support exporting the > LyX CSS stylesheet as a separate file. This is what I've come up with > so far. Would you mind having a look and letting me know if there is > amore efficient way to do it? > > ++ Line 1773, Buffer.cpp > > if (params().html_css_as_file) { > lyxerr << "Export Separate CSS: True"; > // Create a Link to the Stylesheet > os << "<link rel='stylesheet' href='docstyle.css' > type='text/css'>\n"; > // Create a New Stream for CSS > ofdocstream ocss; > string const fcssname = filePath() + "docstyle.css"; > This file should be written to the *temporary* directory, in the first instance---all files for export should first be written there---and registered as an included file. This would be something like: string const fcssname = addName(temppath(), "docstyle.css"); Then runparams.exportdata->addExportedFile(fcssname); if it opens correctly (or, I guess, after it closes correctly).
> > // Check to see if it is open > if (!openFileWrite(ocss, FileName(fcssname))) > return; > If this fails we should probably fall back to writing it to the file header. > // Write Styles > docstring const styleinfo = > features.getTClassHTMLStyles(); > if (!styleinfo.empty()) { > ocss << styleinfo > << "\n"; > } > if (needfg) > ocss << " color: " > << > from_ascii(X11hexname(params().fontcolor)) > << ";\n"; > if (needbg) > ocss << " background-color: " > << > from_ascii(X11hexname(params().backgroundcolor)) > << ";\n"; > ocss.close(); > if (ocss.fail()) > lyxerr << "File '" << fcssname << "' was not > closed properly." << endl; > Similarly here: If this fails, fall back to what follows. > } > else { > lyxerr << "Export Separate CSS: False"; > os << "\n<!-- Layout-provided Styles -->\n"; > docstring const styleinfo = > features.getTClassHTMLStyles(); > if (!styleinfo.empty()) { > os << "<style type='text/css'>\n" > << styleinfo << "\n"; > } > if (needfg || needbg) { > os << "<style type='text/css'>\nbody > {\n"; > if (needfg) > os << " color: " > << > from_ascii(X11hexname(params().fontcolor)) > << ";\n"; > if (needbg) > os << " background-color: " > << > from_ascii(X11hexname(params().backgroundcolor)) > << ";\n"; > os << "}\n</style>\n"; > } > } > os << "</head>\n"; > } > Otherwise, this looks good. And useful. Richard