]> git.lyx.org Git - lyx.git/commitdiff
Implement Paragraph::getLabel()
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 28 Jul 2024 13:52:19 +0000 (15:52 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 28 Jul 2024 13:52:19 +0000 (15:52 +0200)
This function returns the first label (as string) if there is any

src/Paragraph.cpp
src/Paragraph.h

index d21e86ebbf464cca2c4173a375c28219dec212df..1d239ef5a0a1dd2fc28c2944992045b274b6b64d 100644 (file)
@@ -3350,6 +3350,21 @@ string Paragraph::getID(Buffer const &, OutputParams const &)
 }
 
 
+string Paragraph::getLabel() const
+{
+       for (pos_type i = 0; i < size(); ++i) {
+               if (Inset const * inset = getInset(i)) {
+                       InsetCode lyx_code = inset->lyxCode();
+                       if (lyx_code == LABEL_CODE) {
+                               InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
+                               return to_utf8(il->getParam("name"));
+                       }
+               }
+       }
+       return string();
+}
+
+
 pos_type Paragraph::firstWordDocBook(XMLStream & xs, OutputParams const & runparams) const
 {
        pos_type i;
index ef94352f37a356c48177045f74f0e34aa9daaa5a..ee27e170ece87196f77e76899495a19744101e65 100644 (file)
@@ -201,6 +201,9 @@ public:
        /// Get the id of the paragraph, useful for DocBook
        std::string getID(Buffer const & buf, OutputParams const & runparams) const;
 
+       /// Get the (first) string of a \label in this paragraph, or empty string
+       std::string getLabel() const;
+
        /// Output the first word of a paragraph, return the position where it left.
        pos_type firstWordDocBook(XMLStream & xs, OutputParams const & runparams) const;