+void InsetHyperlink::viewTarget() const
+{
+ if (getParam("type").empty()) { //==Web
+ QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
+ if (!QDesktopServices::openUrl(url))
+ LYXERR0("Unable to open URL!");
+ } else if (getParam("type") == "file:") {
+ FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
+ string const format = theFormats().getFormatFromFile(url);
+ theFormats().view(buffer(), url, format);
+ }
+}
+
+
+docstring makeURL(docstring const & url, docstring const & type) {
+ if (type == "other" ||
+ (!type.empty() && url.find(type) == 0))
+ return url;
+ return type + url;
+}
+
+
+void InsetHyperlink::latex(otexstream & os,
+ OutputParams const & runparams) const
+{
+ docstring url = getParam("target");
+ docstring name = getParam("name");
+ docstring const & utype = getParam("type");
+ static char_type const chars_url[2] = {'%', '#'};
+
+ // 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
+ // such as % correctly.
+ if (name.empty())
+ name = url;
+
+ if (!url.empty()) {
+ // Use URI/URL-style percent-encoded string (hexadecimal).
+ // We exclude some characters that must not be transformed
+ // in hrefs: % # / : ? = & ! * ' ( ) ; @ + $ , [ ]
+ // or that we need to treat manually: \.
+ url = to_percent_encoding(url, from_ascii("%#\\/:?=&!*'();@+$,[]"));
+ // We handle \ manually since \\ is valid