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:
parent
16326b8690
commit
fd00c5f698
1
TODO
1
TODO
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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())
|
||||||
|
@ -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())
|
||||||
|
@ -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 << "&";
|
||||||
|
break;
|
||||||
|
case '\"':
|
||||||
|
out << """;
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
out << "'";
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
out << "<";
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
out << ">";
|
||||||
|
break;
|
||||||
|
case '`': // for IE
|
||||||
|
out << "`";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
out << c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace pdf2htmlEX
|
} //namespace pdf2htmlEX
|
||||||
|
@ -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__
|
||||||
|
Loading…
Reference in New Issue
Block a user