void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
- Context const & context, InsetLayout const * layout)
+ Context const & context, InsetLayout const * layout,
+ string const rdelim)
{
bool const forcePlainLayout =
layout ? layout->forcePlainLayout() : false;
if (layout)
output_arguments(os, p, outer, false, false, newcontext,
layout->latexargs());
- parse_text(p, os, flags, outer, newcontext);
+ parse_text(p, os, flags, outer, newcontext, rdelim);
if (layout)
output_arguments(os, p, outer, false, true, newcontext,
layout->postcommandargs());
namespace {
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
- Context const & context, string const & name)
+ Context const & context, string const & name,
+ string const rdelim = string())
{
InsetLayout const * layout = 0;
DocumentClass::InsetLayouts::const_iterator it =
context.textclass.insetLayouts().find(from_ascii(name));
if (it != context.textclass.insetLayouts().end())
layout = &(it->second);
- parse_text_in_inset(p, os, flags, outer, context, layout);
+ parse_text_in_inset(p, os, flags, outer, context, layout, rdelim);
}
/// parses a paragraph snippet, useful for example for \\emph{...}
if (lait->second.mandatory) {
if (p.next_token().cat() != catBegin)
break;
- p.get_token(); // eat '{'
+ string ldelim = to_utf8(lait->second.ldelim);
+ string rdelim = to_utf8(lait->second.rdelim);
+ if (ldelim.empty())
+ ldelim = "{";
+ if (rdelim.empty())
+ rdelim = "}";
+ p.get_token(); // eat ldelim
+ if (ldelim.size() > 1)
+ p.get_token(); // eat ldelim
if (need_layout) {
context.check_layout(os);
need_layout = false;
if (post)
os << "post:";
os << i << "\nstatus collapsed\n\n";
- parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context);
+ parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
end_inset(os);
} else {
- if (p.next_token().cat() == catEscape ||
- p.next_token().character() != '[')
+ string ldelim = to_utf8(lait->second.ldelim);
+ string rdelim = to_utf8(lait->second.rdelim);
+ if (ldelim.empty())
+ ldelim = "[";
+ if (rdelim.empty())
+ rdelim = "]";
+ string tok = p.next_token().asInput();
+ // we only support delimiters with max 2 chars for now.
+ if (ldelim.size() > 1)
+ tok += p.next_next_token().asInput();
+ if (p.next_token().cat() == catEscape || tok != ldelim)
continue;
- p.get_token(); // eat '['
+ p.get_token(); // eat ldelim
+ if (ldelim.size() > 1)
+ p.get_token(); // eat ldelim
if (need_layout) {
context.check_layout(os);
need_layout = false;
if (post)
os << "post:";
os << i << "\nstatus collapsed\n\n";
- parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
+ parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
end_inset(os);
}
eat_whitespace(p, os, context, false);
}
context.check_deeper(os);
// handle known optional and required arguments
- // Unfortunately LyX can't handle arguments of list arguments (bug 7468):
- // It is impossible to place anything after the environment name,
- // but before the first \\item.
- if (context.layout->latextype == LATEX_ENVIRONMENT)
+ // FIXME: for item environments, this is currently
+ // placed wrongly (in an empty paragraph). It has to go to
+ // the first \item par instead.
+ if (context.layout->latextype == LATEX_ENVIRONMENT
+ || context.layout->latextype == LATEX_ITEM_ENVIRONMENT)
output_arguments(os, p, outer, false, false, context,
context.layout->latexargs());
parse_text(p, os, FLAG_END, outer, context);
void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
- Context & context)
+ Context & context, string const rdelim)
{
Layout const * newlayout = 0;
InsetLayout const * newinsetlayout = 0;
return;
if (t.cat() == catEnd && (flags & FLAG_BRACE_LAST))
return;
+ string tok = t.asInput();
+ // we only support delimiters with max 2 chars for now.
+ if (rdelim.size() > 1)
+ tok += p.next_token().asInput();
+ if (t.cat() != catEscape && !rdelim.empty()
+ && tok == rdelim && (flags & FLAG_RDELIM)) {
+ if (rdelim.size() > 1)
+ p.get_token(); // eat rdelim
+ return;
+ }
// If there is anything between \end{env} and \begin{env} we
// don't need to output a separator.