Introduce a "formatted counter" for use with formatted reference during

XHTML output.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33113 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-01-20 20:33:36 +00:00
parent f1b8f4d059
commit c2ac70552c
8 changed files with 60 additions and 13 deletions

View 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

View File

@ -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()

View 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(), /* */);

View 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.

View 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)

View 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("??");
}
}
}

View 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_;
};

View 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;