+2004-10-29 José Matos <jamatos@lyx.org>
+
+ * output_docbook.C (makeEnvironment):
+ * sgml.C (openTag):
+ * paragraph.[Ch] (getID): rename function, and return it enclosed in id="...".
+
+2004-10-29 Andreas Vox <vox@isp.uni-luebeck.de>
+
+ * sgml.[Ch] (uniqueID): returns a unique id for a given label.
+ (cleanID): sanitize any id.
+
2004-10-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* buffer.C, lyxlex_pimpl.C:
+2004-10-29 José Matos <jamatos@lyx.org>
+
+ * insetgraphics.C (uniqueID): transfered to sgml.C
+
+2004-10-29 Andreas Vox <vox@isp.uni-luebeck.de>
+
+ * insetlabel.C (docbook, linuxdoc):
+ * insetref.C (docbook, linuxdoc) sanitize id.
+
2004-10-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ExternalSupport.C: s/getExtFromContents/getFormatFromContents/
#include "metricsinfo.h"
#include "mover.h"
#include "outputparams.h"
+#include "sgml.h"
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
#include "support/lyxlib.h" // float_equal
#include "support/os.h"
#include "support/systemcall.h"
-#include "support/tostr.h"
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
}
-string const uniqueID()
-{
- static unsigned int seed = 1000;
- return "graph" + tostr(++seed);
-}
-
-
string findTargetFormat(string const & format, OutputParams const & runparams)
{
// Are we using latex or pdflatex?
InsetGraphics::InsetGraphics()
- : graphic_label(uniqueID()),
+ : graphic_label(sgml::uniqueID("graph")),
graphic_(new RenderGraphic(this))
{}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
: InsetOld(ig),
boost::signals::trackable(),
- graphic_label(uniqueID()),
+ graphic_label(sgml::uniqueID("graph")),
graphic_(new RenderGraphic(*ig.graphic_, this))
{
setParams(ig.params());
#include "lyxtext.h"
#include "paragraph.h"
#include "pariterator.h"
+#include "sgml.h"
#include "frontends/LyXView.h"
int InsetLabel::linuxdoc(Buffer const &, ostream & os,
OutputParams const &) const
{
- os << "<label id=\"" << getContents() << "\" >";
+ os << "<label id=\"" << sgml::cleanID(getContents()) << "\" >";
return 0;
}
int InsetLabel::docbook(Buffer const &, ostream & os,
OutputParams const &) const
{
- os << "<!-- anchor id=\"" << getContents() << "\" -->";
+ os << "<!-- anchor id=\"" << sgml::cleanID(getContents()) << "\" -->";
return 0;
}
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "outputparams.h"
+#include "sgml.h"
#include "frontends/LyXView.h"
int InsetRef::linuxdoc(Buffer const &, ostream & os,
OutputParams const &) const
{
- os << "<ref id=\"" << getContents()
+ os << "<ref id=\"" << sgml::cleanID(getContents())
<< "\" name=\"" << getOptions() << "\" >";
return 0;
}
OutputParams const & runparams) const
{
if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
- os << "<xref linkend=\"" << getContents() << "\" />";
+ os << "<xref linkend=\"" << sgml::cleanID(getContents()) << "\" />";
} else if (getOptions().empty()) {
- os << "<xref linkend=\"" << getContents() << "\">";
+ os << "<xref linkend=\"" << sgml::cleanID(getContents()) << "\">";
} else {
- os << "<link linkend=\"" << getContents()
+ os << "<link linkend=\"" << sgml::cleanID(getContents())
<< "\">" << getOptions() << "</link>";
}
+2004-10-29 Andreas Vox <vox@isp.uni-luebeck.de>
+
+ * math_hullinset.C (docbook):
+ * ref_inset.C (docbook): sanitize ids, clean exported docbook.
+
2004-10-15 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* math_hullinset.C (mutate): fix endless loop for unknown types
#include "lyx_main.h"
#include "lyxrc.h"
#include "outputparams.h"
+#include "sgml.h"
#include "textpainter.h"
#include "undo.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
+#include "support/lstrings.h"
+
#include <boost/bind.hpp>
#include <sstream>
using lyx::cap::grabAndEraseSelection;
+using lyx::support::subst;
using std::endl;
using std::max;
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
-#include "support/lstrings.h"
#include "support/lyxlib.h"
name = "informalequation";
string bname = name;
- if (! label(0).empty()) bname += " id=\"" + label(0)+ "\"";
+ if (!label(0).empty())
+ bname += " id=\"" + sgml::cleanID(label(0)) + "\"";
ms << MTag(bname.c_str());
+ ostringstream ls;
if (runparams.flavor == OutputParams::XML) {
- ms << MTag("math");
- MathGridInset::mathmlize(ms);
- ms << ETag("math");
- ms << MTag("alt role=\"tex\" ");
- ostringstream ls;
+ ms << MTag("alt role=\"tex\" ");
+ // Workaround for db2latex: db2latex always includes equations with
+ // \ensuremath{} or \begin{display}\end{display}
+ // so we strip LyX' math environment
WriteStream wi(ls, false, false);
MathGridInset::write(wi);
- ms << ls.str();
- ms << ETag("alt");
+ ms << subst(subst(ls.str(), "&", "&"), "<", "<");
+ ms << ETag("alt");
+ ms << MTag("math");
+ MathGridInset::mathmlize(ms);
+ ms << ETag("math");
} else {
- ms << MTag("alt role=\"tex\" ");
- res = latex(buf, ms.os(), runparams);
- ms << ETag("alt");
+ ms << MTag("alt role=\"tex\"");
+ res = latex(buf, ls, runparams);
+ ms << subst(subst(ls.str(), "&", "&"), "<", "<");
+ ms << ETag("alt");
}
-
+
+ ms << "<graphic fileref=\"eqn/";
+ if ( !label(0).empty())
+ ms << sgml::cleanID(label(0));
+ else {
+ // Some arbitrary unique number for this os.
+ // Note that each call of math_hullinset::docbook()
+ // will increase the os position by at least 60 chars or more
+ ms << sgml::uniqueID("anon");
+ }
+ if (runparams.flavor == OutputParams::XML)
+ ms << "\"/>";
+ else
+ ms << "\">";
+
ms << ETag(name.c_str());
return ms.line() + res;
}
#include "math_data.h"
#include "math_factory.h"
#include "math_support.h"
+#include "outputparams.h"
+#include "sgml.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
{
os << "<ref id=\"" << asString(cell(0))
- << "\" name=\"" << asString(cell(1)) << "\" >";
+ << "\" name=\"" << asString(cell(1)) << "\">";
return 0;
}
-int RefInset::docbook(std::ostream & os, OutputParams const &) const
+int RefInset::docbook(std::ostream & os, OutputParams const & runparams) const
{
if (cell(1).empty()) {
- os << "<xref linkend=\"" << asString(cell(0)) << "\">";
+ os << "<xref linkend=\"" << sgml::cleanID(asString(cell(0)));
+ if (runparams.flavor == OutputParams::XML)
+ os << "\"/>";
+ else
+ os << "\">";
} else {
- os << "<link linkend=\"" << asString(cell(0))
+ os << "<link linkend=\"" << sgml::cleanID(asString(cell(0)))
<< "\">" << asString(cell(1)) << "</link>";
}
while (par != pend) {
LyXLayout_ptr const & style = par->layout();
ParagraphList::const_iterator send;
- string id = par->getDocbookId();
- id = id.empty()? "" : " id = \"" + id + "\"";
+ string id = par->getID();
string wrapper = "";
pos_type sep = 0;
}
-string Paragraph::getDocbookId() const
+string Paragraph::getID() const
{
for (pos_type i = 0; i < size(); ++i) {
if (isInset(i)) {
InsetBase const * inset = getInset(i);
InsetBase::Code lyx_code = inset->lyxCode();
if (lyx_code == InsetBase::LABEL_CODE) {
- return static_cast<InsetCommand const *>(inset)->getContents();
+ string const id = static_cast<InsetCommand const *>(inset)->getContents();
+ return "id=\"" + sgml::cleanID(id) + "\"";
}
}
OutputParams const & runparams,
lyx::depth_type depth) const;
- /// Get the id of the paragraph, usefull for docbook
- std::string getDocbookId() const;
+ /// Get the id of the paragraph, usefull for docbook and linuxdoc
+ std::string getID() const;
// Get the first word of a paragraph, return the position where it left
lyx::pos_type getFirstWord(Buffer const & buf,
#include <boost/tuple/tuple.hpp>
+#include <map>
#include <sstream>
using lyx::support::subst;
using std::make_pair;
-
+using std::map;
using std::ostream;
using std::ostringstream;
using std::pair;
}
+string const uniqueID(string const label)
+{
+ static unsigned int seed = 1000;
+ return label + tostr(++seed);
+}
+
+
+string cleanID(std::string const & orig, std::string const & allowed)
+{
+ // The standard DocBook SGML declaration only allows letters,
+ // digits, '-' and '.' in a name.
+ // Since users might change that declaration one has to cater
+ // for additional allowed characters.
+ // This routine replaces illegal characters by '-' or '.'
+ // and adds a number for uniqueness.
+ // If you know what you are doing, you can set allowed==""
+ // to disable this mangling.
+
+ string::const_iterator it = orig.begin();
+ string::const_iterator end = orig.end();
+
+ string content;
+
+ if (allowed.empty()) {
+ return orig;
+ }
+
+ typedef map<string, string> MangledMap;
+ static MangledMap mangledNames;
+ static int mangleID = 1;
+
+ MangledMap::const_iterator const known = mangledNames.find(orig);
+ if (known != mangledNames.end())
+ return (*known).second;
+
+ // make sure it starts with a letter
+ if (!isalpha(*it) && allowed.find(*it) >= allowed.size())
+ content += "x";
+
+ bool mangle = false;
+ for (; it != end; ++it) {
+ char c = *it;
+ if (isalpha(c) || isdigit(c) || c == '-' || c == '.' || allowed.find(c) < allowed.size())
+ content += c;
+ else if (c == '_' || c == ' ') {
+ mangle = true;
+ content += "-";
+ }
+ else if (c == ':' || c == ',' || c == ';' || c == '!') {
+ mangle = true;
+ content += ".";
+ }
+ else {
+ mangle = true;
+ }
+ }
+ if (mangle) {
+ content += "-" + tostr(mangleID++);
+ }
+ else if (isdigit(content[content.size()-1])) {
+ content += ".";
+ }
+
+ mangledNames[orig] = content;
+
+ return content;
+}
+
+
void openTag(ostream & os, string const & name, string const & attribute)
{
// This should be fixed in layout files later.
string param = style->latexparam();
Counters & counters = buf.params().getLyXTextClass().counters();
- string id = par.getDocbookId();
- id = id.empty()? "" : " id = \"" + id + "\"";
+ string id = par.getID();
string attribute;
if(!id.empty()) {
/// Escape a word instead of a single character
std::string escapeString(std::string const & raw);
+/// replaces illegal chars like ':' or '_' from SGML ID attributes
+std::string cleanID(std::string const & orig, std::string const & allowed = std::string());
+
+/// returns a uniq numeric id
+std::string const uniqueID(std::string const label);
+
/// Opens tag
void openTag(std::ostream & os, std::string const & name,
std::string const & attribute = std::string());