+ docstring const & ref = getParam("reference");
+ InsetLabel const * il = buffer().insetLabel(ref);
+ string const & cmd = params().getCmdName();
+ docstring display_string;
+
+ if (il && !il->counterValue().empty()) {
+ // Try to construct a label from the InsetLabel we reference.
+ docstring const & value = il->counterValue();
+ if (cmd == "ref")
+ display_string = value;
+ else if (cmd == "vref")
+ // normally, would be "ref on page #", but we have no pages
+ display_string = value;
+ else if (cmd == "pageref" || cmd == "vpageref")
+ // normally would be "on page #", but we have no pages.
+ display_string = translateIfPossible(from_ascii("elsewhere"),
+ op.local_font->language()->lang());
+ else if (cmd == "eqref")
+ display_string = '(' + value + ')';
+ else if (cmd == "formatted") {
+ display_string = il->prettyCounter();
+ if (buffer().params().use_refstyle && getParam("caps") == "true")
+ capitalize(display_string);
+ // it is hard to see what to do about plurals...
+ }
+ else if (cmd == "nameref")
+ // FIXME We don't really have the ability to handle these
+ // properly in XHTML output yet (bug #8599).
+ // It might not be that hard to do. We have the InsetLabel,
+ // and we can presumably find its paragraph using the TOC.
+ // But the label might be referencing a section, yet not be
+ // in that section. So this is not trivial.
+ display_string = il->prettyCounter();
+ } else
+ display_string = ref;
+
+ // FIXME What we'd really like to do is to be able to output some
+ // appropriate sort of text here. But to do that, we need to associate
+ // some sort of counter with the label, and we don't have that yet.
+ docstring const attr = "href=\"#" + html::cleanAttr(ref) + '"';
+ xs << html::StartTag("a", to_utf8(attr));
+ xs << display_string;
+ xs << html::EndTag("a");
+ return docstring();
+}
+
+
+void InsetRef::toString(odocstream & os) const
+{
+ odocstringstream ods;
+ plaintext(ods, OutputParams(0));
+ os << ods.str();
+}
+
+
+void InsetRef::forOutliner(docstring & os, size_t const, bool const) const
+{
+ // There's no need for details in the TOC, and a long label
+ // will just get in the way.
+ os += '#';
+}
+
+
+void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
+{
+ docstring const & ref = getParam("reference");
+ // register this inset into the buffer reference cache.
+ buffer().addReference(ref, this, it);
+
+ docstring label;
+ string const & cmd = getCmdName();
+ for (int i = 0; !types[i].latex_name.empty(); ++i) {
+ if (cmd == types[i].latex_name) {
+ label = _(types[i].short_gui_name);
+ break;
+ }
+ }
+
+ if (cmd != "labelonly")
+ label += ref;
+ else {
+ if (getParam("noprefix") != "true")
+ label += ref;
+ else {
+ docstring prefix;
+ docstring suffix = split(ref, prefix, ':');
+ if (suffix.empty()) {
+ label += ref;
+ } else {
+ label += suffix;
+ }
+ }
+ }
+
+ if (!buffer().params().isLatex() && !getParam("name").empty()) {
+ label += "||";
+ label += getParam("name");
+ }
+
+ unsigned int const maxLabelChars = 24;
+ if (label.size() > maxLabelChars) {
+ tooltip_ = label;
+ support::truncateWithEllipsis(label, maxLabelChars);
+ } else
+ tooltip_ = from_ascii("");
+ screen_label_ = label;
+}
+
+
+void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
+ UpdateType) const
+{
+ docstring const & label = getParam("reference");
+ if (buffer().insetLabel(label))
+ // This InsetRef has already been taken care of in InsetLabel::addToToc().
+ return;
+
+ // It seems that this reference does not point to any valid label.
+ screen_label_ = _("BROKEN: ") + screen_label_;
+ shared_ptr<Toc> toc = buffer().tocBackend().toc("label");
+ toc->push_back(TocItem(cpit, 0, screen_label_, output_active));