mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 10:18:50 +00:00
InsetHyperlink.cpp: - fix my rash r28141
- bugfix allow the usage of "%" in the URL field git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28169 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1e84670849
commit
06e961047e
@ -67,32 +67,37 @@ docstring InsetHyperlink::screenLabel() const
|
|||||||
int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
|
int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
docstring url = getParam("target");
|
docstring url = getParam("target");
|
||||||
|
docstring name = getParam("name");
|
||||||
static docstring const backslash = from_ascii("\\");
|
static docstring const backslash = from_ascii("\\");
|
||||||
static docstring const braces = from_ascii("{}");
|
static docstring const braces = from_ascii("{}");
|
||||||
static char_type const chars_url[2] = {'%', '#'};
|
|
||||||
static char_type const chars_name[6] = {
|
static char_type const chars_name[6] = {
|
||||||
'&', '_', '$', '%', '#', '^'};
|
'&', '_', '$', '%', '#', '^'};
|
||||||
|
|
||||||
|
// For the case there is no name given, the target is set as name.
|
||||||
|
// Do this before !url.empty() and !name.empty() to handle characters
|
||||||
|
// like the "%" correctly.
|
||||||
|
if (name.empty())
|
||||||
|
name = url;
|
||||||
|
|
||||||
// The characters in chars_url[] need to be changed to a command when
|
// The characters in chars_url[] need to be changed to a command when
|
||||||
// they are in the url field.
|
// they are in the url field.
|
||||||
if (!url.empty()) {
|
if (!url.empty()) {
|
||||||
// the chars_url[] characters must be handled for both, url and href
|
// Replace the "\" character by its ASCII code according to the URL specifications
|
||||||
for (int k = 0; k < 2; k++) {
|
// because "\" is not allowed in URLs and by \href. Only do this when the
|
||||||
for (size_t i = 0, pos;
|
// following character is not also a "\", because "\\" is valid code
|
||||||
(pos = url.find(chars_url[k], i)) != string::npos;
|
|
||||||
i = pos + 2) {
|
|
||||||
url.replace(pos, 1, backslash + chars_url[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Replace the "\" character with a "/" because "\" is not allowed in
|
|
||||||
// URLs and by \href. Only do this when the following character
|
|
||||||
// is not also a "\", because "\\" is valid code
|
|
||||||
docstring const slash = from_ascii("/");
|
|
||||||
for (size_t i = 0, pos;
|
for (size_t i = 0, pos;
|
||||||
(pos = url.find('\\', i)) != string::npos;
|
(pos = url.find('\\', i)) != string::npos;
|
||||||
i = pos + 2) {
|
i = pos + 2) {
|
||||||
if (url[pos + 1] != '\\')
|
if (url[pos + 1] != '\\')
|
||||||
url.replace(pos, 1, slash);
|
url.replace(pos, 1, from_ascii("%5C"));
|
||||||
|
}
|
||||||
|
// "#" needs to be escapes to "\#", therefore the treatment
|
||||||
|
// of "\" must be done before
|
||||||
|
for (size_t i = 0, pos;
|
||||||
|
(pos = url.find('#', i)) != string::npos;
|
||||||
|
i = pos + 2) {
|
||||||
|
if (url[pos + 1] != '\\')
|
||||||
|
url.replace(pos, 1, from_ascii("\\#"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add "http://" when the type is web (type = empty)
|
// add "http://" when the type is web (type = empty)
|
||||||
@ -105,8 +110,6 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
|
|||||||
|
|
||||||
} // end if (!url.empty())
|
} // end if (!url.empty())
|
||||||
|
|
||||||
docstring name = getParam("name");
|
|
||||||
|
|
||||||
// The characters in chars_name[] need to be changed to a command when
|
// The characters in chars_name[] need to be changed to a command when
|
||||||
// they are in the name field.
|
// they are in the name field.
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
@ -121,6 +124,7 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
|
|||||||
}
|
}
|
||||||
// The characters in chars_name[] need to be changed to a command when
|
// The characters in chars_name[] need to be changed to a command when
|
||||||
// they are in the name field.
|
// they are in the name field.
|
||||||
|
// Therefore the treatment of "\" must be the first thing
|
||||||
for (int k = 0; k < 6; k++) {
|
for (int k = 0; k < 6; k++) {
|
||||||
for (size_t i = 0, pos;
|
for (size_t i = 0, pos;
|
||||||
(pos = name.find(chars_name[k], i)) != string::npos;
|
(pos = name.find(chars_name[k], i)) != string::npos;
|
||||||
@ -141,9 +145,8 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
|
|||||||
if (runparams.moving_arg)
|
if (runparams.moving_arg)
|
||||||
os << "\\protect";
|
os << "\\protect";
|
||||||
|
|
||||||
//for the case there is no name given, the target is set as name
|
// output the ready \href command
|
||||||
os << "\\href{" << getParam("type") << url << "}{"
|
os << "\\href{" << getParam("type") << url << "}{" << name << '}';
|
||||||
<< (name.empty()? url : name) << '}';
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user