Hi,
        this patch removes mixed content from output parameters and finally
implement ids mangling in SGML/XML.
--
José Abílio


-------------------------------------------------------------
A FCUP utiliza o sistema de webmail Horde/IMP (www.horde.org)

Visite: http://www.fc.up.pt/
Index: lib/layouts/db_stdclass.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/db_stdclass.inc,v
retrieving revision 1.17
diff -u -p -r1.17 db_stdclass.inc
--- lib/layouts/db_stdclass.inc	30 Oct 2004 19:26:52 -0000	1.17
+++ lib/layouts/db_stdclass.inc	31 Oct 2004 19:26:37 -0000
@@ -15,6 +15,7 @@ DefaultStyle            Standard
 
 ClassOptions
 #	Header             "PUBLIC "-//OASIS//DTD DocBook V4.1//EN""
+	Other		   ".-"
 End
 
 Style Standard
Index: src/output_docbook.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/output_docbook.C,v
retrieving revision 1.23
diff -u -p -r1.23 output_docbook.C
--- src/output_docbook.C	30 Oct 2004 18:44:55 -0000	1.23
+++ src/output_docbook.C	31 Oct 2004 19:26:37 -0000
@@ -107,7 +107,7 @@ ParagraphList::const_iterator makeParagr
 		if (par->layout() == defaultstyle && par->emptyTag()) {
 			par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
 		} else {
-			sgml::openTag(buf, os, *par);
+			sgml::openTag(buf, os, runparams, *par);
 			par->simpleDocBookOnePar(buf, os, runparams, outerFont(par - paragraphs.begin(), paragraphs));
 			sgml::closeTag(os, *par);
 			os << '\n';
@@ -130,7 +130,7 @@ ParagraphList::const_iterator makeEnviro
 	string item_tag;
 
 	// Opening outter tag
-	sgml::openTag(buf, os, *pbegin);
+	sgml::openTag(buf, os, runparams, *pbegin);
 	os << '\n';
 	if (bstyle->latextype == LATEX_ENVIRONMENT and bstyle->pass_thru)
 		os << "<![CDATA[";
@@ -138,7 +138,7 @@ ParagraphList::const_iterator makeEnviro
 	while (par != pend) {
 		LyXLayout_ptr const & style = par->layout();
 		ParagraphList::const_iterator send;
-		string id = par->getID();
+		string id = par->getID(buf, runparams);
 		string wrapper = "";
 		pos_type sep = 0;
 
@@ -225,7 +225,7 @@ ParagraphList::const_iterator makeComman
 	LyXLayout_ptr const & bstyle = par->layout();
 
 	//Open outter tag
-	sgml::openTag(buf, os, *pbegin);
+	sgml::openTag(buf, os, runparams, *pbegin);
 	os << '\n';
 
 	// Label around sectioning number:
Index: src/outputparams.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/outputparams.C,v
retrieving revision 1.2
diff -u -p -r1.2 outputparams.C
--- src/outputparams.C	16 Aug 2004 00:32:00 -0000	1.2
+++ src/outputparams.C	31 Oct 2004 19:26:37 -0000
@@ -17,7 +17,7 @@
 OutputParams::OutputParams()
 	: flavor(LATEX), nice(false), moving_arg(false),
 	  free_spacing(false), use_babel(false),
-	  mixed_content(false), linelen(0), depth(0),
+	  linelen(0), depth(0),
 	  exportdata(new ExportData)
 {}
 
Index: src/outputparams.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/outputparams.h,v
retrieving revision 1.10
diff -u -p -r1.10 outputparams.h
--- src/outputparams.h	26 Oct 2004 21:16:43 -0000	1.10
+++ src/outputparams.h	31 Oct 2004 19:26:37 -0000
@@ -73,12 +73,6 @@ struct OutputParams {
 	*/
 	bool use_babel;
 
-	/** Used for docbook to see if inside a region of mixed content.
-	    In that case all the white spaces are significant and cannot appear
-	    at the begin or end.
-	*/
-	bool mixed_content;
-
 	/** Line length to use with plaintext export.
 	*/
 	lyx::size_type linelen;
Index: src/paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.388
diff -u -p -r1.388 paragraph.C
--- src/paragraph.C	30 Oct 2004 22:14:01 -0000	1.388
+++ src/paragraph.C	31 Oct 2004 19:26:37 -0000
@@ -1356,7 +1356,7 @@ bool Paragraph::emptyTag() const
 }
 
 
-string Paragraph::getID() const
+string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const
 {
 	for (pos_type i = 0; i < size(); ++i) {
 		if (isInset(i)) {
@@ -1364,7 +1364,7 @@ string Paragraph::getID() const
 			InsetBase::Code lyx_code = inset->lyxCode();
 			if (lyx_code == InsetBase::LABEL_CODE) {
 				string const id = static_cast<InsetCommand const *>(inset)->getContents();
-				return "id=\"" + sgml::cleanID(id) + "\"";
+				return "id=\"" + sgml::cleanID(buf, runparams, id) + "\"";
 			}
 		}
 
Index: src/paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.139
diff -u -p -r1.139 paragraph.h
--- src/paragraph.h	30 Oct 2004 22:14:02 -0000	1.139
+++ src/paragraph.h	31 Oct 2004 19:26:37 -0000
@@ -133,7 +133,8 @@ public:
 	bool Paragraph::emptyTag() const;
 
 	/// Get the id of the paragraph, usefull for docbook and linuxdoc
-	std::string getID() const;
+	std::string getID(Buffer const & buf,
+			  OutputParams const & runparams) const;
 
 	// Get the first word of a paragraph, return the position where it left
 	lyx::pos_type getFirstWord(Buffer const & buf,
Index: src/sgml.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/sgml.C,v
retrieving revision 1.23
diff -u -p -r1.23 sgml.C
--- src/sgml.C	29 Oct 2004 23:08:03 -0000	1.23
+++ src/sgml.C	31 Oct 2004 19:26:37 -0000
@@ -17,6 +17,7 @@
 #include "bufferparams.h"
 #include "counters.h"
 #include "lyxtext.h"
+#include "outputparams.h"
 #include "paragraph.h"
 
 #include "support/lstrings.h"
@@ -120,7 +121,7 @@ string const uniqueID(string const label
 }
 
 
-string cleanID(std::string const & orig, std::string const & allowed)
+string cleanID(Buffer const & buf, OutputParams const & runparams, std::string const & orig)
 {
 	// The standard DocBook SGML declaration only allows letters,
 	// digits, '-' and '.' in a name.
@@ -130,16 +131,17 @@ string cleanID(std::string const & orig,
 	// and adds a number for uniqueness.
 	// If you know what you are doing, you can set allowed==""
 	// to disable this mangling.
-	
+	LyXTextClass const & tclass = buf.params().getLyXTextClass();
+	string const allowed = runparams.flavor == OutputParams::XML? ".-_:":tclass.options();
+
+	if (allowed.empty())
+		return orig;
+
 	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;
@@ -204,14 +206,14 @@ void closeTag(ostream & os, string const
 }
 
 
-void openTag(Buffer const & buf, ostream & os, Paragraph const & par)
+void openTag(Buffer const & buf, ostream & os, OutputParams const & runparams, Paragraph const & par)
 {
 	LyXLayout_ptr const & style = par.layout();
 	string const & name = style->latexname();
 	string param = style->latexparam();
 	Counters & counters = buf.params().getLyXTextClass().counters();
 
-	string id = par.getID();
+	string id = par.getID(buf, runparams);
 
 	string attribute;
 	if(!id.empty()) {
Index: src/sgml.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/sgml.h,v
retrieving revision 1.17
diff -u -p -r1.17 sgml.h
--- src/sgml.h	29 Oct 2004 23:08:03 -0000	1.17
+++ src/sgml.h	31 Oct 2004 19:26:37 -0000
@@ -21,6 +21,7 @@
 
 class Buffer;
 class Paragraph;
+class OutputParams;
 
 namespace sgml {
 
@@ -34,10 +35,11 @@ std::pair<bool, std::string> escapeChar(
 /// 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());
+/// replaces illegal characters from SGML/XML ID attributes
+std::string cleanID(Buffer const & buf, OutputParams const & runparams,
+		    std::string const & orig);
 
-/// returns a uniq numeric id
+/// returns a unique numeric id
 std::string const uniqueID(std::string const label);
 
 /// Opens tag
@@ -45,7 +47,8 @@ void openTag(std::ostream & os, std::str
 	    std::string const & attribute = std::string());
 
 /// Open tag
-void openTag(Buffer const & buf, std::ostream & os, Paragraph const & par);
+void openTag(Buffer const & buf, std::ostream & os,
+	     OutputParams const & runparams, Paragraph const & par);
 
 /// Close tag
 void closeTag(std::ostream & os, std::string const & name);
Index: src/tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.214
diff -u -p -r1.214 tabular.C
--- src/tabular.C	5 Oct 2004 10:11:29 -0000	1.214
+++ src/tabular.C	31 Oct 2004 19:26:37 -0000
@@ -2215,9 +2215,7 @@ int LyXTabular::docbookRow(Buffer const 
 		}
 
 		os << '>';
-		OutputParams runp = runparams;
-		runp.mixed_content = true;
-		ret += getCellInset(cell).docbook(buf, os, runp);
+		ret += getCellInset(cell).docbook(buf, os, runparams);
 		os << "</entry>\n";
 		++cell;
 	}
Index: src/insets/insetcharstyle.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v
retrieving revision 1.24
diff -u -p -r1.24 insetcharstyle.C
--- src/insets/insetcharstyle.C	31 Oct 2004 12:30:26 -0000	1.24
+++ src/insets/insetcharstyle.C	31 Oct 2004 19:26:38 -0000
@@ -195,7 +195,7 @@ int InsetCharStyle::docbook(Buffer const
 	ParagraphList::const_iterator par = paragraphs().begin();
         ParagraphList::const_iterator end = paragraphs().end();
 
-	sgml::openTag(os, params_.latexname, par->getID() + params_.latexparam);
+	sgml::openTag(os, params_.latexname, par->getID(buf, runparams) + params_.latexparam);
 
         for (; par != end; ++par) {
 		par->simpleDocBookOnePar(buf, os, runparams,
Index: src/insets/insetlabel.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetlabel.C,v
retrieving revision 1.96
diff -u -p -r1.96 insetlabel.C
--- src/insets/insetlabel.C	29 Oct 2004 23:08:03 -0000	1.96
+++ src/insets/insetlabel.C	31 Oct 2004 19:26:38 -0000
@@ -133,17 +133,17 @@ int InsetLabel::plaintext(Buffer const &
 }
 
 
-int InsetLabel::linuxdoc(Buffer const &, ostream & os,
-			 OutputParams const &) const
+int InsetLabel::linuxdoc(Buffer const & buf, ostream & os,
+			 OutputParams const & runparams) const
 {
-	os << "<label id=\"" << sgml::cleanID(getContents()) << "\" >";
+	os << "<label id=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" >";
 	return 0;
 }
 
 
-int InsetLabel::docbook(Buffer const &, ostream & os,
-			OutputParams const &) const
+int InsetLabel::docbook(Buffer const & buf, ostream & os,
+			OutputParams const & runparams) const
 {
-	os << "<!-- anchor id=\"" << sgml::cleanID(getContents()) << "\" -->";
+	os << "<!-- anchor id=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" -->";
 	return 0;
 }
Index: src/insets/insetref.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetref.C,v
retrieving revision 1.91
diff -u -p -r1.91 insetref.C
--- src/insets/insetref.C	29 Oct 2004 23:08:03 -0000	1.91
+++ src/insets/insetref.C	31 Oct 2004 19:26:38 -0000
@@ -102,24 +102,24 @@ int InsetRef::plaintext(Buffer const &, 
 }
 
 
-int InsetRef::linuxdoc(Buffer const &, ostream & os,
-		       OutputParams const &) const
+int InsetRef::linuxdoc(Buffer const & buf, ostream & os,
+		       OutputParams const & runparams) const
 {
-	os << "<ref id=\"" << sgml::cleanID(getContents())
+	os << "<ref id=\"" << sgml::cleanID(buf, runparams, getContents())
 	   << "\" name=\"" << getOptions() << "\" >";
 	return 0;
 }
 
 
-int InsetRef::docbook(Buffer const &, ostream & os,
+int InsetRef::docbook(Buffer const & buf, ostream & os,
 		      OutputParams const & runparams) const
 {
 	if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
-		os << "<xref linkend=\"" << sgml::cleanID(getContents()) << "\" />";
+		os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" />";
 	} else if (getOptions().empty()) {
-		os << "<xref linkend=\"" << sgml::cleanID(getContents()) << "\">";
+		os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\">";
 	} else {
-		os << "<link linkend=\"" << sgml::cleanID(getContents())
+		os << "<link linkend=\"" << sgml::cleanID(buf, runparams, getContents())
 		   << "\">" << getOptions() << "</link>";
 	}
 
Index: src/insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.438
diff -u -p -r1.438 insettabular.C
--- src/insets/insettabular.C	23 Oct 2004 09:46:33 -0000	1.438
+++ src/insets/insettabular.C	31 Oct 2004 19:26:38 -0000
@@ -924,15 +924,11 @@ int InsetTabular::docbook(Buffer const &
 
 	if (!master) {
 		os << "<informaltable>";
-		if (runparams.mixed_content)
-			os << endl;
 		++ret;
 	}
 	ret += tabular.docbook(buf, os, runparams);
 	if (!master) {
 		os << "</informaltable>";
-		if (runparams.mixed_content)
-			os << endl;
 		++ret;
 	}
 	return ret;
Index: src/mathed/math_hullinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v
retrieving revision 1.154
diff -u -p -r1.154 math_hullinset.C
--- src/mathed/math_hullinset.C	29 Oct 2004 23:08:04 -0000	1.154
+++ src/mathed/math_hullinset.C	31 Oct 2004 19:26:38 -0000
@@ -1346,7 +1346,7 @@ int MathHullInset::docbook(Buffer const 
 
 	string bname = name;
 	if (!label(0).empty()) 
-		bname += " id=\"" + sgml::cleanID(label(0)) + "\"";
+		bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\"";
 	ms << MTag(bname.c_str());
 
 	ostringstream ls;
@@ -1371,7 +1371,7 @@ int MathHullInset::docbook(Buffer const 
 	
 	ms <<  "<graphic fileref=\"eqn/";
 	if ( !label(0).empty()) 
-		ms << sgml::cleanID(label(0));
+		ms << sgml::cleanID(buf, runparams, label(0));
 	else {
 		// Some arbitrary unique number for this os. 
 		// Note that each call of math_hullinset::docbook()
Index: src/mathed/ref_inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ref_inset.C,v
retrieving revision 1.47
diff -u -p -r1.47 ref_inset.C
--- src/mathed/ref_inset.C	29 Oct 2004 23:08:04 -0000	1.47
+++ src/mathed/ref_inset.C	31 Oct 2004 19:26:38 -0000
@@ -14,6 +14,7 @@
 
 #include "BufferView.h"
 #include "LaTeXFeatures.h"
+#include "buffer.h"
 #include "cursor.h"
 #include "debug.h"
 #include "funcrequest.h"
@@ -138,16 +139,16 @@ int RefInset::linuxdoc(std::ostream & os
 }
 
 
-int RefInset::docbook(std::ostream & os, OutputParams const & runparams) const
+int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
 {
 	if (cell(1).empty()) {
-		os << "<xref linkend=\"" << sgml::cleanID(asString(cell(0)));
+		os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
 		if (runparams.flavor == OutputParams::XML) 
 			os << "\"/>";
 		else
 			os << "\">";
 	} else {
-		os << "<link linkend=\"" << sgml::cleanID(asString(cell(0)))
+		os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
 		   << "\">" << asString(cell(1)) << "</link>";
 	}
 
Index: src/mathed/ref_inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ref_inset.h,v
retrieving revision 1.24
diff -u -p -r1.24 ref_inset.h
--- src/mathed/ref_inset.h	18 Mar 2004 12:53:43 -0000	1.24
+++ src/mathed/ref_inset.h	31 Oct 2004 19:26:38 -0000
@@ -14,6 +14,7 @@
 
 
 #include "command_inset.h"
+class Buffer;
 
 // for \ref
 class RefInset : public CommandInset {
@@ -40,7 +41,7 @@ public:
 	/// linuxdoc output
 	int linuxdoc(std::ostream & os, OutputParams const &) const;
 	/// docbook output
-	int docbook(std::ostream & os, OutputParams const &) const;
+	int docbook(Buffer const & buf, std::ostream & os, OutputParams const &) const;
 
 	/// small wrapper for the time being
 	DispatchResult localDispatch(FuncRequest & cmd);

Reply via email to