Remove mixed_content from output parameters.

Escape ids to always produce legal output.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9157 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
José Matox 2004-11-02 11:25:20 +00:00
parent 76cd9510e9
commit 1ecc7b79cd
18 changed files with 75 additions and 56 deletions

View File

@ -1,3 +1,13 @@
2004-11-02 José Matos <jamatos@lyx.org>
* output_docbook.C (docbook):
* paragraph.C (getID):
* sgml.[Ch] (openTag, cleanID): escape characters inside ids to
garantee that the output is always legal.
* tabular.C (docbook):
* outputprams.[Ch]: remove mixed contents.
2004-11-01 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* text2.C (setCounter): prevent endless loop

View File

@ -1,3 +1,13 @@
2004-11-02 José Matos <jamatos@lyx.org>
* insetcharstyle.C (docbook):
* insetlabel.C (linuxdoc, docbook):
* insetref.C (linuxdoc, docbook): escape chacters in id to produce
always legal output.
* insettabular.C (docbook): mixed content no longer belongs to
output parameters.
2004-11-01 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetcharstyle.C (priv_dispatch): prevent paragraph breaks

View File

@ -201,7 +201,7 @@ int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
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,

View File

@ -133,17 +133,17 @@ int InsetLabel::plaintext(Buffer const &, ostream & os,
}
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;
}

View File

@ -102,24 +102,24 @@ int InsetRef::plaintext(Buffer const &, ostream & os,
}
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>";
}

View File

@ -924,15 +924,11 @@ int InsetTabular::docbook(Buffer const & buf, ostream & os,
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;

View File

@ -1,3 +1,9 @@
2004-11-02 José Matos <jamatos@lyx.org>
* ref_inset.[Ch] (docbook):
* math_hullinset.C (docbook): remove useless comment. Escape the
id to always be valid.
2004-10-29 Andreas Vox <vox@isp.uni-luebeck.de>
* math_hullinset.C (docbook):

View File

@ -1346,7 +1346,7 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
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,11 +1371,8 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
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()
// will increase the os position by at least 60 chars or more
ms << sgml::uniqueID("anon");
}
if (runparams.flavor == OutputParams::XML)

View File

@ -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, OutputParams const &) const
}
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>";
}

View File

@ -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);

View File

@ -107,7 +107,7 @@ ParagraphList::const_iterator makeParagraph(Buffer const & buf,
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 makeEnvironment(Buffer const & buf,
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 makeEnvironment(Buffer const & buf,
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 makeCommand(Buffer const & buf,
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:

View File

@ -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)
{}

View File

@ -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;

View File

@ -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) + "\"";
}
}

View File

@ -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,

View File

@ -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, std::string const & allowed)
// 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 & name)
}
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()) {

View File

@ -21,6 +21,7 @@
class Buffer;
class Paragraph;
class OutputParams;
namespace sgml {
@ -34,10 +35,11 @@ std::pair<bool, std::string> escapeChar(char c);
/// 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::string const & name,
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);

View File

@ -2215,9 +2215,7 @@ int LyXTabular::docbookRow(Buffer const & buf, ostream & os, int row,
}
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;
}