mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
Allow an 'other' type for hyperlinks. Format change.
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.
This commit is contained in:
parent
962f2370b2
commit
144cf4bb9a
@ -7,6 +7,9 @@ changes happened in particular if possible. A good example would be
|
|||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
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>
|
2022-12-11 Jürgen Spitzmüller <spitz@lyx.org>
|
||||||
* Format incremented to 613: Support \\fonts_default_family for non-TeX fonts.
|
* Format incremented to 613: Support \\fonts_default_family for non-TeX fonts.
|
||||||
|
|
||||||
|
@ -4640,6 +4640,37 @@ def revert_familydefault(document):
|
|||||||
document.header[i] = "\\font_default_family default"
|
document.header[i] = "\\font_default_family default"
|
||||||
add_to_preamble(document, ["\\renewcommand{\\familydefault}{\\" + dfamily + "}"])
|
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
|
# Conversion hub
|
||||||
#
|
#
|
||||||
@ -4714,10 +4745,12 @@ convert = [
|
|||||||
[610, []],
|
[610, []],
|
||||||
[611, []],
|
[611, []],
|
||||||
[612, [convert_starred_refs]],
|
[612, [convert_starred_refs]],
|
||||||
[613, []]
|
[613, []],
|
||||||
|
[614, []]
|
||||||
]
|
]
|
||||||
|
|
||||||
revert = [[612, [revert_familydefault]],
|
revert = [[613, [revert_hyper_other]],
|
||||||
|
[612, [revert_familydefault]],
|
||||||
[611, [revert_starred_refs]],
|
[611, [revert_starred_refs]],
|
||||||
[610, []],
|
[610, []],
|
||||||
[609, [revert_index_macros]],
|
[609, [revert_index_macros]],
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "insets/InsetHyperlink.h"
|
#include "insets/InsetHyperlink.h"
|
||||||
|
|
||||||
|
#include "support/debug.h"
|
||||||
|
|
||||||
#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
|
#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
|
||||||
// GCC couldn't find operator==
|
// GCC couldn't find operator==
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -48,6 +50,8 @@ GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
|
|||||||
this, SIGNAL(changed()));
|
this, SIGNAL(changed()));
|
||||||
connect(fileRB, SIGNAL(clicked()),
|
connect(fileRB, SIGNAL(clicked()),
|
||||||
this, SIGNAL(changed()));
|
this, SIGNAL(changed()));
|
||||||
|
connect(noneRB, SIGNAL(clicked()),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
|
||||||
setFocusProxy(targetED);
|
setFocusProxy(targetED);
|
||||||
}
|
}
|
||||||
@ -68,6 +72,10 @@ void GuiHyperlink::paramsToDialog(Inset const * inset)
|
|||||||
emailRB->setChecked(true);
|
emailRB->setChecked(true);
|
||||||
else if (type == "file:")
|
else if (type == "file:")
|
||||||
fileRB->setChecked(true);
|
fileRB->setChecked(true);
|
||||||
|
else if (type == "other")
|
||||||
|
noneRB->setChecked(true);
|
||||||
|
else
|
||||||
|
LYXERR0("Unknown hyperlink type: " << type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,10 +87,12 @@ bool GuiHyperlink::initialiseParams(std::string const & sdata)
|
|||||||
targetED->setText(toqstr(params["target"]));
|
targetED->setText(toqstr(params["target"]));
|
||||||
nameED->setText(toqstr(params["name"]));
|
nameED->setText(toqstr(params["name"]));
|
||||||
literalCB->setChecked(params["literal"] == "true");
|
literalCB->setChecked(params["literal"] == "true");
|
||||||
if (params["type"] == from_utf8("mailto:"))
|
if (params["type"] == "mailto:")
|
||||||
emailRB->setChecked(true);
|
emailRB->setChecked(true);
|
||||||
else if (params["type"] == from_utf8("file:"))
|
else if (params["type"] == "file:")
|
||||||
fileRB->setChecked(true);
|
fileRB->setChecked(true);
|
||||||
|
else if (params["type"] == "other")
|
||||||
|
noneRB->setChecked(true);
|
||||||
else
|
else
|
||||||
webRB->setChecked(true);
|
webRB->setChecked(true);
|
||||||
return true;
|
return true;
|
||||||
@ -101,6 +111,8 @@ docstring GuiHyperlink::dialogToParams() const
|
|||||||
params["type"] = from_utf8("mailto:");
|
params["type"] = from_utf8("mailto:");
|
||||||
else if (fileRB->isChecked())
|
else if (fileRB->isChecked())
|
||||||
params["type"] = from_utf8("file:");
|
params["type"] = from_utf8("file:");
|
||||||
|
else if (noneRB->isChecked())
|
||||||
|
params["type"] = from_utf8("other");
|
||||||
params["literal"] = literalCB->isChecked()
|
params["literal"] = literalCB->isChecked()
|
||||||
? from_ascii("true") : from_ascii("false");
|
? from_ascii("true") : from_ascii("false");
|
||||||
params.setCmdName("href");
|
params.setCmdName("href");
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>290</width>
|
<width>306</width>
|
||||||
<height>188</height>
|
<height>226</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -160,6 +160,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="noneRB">
|
||||||
|
<property name="text">
|
||||||
|
<string>Other</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -170,7 +177,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>112</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -109,10 +109,10 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
{
|
{
|
||||||
switch (cmd.action()) {
|
switch (cmd.action()) {
|
||||||
case LFUN_INSET_EDIT: {
|
case LFUN_INSET_EDIT: {
|
||||||
|
docstring const & utype = getParam("type");
|
||||||
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
||||||
bool url_valid = getParam("type").empty() && url.isValid();
|
bool url_valid = utype.empty() && url.isValid();
|
||||||
|
flag.setEnabled(url_valid || utype == "file:");
|
||||||
flag.setEnabled(url_valid || getParam("type") == "file:");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,6 @@ void InsetHyperlink::viewTarget() const
|
|||||||
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
||||||
if (!QDesktopServices::openUrl(url))
|
if (!QDesktopServices::openUrl(url))
|
||||||
LYXERR0("Unable to open URL!");
|
LYXERR0("Unable to open URL!");
|
||||||
|
|
||||||
} else if (getParam("type") == "file:") {
|
} else if (getParam("type") == "file:") {
|
||||||
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
|
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
|
||||||
string const format = theFormats().getFormatFromFile(url);
|
string const format = theFormats().getFormatFromFile(url);
|
||||||
@ -137,11 +136,20 @@ void InsetHyperlink::viewTarget() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
void InsetHyperlink::latex(otexstream & os,
|
||||||
OutputParams const & runparams) const
|
OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
docstring url = getParam("target");
|
docstring url = getParam("target");
|
||||||
docstring name = getParam("name");
|
docstring name = getParam("name");
|
||||||
|
docstring const & utype = getParam("type");
|
||||||
static char_type const chars_url[2] = {'%', '#'};
|
static char_type const chars_url[2] = {'%', '#'};
|
||||||
|
|
||||||
// For the case there is no name given, the target is set as name.
|
// For the case there is no name given, the target is set as name.
|
||||||
@ -177,10 +185,9 @@ void InsetHyperlink::latex(otexstream & os,
|
|||||||
|
|
||||||
// add "http://" when the type is web (type = empty)
|
// add "http://" when the type is web (type = empty)
|
||||||
// and no "://" or "run:" is given
|
// and no "://" or "run:" is given
|
||||||
docstring type = getParam("type");
|
|
||||||
if (url.find(from_ascii("://")) == string::npos
|
if (url.find(from_ascii("://")) == string::npos
|
||||||
&& url.find(from_ascii("run:")) == string::npos
|
&& url.find(from_ascii("run:")) == string::npos
|
||||||
&& type.empty())
|
&& utype.empty())
|
||||||
url = from_ascii("http://") + url;
|
url = from_ascii("http://") + url;
|
||||||
|
|
||||||
} // end if (!url.empty())
|
} // end if (!url.empty())
|
||||||
@ -190,7 +197,7 @@ void InsetHyperlink::latex(otexstream & os,
|
|||||||
ParamInfo::HANDLING_LATEXIFY);
|
ParamInfo::HANDLING_LATEXIFY);
|
||||||
// replace the tilde by the \sim character as suggested in the
|
// replace the tilde by the \sim character as suggested in the
|
||||||
// LaTeX FAQ for URLs
|
// LaTeX FAQ for URLs
|
||||||
if (getParam("literal") != from_ascii("true")) {
|
if (getParam("literal") != "true") {
|
||||||
docstring const sim = from_ascii("$\\sim$");
|
docstring const sim = from_ascii("$\\sim$");
|
||||||
for (size_t i = 0, pos;
|
for (size_t i = 0, pos;
|
||||||
(pos = name.find('~', i)) != string::npos;
|
(pos = name.find('~', i)) != string::npos;
|
||||||
@ -203,7 +210,7 @@ void InsetHyperlink::latex(otexstream & os,
|
|||||||
os << "\\protect";
|
os << "\\protect";
|
||||||
|
|
||||||
// output the ready \href command
|
// output the ready \href command
|
||||||
os << "\\href{" << getParam("type") << url << "}{" << name << '}';
|
os << "\\href{" << makeURL(url, utype) << "}{" << name << '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -226,7 +233,8 @@ int InsetHyperlink::plaintext(odocstringstream & os,
|
|||||||
|
|
||||||
void InsetHyperlink::docbook(XMLStream & xs, OutputParams const &) const
|
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::escapeString(getParam("name"));
|
||||||
xs << xml::EndTag("link");
|
xs << xml::EndTag("link");
|
||||||
}
|
}
|
||||||
@ -237,7 +245,7 @@ docstring InsetHyperlink::xhtml(XMLStream & xs, OutputParams const &) const
|
|||||||
docstring const & target =
|
docstring const & target =
|
||||||
xml::escapeString(getParam("target"), XMLStream::ESCAPE_AND);
|
xml::escapeString(getParam("target"), XMLStream::ESCAPE_AND);
|
||||||
docstring const & name = getParam("name");
|
docstring const & name = getParam("name");
|
||||||
xs << xml::StartTag("a", to_utf8("href=\"" + target + "\""));
|
xs << xml::StartTag("a", to_utf8("href=\"" + makeURL(target, getParam("type")) + "\""));
|
||||||
xs << (name.empty() ? target : name);
|
xs << (name.empty() ? target : name);
|
||||||
xs << xml::EndTag("a");
|
xs << xml::EndTag("a");
|
||||||
return docstring();
|
return docstring();
|
||||||
@ -265,13 +273,15 @@ void InsetHyperlink::forOutliner(docstring & os, size_t const, bool const) const
|
|||||||
|
|
||||||
docstring InsetHyperlink::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
|
docstring InsetHyperlink::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
|
||||||
{
|
{
|
||||||
docstring url = getParam("target");
|
docstring const & url = getParam("target");
|
||||||
docstring type = getParam("type");
|
docstring const & type = getParam("type");
|
||||||
docstring guitype = _("www");
|
docstring guitype = _("www");
|
||||||
if (type == "mailto:")
|
if (type == "mailto:")
|
||||||
guitype = _("email");
|
guitype = _("email");
|
||||||
else if (type == "file:")
|
else if (type == "file:")
|
||||||
guitype = _("file");
|
guitype = _("file");
|
||||||
|
else if (type == "other")
|
||||||
|
guitype = _("other");
|
||||||
return bformat(_("Hyperlink (%1$s) to %2$s"), guitype, url);
|
return bformat(_("Hyperlink (%1$s) to %2$s"), guitype, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
|||||||
|
|
||||||
// Do not remove the comment below, so we get merge conflict in
|
// Do not remove the comment below, so we get merge conflict in
|
||||||
// independent branches. Instead add your own.
|
// independent branches. Instead add your own.
|
||||||
#define LYX_FORMAT_LYX 613 // spitz: \defaultfamily for non-TeX fonts
|
#define LYX_FORMAT_LYX 614 // rkh: Add 'other' option to hyperlink
|
||||||
#define LYX_FORMAT_TEX2LYX 613
|
#define LYX_FORMAT_TEX2LYX 614
|
||||||
|
|
||||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
|
Loading…
Reference in New Issue
Block a user