Also, perform the URL fixing magic for DocBook and XHTML.
As it was, it was impossible to enter e.g. "tel:" type links. Now
choosing the "Other" type just outputs the URL as given.
Also, the addition of "http" or "file" was not being done for
DocBook and XHTML. Now it is.
-----------------------
+2022-12-25 Richard Kimberly Heck <rikiheck@lyx.org>
+ * Format incremented to 614: New "Other" type for hyperlinks
+
2022-12-11 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 613: Support \\fonts_default_family for non-TeX fonts.
document.header[i] = "\\font_default_family default"
add_to_preamble(document, ["\\renewcommand{\\familydefault}{\\" + dfamily + "}"])
-
+
+
+def revert_hyper_other(document):
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset CommandInset href", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(document.body, i)
+ if j == -1:
+ document.warning("Cannot find end of inset at line " << str(i))
+ i += 1
+ continue
+ k = find_token(document.body, "type \"other\"", i, j)
+ if k == -1:
+ i = j
+ continue
+ # build command
+ n = find_token(document.body, "name", i, j)
+ t = find_token(document.body, "target", i, j)
+ if n == -1 or t == -1:
+ document.warning("Malformed hyperlink inset at line " + str(i))
+ i = j
+ continue
+ name = document.body[n][6:-1]
+ target = document.body[t][8:-1]
+ cmd = "\href{" + target + "}{" + name + "}"
+ ecmd = put_cmd_in_ert(cmd)
+ document.body[i:j+1] = ecmd
+ i += 1
+
+
##
# Conversion hub
#
[610, []],
[611, []],
[612, [convert_starred_refs]],
- [613, []]
+ [613, []],
+ [614, []]
]
-revert = [[612, [revert_familydefault]],
+revert = [[613, [revert_hyper_other]],
+ [612, [revert_familydefault]],
[611, [revert_starred_refs]],
[610, []],
[609, [revert_index_macros]],
#include "insets/InsetHyperlink.h"
+#include "support/debug.h"
+
#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
// GCC couldn't find operator==
namespace lyx {
this, SIGNAL(changed()));
connect(fileRB, SIGNAL(clicked()),
this, SIGNAL(changed()));
+ connect(noneRB, SIGNAL(clicked()),
+ this, SIGNAL(changed()));
setFocusProxy(targetED);
}
emailRB->setChecked(true);
else if (type == "file:")
fileRB->setChecked(true);
+ else if (type == "other")
+ noneRB->setChecked(true);
+ else
+ LYXERR0("Unknown hyperlink type: " << type);
}
targetED->setText(toqstr(params["target"]));
nameED->setText(toqstr(params["name"]));
literalCB->setChecked(params["literal"] == "true");
- if (params["type"] == from_utf8("mailto:"))
+ if (params["type"] == "mailto:")
emailRB->setChecked(true);
- else if (params["type"] == from_utf8("file:"))
+ else if (params["type"] == "file:")
fileRB->setChecked(true);
+ else if (params["type"] == "other")
+ noneRB->setChecked(true);
else
webRB->setChecked(true);
return true;
params["type"] = from_utf8("mailto:");
else if (fileRB->isChecked())
params["type"] = from_utf8("file:");
+ else if (noneRB->isChecked())
+ params["type"] = from_utf8("other");
params["literal"] = literalCB->isChecked()
? from_ascii("true") : from_ascii("false");
params.setCmdName("href");
<rect>
<x>0</x>
<y>0</y>
- <width>290</width>
- <height>188</height>
+ <width>306</width>
+ <height>226</height>
</rect>
</property>
<property name="windowTitle">
</property>
</widget>
</item>
+ <item>
+ <widget class="QRadioButton" name="noneRB">
+ <property name="text">
+ <string>Other</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>112</width>
+ <width>40</width>
<height>20</height>
</size>
</property>
{
switch (cmd.action()) {
case LFUN_INSET_EDIT: {
+ docstring const & utype = getParam("type");
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
- bool url_valid = getParam("type").empty() && url.isValid();
-
- flag.setEnabled(url_valid || getParam("type") == "file:");
+ bool url_valid = utype.empty() && url.isValid();
+ flag.setEnabled(url_valid || utype == "file:");
return true;
}
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);
}
+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 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.
// add "http://" when the type is web (type = empty)
// and no "://" or "run:" is given
- docstring type = getParam("type");
if (url.find(from_ascii("://")) == string::npos
&& url.find(from_ascii("run:")) == string::npos
- && type.empty())
+ && utype.empty())
url = from_ascii("http://") + url;
} // end if (!url.empty())
ParamInfo::HANDLING_LATEXIFY);
// replace the tilde by the \sim character as suggested in the
// LaTeX FAQ for URLs
- if (getParam("literal") != from_ascii("true")) {
+ if (getParam("literal") != "true") {
docstring const sim = from_ascii("$\\sim$");
for (size_t i = 0, pos;
(pos = name.find('~', i)) != string::npos;
os << "\\protect";
// output the ready \href command
- os << "\\href{" << getParam("type") << url << "}{" << name << '}';
+ os << "\\href{" << makeURL(url, utype) << "}{" << name << '}';
}
void InsetHyperlink::docbook(XMLStream & xs, OutputParams const &) const
{
- xs << xml::StartTag("link", "xlink:href=\"" + subst(getParam("target"), from_ascii("&"), from_ascii("&")) + "\"");
+ docstring target = subst(getParam("target"), from_ascii("&"), from_ascii("&")) ;
+ xs << xml::StartTag("link", "xlink:href=\"" + makeURL(target, getParam("type")) + "\"");
xs << xml::escapeString(getParam("name"));
xs << xml::EndTag("link");
}
{
docstring const & target =
xml::escapeString(getParam("target"), XMLStream::ESCAPE_AND);
- docstring const & name = getParam("name");
- xs << xml::StartTag("a", to_utf8("href=\"" + target + "\""));
+ docstring const & name = getParam("name");
+ xs << xml::StartTag("a", to_utf8("href=\"" + makeURL(target, getParam("type")) + "\""));
xs << (name.empty() ? target : name);
xs << xml::EndTag("a");
return docstring();
docstring InsetHyperlink::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
{
- docstring url = getParam("target");
- docstring type = getParam("type");
+ docstring const & url = getParam("target");
+ docstring const & type = getParam("type");
docstring guitype = _("www");
if (type == "mailto:")
guitype = _("email");
else if (type == "file:")
guitype = _("file");
+ else if (type == "other")
+ guitype = _("other");
return bformat(_("Hyperlink (%1$s) to %2$s"), guitype, url);
}
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 613 // spitz: \defaultfamily for non-TeX fonts
-#define LYX_FORMAT_TEX2LYX 613
+#define LYX_FORMAT_LYX 614 // rkh: Add 'other' option to hyperlink
+#define LYX_FORMAT_TEX2LYX 614
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER