git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@28196 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-01-17 05:29:58 +00:00
parent 9b112f4619
commit 9158749b08
2 changed files with 24 additions and 15 deletions

View File

@ -67,24 +67,31 @@ docstring InsetHyperlink::screenLabel() const
int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
{
docstring url = getParam("target");
docstring name = getParam("name");
static docstring const backslash = from_ascii("\\");
static docstring const braces = from_ascii("{}");
static char_type const chars_url[2] = {'%', '#'};
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
// they are in the url field.
if (!url.empty()) {
// the chars_url[] characters must be handled for both, url and href
for (int k = 0; k < 2; k++) {
for (size_t i = 0, pos;
(pos = url.find(chars_url[k], i)) != string::npos;
i = pos + 2) {
url.replace(pos, 1, backslash + chars_url[k]);
}
// Replace the "\" character by its ASCII code according to the URL specifications
// because "\" is not allowed in URLs and by \href. Only do this when the
// following character is not also a "\", because "\\" is valid code
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("%5C"));
}
// add "http://" when the type is web (type = empty)
// and no "://" or "run:" is given
docstring type = getParam("type");
@ -95,12 +102,9 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
} // end if (!url.empty())
docstring name = getParam("name");
// The characters in chars_name[] need to be changed to a command when
// they are in the name field.
if (!name.empty()) {
// handle the "\" character, but only when the following character
// is not also a "\", because "\\" is valid code
docstring const textbackslash = from_ascii("\\textbackslash{}");
@ -110,6 +114,9 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
if (name[pos + 1] != '\\')
name.replace(pos, 1, textbackslash);
}
// The characters in chars_name[] need to be changed to a command when
// they are in the name field.
// Therefore the treatment of "\" must be the first thing
for (int k = 0; k < 6; k++) {
for (size_t i = 0, pos;
(pos = name.find(chars_name[k], i)) != string::npos;
@ -130,9 +137,8 @@ int InsetHyperlink::latex(odocstream & os, OutputParams const & runparams) const
if (runparams.moving_arg)
os << "\\protect";
//for the case there is no name given, the target is set as name
os << "\\href{" << getParam("type") << url << "}{"
<< (name.empty()? url : name) << '}';
// output the ready \href command
os << "\\href{" << getParam("type") << url << "}{" << name << '}';
return 0;
}

View File

@ -118,6 +118,9 @@ What's new
- For CJK documents using utf8 encoding, load the CJKutf8 package, if
available (part of bug 5386).
- Fix bugs when entering hyperlink paths containing special characters
(bug 5686).
* USER INTERFACE