1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

new escaping function for html tag attributes

This commit is contained in:
Lu Wang 2013-10-18 15:40:51 +08:00
parent 16326b8690
commit fd00c5f698
6 changed files with 49 additions and 12 deletions

1
TODO
View File

@ -1,5 +1,4 @@
tmp dir: use pid tmp dir: use pid
link.cc: outputURL -> outputUnicodes
remove page from dom -- UI option remove page from dom -- UI option
view hash view hash
update jquery update jquery

View File

@ -212,7 +212,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
<< "\" data-page-no=\"" << pageNum << "\" data-page-no=\"" << pageNum
<< "\" data-page-url=\""; << "\" data-page-url=\"";
outputURL(f_pages.fs, cur_page_filename); outputAttribute(f_pages.fs, cur_page_filename);
f_pages.fs << "\">"; f_pages.fs << "\">";
} }
@ -555,7 +555,7 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
else else
{ {
out << entry.prefix_external; out << entry.prefix_external;
outputURL(out, fn); outputAttribute(out, fn);
out << entry.suffix_external << endl; out << entry.suffix_external << endl;
if(copy) if(copy)

View File

@ -195,7 +195,7 @@ void HTMLRenderer::processLink(AnnotLink * al)
if(!dest_str.empty()) if(!dest_str.empty())
{ {
(*f_curpage) << "<a class=\"" << CSS::LINK_CN << "\" href=\""; (*f_curpage) << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
outputURL((*f_curpage), dest_str); outputAttribute((*f_curpage), dest_str);
(*f_curpage) << "\""; (*f_curpage) << "\"";
if(!dest_detail_str.empty()) if(!dest_detail_str.empty())

View File

@ -37,7 +37,7 @@ void HTMLRenderer::process_outline_items(GooList * items)
// we don't care dest is empty or not. // we don't care dest is empty or not.
f_outline.fs << "<li>" << "<a class=\"" << CSS::LINK_CN << "\" href=\""; f_outline.fs << "<li>" << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
outputURL(f_outline.fs, dest); outputAttribute(f_outline.fs, dest);
f_outline.fs << "\""; f_outline.fs << "\"";
if(!detail.empty()) if(!detail.empty())

View File

@ -86,6 +86,7 @@ void outputUnicodes(ostream & out, const Unicode * u, int uLen)
} }
} }
/*
static void outputHEX(ostream & out, char c) static void outputHEX(ostream & out, char c)
{ {
static const char * hexchars = "0123456789abcdef"; static const char * hexchars = "0123456789abcdef";
@ -99,11 +100,11 @@ void outputURL(ostream & out, const string & s)
{ {
dont_escape = new char [256]; dont_escape = new char [256];
memset(dont_escape, 0, 256 * sizeof(char)); memset(dont_escape, 0, 256 * sizeof(char));
/* / *
* http://tools.ietf.org/html/rfc3986#section-2 * http://tools.ietf.org/html/rfc3986#section-2
* *
* Also includes '%', in case that the original url has been escaped * Also includes '%', in case that the original url has been escaped
*/ * /
const char * no_escape_chars = ":/?#[]@!$&'()*+,;=" const char * no_escape_chars = ":/?#[]@!$&'()*+,;="
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
@ -126,6 +127,7 @@ void outputURL(ostream & out, const string & s)
} }
} }
} }
*/
void outputJSON(ostream & out, const string & s) void outputJSON(ostream & out, const string & s)
{ {
@ -147,4 +149,35 @@ void outputJSON(ostream & out, const string & s)
} }
} }
void outputAttribute(std::ostream & out, const std::string & s)
{
for (auto iter = s.begin(); iter != s.end(); ++iter)
{
char c = *iter;
switch(c)
{
case '&':
out << "&amp;";
break;
case '\"':
out << "&quot;";
break;
case '\'':
out << "&apos;";
break;
case '<':
out << "&lt;";
break;
case '>':
out << "&gt;";
break;
case '`': // for IE
out << "&#96;";
break;
default:
out << c;
}
}
}
} //namespace pdf2htmlEX } //namespace pdf2htmlEX

View File

@ -22,15 +22,20 @@ void outputUnicodes(std::ostream & out, const Unicode * u, int uLen);
/* /*
* URL encoding * URL escaping
*/
void outputURL(std::ostream & out, const std::string & s);
/*
* JSON encoding
*/ */
//void outputURL(std::ostream & out, const std::string & s);
/*
* JSON escaping
*/
void outputJSON(std::ostream & out, const std::string & s); void outputJSON(std::ostream & out, const std::string & s);
/*
* HTML tag attribute escaping
*/
void outputAttribute(std::ostream & out, const std::string & s);
} // namespace pdf2htmlEX } // namespace pdf2htmlEX
#endif //ENCODING_H__ #endif //ENCODING_H__