From e8c034479179472012dd6a5e56f91804646d65c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Wed, 26 Oct 2011 05:02:37 +0000 Subject: [PATCH] tex2lyx: support for hyperlinks git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40005 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/TODO.txt | 1 - src/tex2lyx/test/test-insets.tex | 17 ++++++++++++++--- src/tex2lyx/text.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 39d78665d0..5ee9a922ac 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -31,7 +31,6 @@ Format LaTeX feature LyX feature 290 wrapped tables InsetWrap 292 japanese japanese-plain 293 ? InsetInfo -299 hyperlink types InsetHyperlink 309 \nocite InsetCitation 310 \nocite{*} InsetBibtex 316 subfig.sty (subfloats) InsetFloat diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 040bd8c629..0aa90c45e9 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -121,10 +121,21 @@ If you prefer verbatim input, you can choose between~\verbatiminput{foo} or~\verbatiminput*{foo}. -\section{URL\index{URL}\nomenclature[www]{URL}{uniform resource locator}} +\section{URLs and Hyperlinks\index{URL}\nomenclature[www]{URL}{uniform resource locator}} -An URL: \url{http://www.lyx.org} -\nomenclature{URL2}{uniform resource locator} +An URL: \url{http://www.lyx.org} \nomenclature{URL2}{uniform resource locator} + +link:\href{http://www.test.test}{www.test.test} + +link2:\href{http://www.test.test}{http://www.test.test} + +mail:\href{mailto:www.test.test}{name} + +file:\href{file:www.test.test}{www.test.test} + +ftp:\href{ftp://www.test.test}{ftp://www.test.test} + +ftp2:\href{ftp://www.test.test}{www.test.test} \section{Lists\index{Lists}} diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 8a9951d3c7..db91970fb5 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2478,6 +2478,30 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, parse_text_in_inset(p, os, FLAG_ITEM, outer, context); end_inset(os); } + + else if (t.cs() == "href") { + context.check_layout(os); + string target = p.getArg('{', '}'); + string name = p.getArg('{', '}'); + string type; + size_t i = target.find(':'); + if (i != string::npos) { + type = target.substr(0, i + 1); + if (type == "mailto:" || type == "file:") + target = target.substr(i + 1); + // handle the case that name is equal to target, except of "http://" + else if (target.substr(i + 3) == name && type == "http:") + target = name; + } + begin_command_inset(os, "href", "href"); + if (name != target) + os << "name \"" << name << "\"\n"; + os << "target \"" << target << "\"\n"; + if (type == "mailto:" || type == "file:") + os << "type \"" << type << "\"\n"; + end_inset(os); + skip_spaces_braces(p); + } else if (t.cs() == "lyxline") { // swallow size argument (it is not used anyway)