]> git.lyx.org Git - lyx.git/blob - src/insets/inseturl.C
Output docbook as utf8. Probably quite a bit more work needed, but then help form...
[lyx.git] / src / insets / inseturl.C
1 /**
2  * \file inseturl.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author José Matos
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "inseturl.h"
14
15 #include "dispatchresult.h"
16 #include "funcrequest.h"
17 #include "LaTeXFeatures.h"
18 #include "gettext.h"
19 #include "outputparams.h"
20
21 #include "support/lstrings.h"
22
23 #include "support/std_ostream.h"
24
25 using lyx::docstring;
26 using lyx::odocstream;
27 using lyx::support::subst;
28
29 using std::string;
30 using std::ostream;
31
32
33 InsetUrl::InsetUrl(InsetCommandParams const & p)
34         : InsetCommand(p, "url")
35 {}
36
37
38 docstring const InsetUrl::getScreenLabel(Buffer const &) const
39 {
40         docstring const temp =
41                 (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: ");
42
43         string url;
44
45         if (!getOptions().empty())
46                 url += getOptions();
47         else
48                 url += getContents();
49
50         // elide if long
51         if (url.length() > 30) {
52                 url = url.substr(0, 10) + "..."
53                         + url.substr(url.length() - 17, url.length());
54         }
55         // FIXME UNICODE
56         return temp + lyx::from_utf8(url);
57 }
58
59
60 int InsetUrl::latex(Buffer const &, odocstream & os,
61                     OutputParams const & runparams) const
62 {
63         docstring const & name = getParam("name");
64         if (!name.empty())
65                 os << name + ' ';
66         if (runparams.moving_arg)
67                 os << "\\protect";
68         os << "\\url{" << getParam("target") << '}';
69         return 0;
70 }
71
72
73 int InsetUrl::plaintext(Buffer const &, odocstream & os,
74                     OutputParams const &) const
75 {
76         // FIXME UNICODE
77         os << '[' << lyx::from_utf8(getContents());
78         if (getOptions().empty())
79                 os << ']';
80         else
81                 // FIXME UNICODE
82                 os << "||" << lyx::from_utf8(getOptions()) << ']';
83         return 0;
84 }
85
86
87 int InsetUrl::docbook(Buffer const &, odocstream & os,
88                       OutputParams const &) const
89 {
90         // FIXME UNICODE
91         os << "<ulink url=\""
92            << lyx::from_ascii(subst(getContents(), "&", "&amp;"))
93            << "\">"
94            << lyx::from_ascii(getOptions())
95            << "</ulink>";
96         return 0;
97 }
98
99
100 int InsetUrl::textString(Buffer const & buf, odocstream & os,
101                        OutputParams const & op) const
102 {
103         return plaintext(buf, os, op);
104 }
105
106
107 void InsetUrl::validate(LaTeXFeatures & features) const
108 {
109         features.require("url");
110 }