commit c8e9f640229ba6260ca6d2e8566b7b366777a7e5
Author: Juergen Spitzmueller <[email protected]>
Date: Fri Jul 25 16:26:46 2025 +0200
Display namerefs properly (GUI and XHTML output) (#8599)
---
src/insets/InsetLabel.cpp | 25 +++++++++++++++++++++++++
src/insets/InsetLabel.h | 4 ++++
src/insets/InsetRef.cpp | 14 ++++++--------
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index cf89a72004..8ab9b58c62 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -242,6 +242,31 @@ void InsetLabel::updateBuffer(ParIterator const & it,
UpdateType, bool const /*d
pretty_counter_ = from_ascii("#");
formatted_counter_ = from_ascii("#");
}
+ if (!active_counter_.empty()) {
+ if (active_counter_ == (*it).layout().counter) {
+ textref_ = (*it).asString(AS_STR_INSETS);
+ return;
+ }
+ ParIterator prev_it = it;
+ while (true) {
+ if (prev_it.pit())
+ --prev_it.top().pit();
+ else {
+ // start of nested inset: go to outer par
+ prev_it.pop_back();
+ if (prev_it.empty()) {
+ // start of document: nothing to do
+ break;
+ }
+ }
+ // We search for the first paragraph which has the
counter.
+ Paragraph & prev_par = *prev_it;
+ if (active_counter_ == prev_par.layout().counter) {
+ textref_ = prev_par.asString(AS_STR_INSETS);
+ break;
+ }
+ }
+ }
}
diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h
index 9a687ffc18..154f332ab5 100644
--- a/src/insets/InsetLabel.h
+++ b/src/insets/InsetLabel.h
@@ -28,6 +28,8 @@ public:
///
docstring const & counterValue() const { return counter_value_; }
///
+ docstring const & textRef() const { return textref_; }
+ ///
docstring const & prettyCounter(bool lc = false) const { return lc ?
pretty_counter_lc_ : pretty_counter_; }
///
docstring formattedCounter(bool lc = false, bool pl = false) const;
@@ -127,6 +129,8 @@ private:
docstring formatted_counter_pl_;
///
docstring formatted_counter_lc_pl_;
+ ///
+ docstring textref_;
};
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 9cc28d1e14..17c549f04f 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -713,14 +713,12 @@ docstring InsetRef::displayString(docstring const & ref,
string const & cmd,
else
display_string.push_back(value);
}
- 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.push_back(il->prettyCounter());
+ else if (cmd == "nameref") {
+ if (il->textRef().empty())
+
display_string.push_back(il->prettyCounter());
+ else
+ display_string.push_back(il->textRef());
+ }
} else
display_string.push_back(ref);
first = false;
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs