mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
Auto-escape attributes.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32208 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
40fcb745a9
commit
508ee6560c
@ -75,6 +75,41 @@ docstring htmlize(docstring const & str) {
|
||||
}
|
||||
|
||||
|
||||
string escapeChar(char c)
|
||||
{
|
||||
string str;
|
||||
switch (c) {
|
||||
case ' ':
|
||||
str += " ";
|
||||
break;
|
||||
case '&':
|
||||
str += "&";
|
||||
break;
|
||||
case '<':
|
||||
str += "<";
|
||||
break;
|
||||
case '>':
|
||||
str += ">";
|
||||
break;
|
||||
default:
|
||||
str += c;
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// escape what needs escaping
|
||||
string htmlize(string const & str) {
|
||||
ostringstream d;
|
||||
string::const_iterator it = str.begin();
|
||||
string::const_iterator en = str.end();
|
||||
for (; it != en; ++it)
|
||||
d << escapeChar(*it);
|
||||
return d.str();
|
||||
}
|
||||
|
||||
|
||||
bool isFontTag(string const & s)
|
||||
{
|
||||
return s == "em" || s == "strong"; // others?
|
||||
@ -86,7 +121,7 @@ docstring StartTag::asTag() const
|
||||
{
|
||||
string output = "<" + tag_;
|
||||
if (!attr_.empty())
|
||||
output += " " + attr_;
|
||||
output += " " + html::htmlize(attr_);
|
||||
output += ">";
|
||||
return from_utf8(output);
|
||||
}
|
||||
@ -110,7 +145,7 @@ docstring CompTag::asTag() const
|
||||
{
|
||||
string output = "<" + tag_;
|
||||
if (!attr_.empty())
|
||||
output += " " + attr_;
|
||||
output += " " + html::htmlize(attr_);
|
||||
output += " />";
|
||||
return from_utf8(output);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define OUTPUT_XHTML_H
|
||||
|
||||
#include "support/docstream.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
@ -26,6 +27,8 @@ class Text;
|
||||
// Inspiration for the *Tag structs and for XHTMLStream
|
||||
// came from MathStream and its cousins.
|
||||
|
||||
/// Attributes will be escaped automatically and so should NOT
|
||||
/// be escaped before passing to the constructor.
|
||||
struct StartTag {
|
||||
///
|
||||
StartTag(std::string const & tag) : tag_(tag) {}
|
||||
@ -57,7 +60,9 @@ struct EndTag {
|
||||
};
|
||||
|
||||
|
||||
// Tags like <img />
|
||||
/// Tags like <img />
|
||||
/// Attributes will be escaped automatically and so should NOT
|
||||
/// be escaped before passing to the constructor.
|
||||
struct CompTag {
|
||||
///
|
||||
CompTag(std::string const & tag)
|
||||
@ -141,6 +146,10 @@ namespace html {
|
||||
docstring escapeChar(char_type c);
|
||||
/// converts a string to a form safe for links, etc
|
||||
docstring htmlize(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);
|
||||
|
||||
// to be removed
|
||||
/// \return true if tag was opened, false if not
|
||||
|
Loading…
x
Reference in New Issue
Block a user