]> git.lyx.org Git - features.git/commitdiff
Introduce a "formatted counter" for use with formatted reference during
authorRichard Heck <rgheck@comcast.net>
Wed, 20 Jan 2010 20:33:36 +0000 (20:33 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 20 Jan 2010 20:33:36 +0000 (20:33 +0000)
XHTML output.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33113 a592a061-630c-0410-9148-cb99ea01b6c8

lib/scripts/layout2layout.py
po/lyx_pot.py
src/Counters.cpp
src/Counters.h
src/TextClass.cpp
src/insets/InsetLabel.cpp
src/insets/InsetLabel.h
src/insets/InsetRef.cpp

index a6abc7eebfeded3aa9badeddfaa07d212efd92ac..2ab34031c03cce988f92d68dcb801dd7962ca4bd 100644 (file)
@@ -77,6 +77,9 @@ import os, re, string, sys
 
 # Incremented to format 21, 12 January 2010 by rgh
 # Added HTMLTocLayout and HTMLTitle tags.
+       
+# Incremented to format 22, 20 January 2010 by rgh
+# Added HTMLFormat tag to Counters.
 
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
@@ -85,7 +88,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 21
+currentFormat = 22
 
 
 def usage(prog_name):
@@ -254,7 +257,7 @@ def convert(lines):
             continue
 
         # This just involved new features, not any changes to old ones
-        if format >= 14 and format <= 20:
+        if format >= 14 and format <= 21:
           i += 1
           continue
 
index 275d4f70b2a7513e336c4cfd9489a9913ece7bd4..a9fa753018d4807f97106ad78af23b48ff4f4f26 100755 (executable)
@@ -77,7 +77,7 @@ def ui_l10n(input_files, output, base):
 def layouts_l10n(input_files, output, base):
     '''Generate pot file from lib/layouts/*.{layout,inc,module}'''
     out = open(output, 'w')
-    Style = re.compile(r'^Style\s+(.*)')
+    Style = re.compile(r'^Style\s+(.*)', re.IGNORECASE)
     # include ???LabelString???, but exclude comment lines
     LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*)')
     GuiName = re.compile(r'\s*GuiName\s+(.*)')
@@ -91,6 +91,7 @@ def layouts_l10n(input_files, output, base):
     I18nPreamble = re.compile(r'\s*(Lang)|(Babel)Preamble\s*$')
     EndI18nPreamble = re.compile(r'\s*End(Lang)|(Babel)Preamble\s*$')
     I18nString = re.compile(r'_\(([^\)]+)\)')
+    CounterFormat = re.compile(r'\s*PrettyFormat\s+(.*)')
 
     for src in input_files:
         readingDescription = False
@@ -173,6 +174,11 @@ def layouts_l10n(input_files, output, base):
                 string = res.group(1)
                 writeString(out, src, base, lineno, string)
                 continue
+            res = CounterFormat.search(line)
+            if res != None:
+                string = res.group(1)
+                writeString(out, src, base, lineno, string)
+                continue
     out.close()
 
 
index 626596a83301d6121dd742f625ced09751f66f4e..c06e9a7f9f4497742f83fc2f01a7b1bb0bb87872 100644 (file)
@@ -52,6 +52,7 @@ bool Counter::read(Lexer & lex)
                CT_WITHIN = 1,
                CT_LABELSTRING,
                CT_LABELSTRING_APPENDIX,
+               CT_PRETTYFORMAT,
                CT_END
        };
 
@@ -59,6 +60,7 @@ bool Counter::read(Lexer & lex)
                { "end", CT_END },
                { "labelstring", CT_LABELSTRING },
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
+               { "prettyformat", CT_PRETTYFORMAT },
                { "within", CT_WITHIN }
        };
 
@@ -81,6 +83,10 @@ bool Counter::read(Lexer & lex)
                                if (master_ == "none")
                                        master_.erase();
                                break;
+                       case CT_PRETTYFORMAT:
+                               lex.next();
+                               prettyformat_ = lex.getDocString();
+                               break;
                        case CT_LABELSTRING:
                                lex.next();
                                labelstring_ = lex.getDocString();
@@ -539,6 +545,22 @@ docstring Counters::counterLabel(docstring const & format,
 }
 
 
+docstring Counters::prettyCounter(docstring const & counter,
+                              string const & lang) const
+{
+       CounterList::const_iterator it = counterList_.find(counter); 
+       if (it == counterList_.end())
+               return from_ascii("??");
+       Counter const & ctr = it->second;
+       docstring const & format = ctr.prettyFormat();
+       if (format.empty()) {
+               docstring cntrname = translateIfPossible(counter, lang);
+               return  cntrname + " " + theCounter(counter, lang);
+       }
+       return counterLabel(format, lang);
+}
+
+
 docstring Counters::currentCounter() const
 { 
        LASSERT(!counter_stack_.empty(), /* */);
index 3384e564c694a4b688e5cc56295d39dd6fef454d..d992bbb3c646f64b003eca3928d7d2372642d388 100644 (file)
@@ -57,6 +57,10 @@ public:
         *  want the version shown in an appendix.
         */
        docstring const & labelString(bool in_appendix) const;
+       /// Similar, but used for formatted references in XHTML output.
+       /// E.g., for a section counter it might be "section \thesection"
+       docstring const & prettyFormat() const { return prettyformat_; }
+       
        /// Returns a map of LaTeX-like strings to format the counter. 
        /** For each language, the string is similar to what one gets
         *  in LaTeX when using "\the<counter>". The \c in_appendix
@@ -79,6 +83,8 @@ private:
        docstring labelstring_;
        /// The same as labelstring_, but in appendices.
        docstring labelstringappendix_;
+       /// Similar, but used for formatted references in XHTML output
+       docstring prettyformat_;
        /// Cache of the labelstring with \\the<counter> expressions expanded, 
        /// indexed by language
        mutable StringMap flatlabelstring_;
@@ -138,6 +144,10 @@ public:
         */
        docstring counterLabel(docstring const & format,
                               std::string const & lang) const;
+       /// returns a formatted version of the counter, using the 
+       /// format given by Counter::prettyFormat().
+       docstring prettyCounter(docstring const & cntr,
+                              std::string const & lang) const;
        /// Are we in appendix?
        bool appendix() const { return appendix_; }
        /// Set the state variable indicating whether we are in appendix.
index 7f7b694595a11112987cb617abf1eea841517928..981dcd185c23b99d256cfca5f4add1c9fb26b8e9 100644 (file)
@@ -66,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 21;
+int const FORMAT = 22;
 
 
 bool layout2layout(FileName const & filename, FileName const & tempfile)
index edcf5ec742a78f88a8969f9d1b080d3b1c8a1ff1..fd196cfd77da8d4dfe2c03a1fdd0b15917be7fff 100644 (file)
@@ -125,10 +125,13 @@ void InsetLabel::updateLabels(ParIterator const & par, UpdateType utype)
                        buffer().masterBuffer()->params().documentClass().counters();
                active_counter_ = cnts.currentCounter();
                Language const * lang = par->getParLanguage(buffer().params());
-               if (lang && !active_counter_.empty())
+               if (lang && !active_counter_.empty()) {
                        counter_value_ = cnts.theCounter(active_counter_, lang->code());
-               else 
-                       counter_value_ = _("(unknown)");
+                       pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
+               } else {
+                       counter_value_ = from_ascii("??");
+                       pretty_counter_ = from_ascii("??");
+               }
        }
 }
 
index 1ad8da9b1675632d08c86bd44d6cda3c1b146ec3..ab78761b96fb6231c5df138268dd6bbd7b49bfa7 100644 (file)
@@ -66,6 +66,8 @@ public:
        docstring const & activeCounter() const { return active_counter_; }
        ///
        docstring const & counterValue() const { return counter_value_; }
+       ///
+       docstring const & prettyCounter() const { return pretty_counter_; }
 protected:
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);
@@ -78,6 +80,8 @@ private:
        docstring active_counter_;
        ///
        docstring counter_value_;
+       ///
+       docstring pretty_counter_;
 };
 
 
index f292caf32eee2d50b4a9b270cc4d1101e7ddb711..30217df713d02a4e39a8d2f908df0bac654766ab 100644 (file)
@@ -126,20 +126,19 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
 
        if (il && !il->counterValue().empty()) {
                // Try to construct a label from the InsetLabel we reference.
-               docstring const & cntr = il->activeCounter();
                docstring const & value = il->counterValue();
                if (cmd == "ref")
                        display_string = value;
                else if (cmd == "vref")
-                       display_string = bformat(from_ascii("%1$s on page ##"), value);
+                       // normally, would be "ref on page #", but we have no pages
+                       display_string = value;
                else if (cmd == "pageref" || cmd == "vpageref")
-                       display_string = _("on page ##");
+                       // normally would be "on page #", but we have no pages
+                       display_string = _("elsewhere");
                else if (cmd == "eqref")
                        display_string = bformat(from_ascii("equation (%1$s)"), value);
                else { // "prettyref"
-                       docstring cntrname = translateIfPossible(cntr);
-                       // FIXME Use the label string, if we have it. Otherwise, do this.
-                       display_string = bformat(from_ascii("%1$s %2$s"), cntrname, value);
+                       display_string = il->prettyCounter();
                }
        } else 
                        display_string = ref;