Restore XHTML output for InsetLabel and InsetRef. There are a couple

other fixes in here, too.

There is an issue here which I guess I'll deal with later, namely, that
the name attribute for <a> is unavailable in XHTML 1.1, which is what we
need for MathML support, at least in Firefox. Firefox will deal with it
if it's there, but the document won't validate. I'll figure out what to
do about this later.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32226 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-11-28 21:37:47 +00:00
parent c1b4b30ab5
commit c5738e5af6
6 changed files with 54 additions and 14 deletions

View File

@ -219,10 +219,17 @@ int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
}
docstring InsetLabel::xhtml(odocstream & os, OutputParams const &) const
docstring InsetLabel::xhtml(XHTMLStream & xs, OutputParams const &) const
{
os << "<a name=\"" << html::htmlize(getParam("name")) << "\"></a>";
// FIXME XHTML
// Unfortunately, the name attribute has been deprecated, so we have to use
// id here to get the document to validate as XHTML 1.1. This will cause a
// problem with some browsers, though, I'm sure. (Guess which!) So we will
// have to figure out what to do about this later.
string const attr = "id=\"" + html::cleanAttr(to_utf8(getParam("name"))) + "\"";
xs << CompTag("a", attr);
return docstring();
}
} // namespace lyx

View File

@ -44,11 +44,11 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(odocstream &, OutputParams const &) const;
docstring xhtml(XHTMLStream &, OutputParams const &) const;
///
static ParamInfo const & findInfo(std::string const &);
///
static std::string defaultCommand() { return "label"; };
static std::string defaultCommand() { return "label"; }
///
static bool isCompatibleCommand(std::string const & s)
{ return s == "label"; }

View File

@ -116,13 +116,16 @@ int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const
}
docstring InsetRef::xhtml(odocstream & os, OutputParams const &) const
docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
{
// FIXME What we'd really like to do is to be able to output some
// appropriate sort of text here. But to do that, we need to associate
// some sort of counter with the label, and we don't have that yet.
docstring const ref = html::htmlize(getParam("reference"));
os << "<a href=\"" << ref << "\">[" << ref << "]</a>";
docstring const ref = html::cleanAttr(getParam("reference"));
string const attr = "href=\"" + to_utf8(ref) + "\"";
xs << StartTag("a", attr);
xs << ref;
xs << EndTag("a");
return docstring();
}

View File

@ -55,7 +55,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(odocstream &, OutputParams const &) const;
docstring xhtml(XHTMLStream &, OutputParams const &) const;
/// the string that is passed to the TOC
void tocString(odocstream &) const;
///

View File

@ -110,6 +110,31 @@ string htmlize(string const & str) {
}
string cleanAttr(string const & str)
{
string newname;
string::const_iterator it = str.begin();
string::const_iterator en = str.end();
for (; it != en; ++it)
newname += isalnum(*it) ? *it : '_';
return newname;
}
docstring cleanAttr(docstring const & str)
{
docstring newname;
docstring::const_iterator it = str.begin();
docstring::const_iterator en = str.end();
for (; it != en; ++it)
if (isalnum(*it))
newname += *it;
else
newname += '_';
return newname;
}
bool isFontTag(string const & s)
{
return s == "em" || s == "strong"; // others?

View File

@ -31,9 +31,9 @@ class Text;
/// be escaped before passing to the constructor.
struct StartTag {
///
StartTag(std::string const & tag) : tag_(tag) {}
explicit StartTag(std::string const & tag) : tag_(tag) {}
///
StartTag(std::string const & tag, std::string const & attr,
explicit StartTag(std::string const & tag, std::string const & attr,
bool keepempty = false)
: tag_(tag), attr_(attr), keepempty_(keepempty) {}
/// <tag_ attr_>
@ -52,7 +52,7 @@ struct StartTag {
struct EndTag {
///
EndTag(std::string tag) : tag_(tag) {}
explicit EndTag(std::string tag) : tag_(tag) {}
/// </tag_>
docstring asEndTag() const;
///
@ -65,10 +65,10 @@ struct EndTag {
/// be escaped before passing to the constructor.
struct CompTag {
///
CompTag(std::string const & tag)
explicit CompTag(std::string const & tag)
: tag_(tag) {}
///
CompTag(std::string const & tag, std::string const & attr)
explicit CompTag(std::string const & tag, std::string const & attr)
: tag_(tag), attr_(attr) {}
/// <tag_ attr_ />
docstring asTag() const;
@ -146,10 +146,15 @@ namespace html {
docstring escapeChar(char_type c);
/// converts a string to a form safe for links, etc
docstring htmlize(docstring const & str);
/// cleans \param str for use as an atttribute by replacing
/// all non-alnum by "_"
docstring cleanAttr(docstring const & str);
///
std::string escapeChar(char c);
/// converts a string to a form safe for links, etc
///
std::string htmlize(std::string const & str);
///
std::string cleanAttr(std::string const & str);
// to be removed
/// \return true if tag was opened, false if not