]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetHyperlink.cpp
Improve handling of top and bottom margin
[lyx.git] / src / insets / InsetHyperlink.cpp
index a500f7bd5913b35d7ea54c226e56826af4eeab9e..0f039e34d81deb9372452bcbd939ad622b80cc7a 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include <config.h>
-
 #include "InsetHyperlink.h"
 
 #include "Buffer.h"
@@ -21,8 +20,9 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "OutputParams.h"
+#include "output_docbook.h"
 #include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
 #include "texstream.h"
 
 #include "support/docstream.h"
@@ -60,19 +60,28 @@ ParamInfo const & InsetHyperlink::findInfo(string const & /* cmdName */)
 
 docstring InsetHyperlink::screenLabel() const
 {
+       // TODO: replace with unicode hyperlink character = U+1F517
        docstring const temp = _("Hyperlink: ");
 
        docstring url;
 
        url += getParam("name");
-       if (url.empty())
+       if (url.empty()) {
                url += getParam("target");
 
-       // elide if long
-       if (url.length() > 30) {
-               docstring end = url.substr(url.length() - 17, url.length());
-               support::truncateWithEllipsis(url, 13);
-               url += end;
+               // elide if long and no name was provided
+               if (url.length() > 30) {
+                       docstring end = url.substr(url.length() - 17, url.length());
+                       support::truncateWithEllipsis(url, 13);
+                       url += end;
+               }
+       } else {
+               // elide if long (approx number of chars in line of article class)
+               if (url.length() > 80) {
+                       docstring end = url.substr(url.length() - 67, url.length());
+                       support::truncateWithEllipsis(url, 13);
+                       url += end;
+               }
        }
        return temp + url;
 }
@@ -204,25 +213,22 @@ int InsetHyperlink::plaintext(odocstringstream & os,
 }
 
 
-int InsetHyperlink::docbook(odocstream & os, OutputParams const &) const
+void InsetHyperlink::docbook(XMLStream & xs, OutputParams const &) const
 {
-       os << "<ulink url=\""
-          << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
-          << "\">"
-          << sgml::escapeString(getParam("name"))
-          << "</ulink>";
-       return 0;
+       xs << xml::StartTag("link", "xlink:href=\"" + subst(getParam("target"), from_ascii("&"), from_ascii("&amp;")) + "\"");
+       xs << xml::escapeString(getParam("name"));
+       xs << xml::EndTag("link");
 }
 
 
-docstring InsetHyperlink::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetHyperlink::xhtml(XMLStream & xs, OutputParams const &) const
 {
        docstring const & target =
-               html::htmlize(getParam("target"), XHTMLStream::ESCAPE_AND);
+               xml::xmlize(getParam("target"), XMLStream::ESCAPE_AND);
        docstring const & name   = getParam("name");
-       xs << html::StartTag("a", to_utf8("href=\"" + target + "\""));
+       xs << xml::StartTag("a", to_utf8("href=\"" + target + "\""));
        xs << (name.empty() ? target : name);
-       xs << html::EndTag("a");
+       xs << xml::EndTag("a");
        return docstring();
 }