encoding_switched = true;
}
+ bool const captionfirst = !isfloat && par->isInset(0)
+ && par->getInset(0)->lyxCode() == CAPTION_CODE;
+
while (par != end) {
pos_type siz = par->size();
bool captionline = false;
os << "\\mintinline";
if (!param_string.empty())
os << "[" << from_utf8(param_string) << "]";
- os << "{" << minted_language << "}";
+ os << "{" << ascii_lowercase(minted_language) << "}";
} else {
os << "\\lstinline";
if (!param_string.empty())
}
os << delim << code << delim;
} else if (use_minted) {
+ OutputParams rp = runparams;
+ rp.moving_arg = true;
+ TexString caption = getCaption(rp);
if (isfloat) {
os << breakln << "\\begin{listing}";
if (!float_placement.empty())
os << '[' << float_placement << "]";
+ } else if (captionfirst && !caption.str.empty()) {
+ os << breakln << "\\lyxmintcaption[t]{"
+ << move(caption) << "}\n";
}
os << breakln << "\\begin{minted}";
if (!param_string.empty())
os << "[" << param_string << "]";
- os << "{" << minted_language << "}\n"
+ os << "{" << ascii_lowercase(minted_language) << "}\n"
<< code << breakln << "\\end{minted}\n";
if (isfloat) {
- OutputParams rp = runparams;
- rp.moving_arg = true;
- TexString caption = getCaption(rp);
if (!caption.str.empty())
os << "\\caption{" << move(caption) << "}\n";
os << "\\end{listing}\n";
+ } else if (!captionfirst && !caption.str.empty()) {
+ os << breakln << "\\lyxmintcaption[b]{"
+ << move(caption) << "}";
}
} else {
OutputParams rp = runparams;
return true;
case LFUN_CAPTION_INSERT: {
// the inset outputs at most one caption
- if (params().isInline() || !params().isFloat()
- || getCaptionInset()) {
+ if (params().isInline() || getCaptionInset()) {
status.setEnabled(false);
return true;
}
void InsetListings::validate(LaTeXFeatures & features) const
{
- if (buffer().params().use_minted)
- features.require("minted");
- else
- features.require("listings");
features.useInsetLayout(getLayout());
string param_string = params().params();
- if (param_string.find("\\color") != string::npos)
- features.require("color");
+ if (buffer().params().use_minted) {
+ features.require("minted");
+ OutputParams rp = features.runparams();
+ if (!params().isFloat() && !getCaption(rp).str.empty())
+ features.require("lyxmintcaption");
+ } else {
+ features.require("listings");
+ if (contains(param_string, "\\color"))
+ features.require("color");
+ }
InsetCaptionable::validate(features);
}
// TexString validity: the substitution preserves the number of newlines.
// Moreover we assume that $2 does not contain newlines, so that the texrow
// information remains accurate.
- cap.str = from_utf8(regex_replace(to_utf8(cap.str), reg, new_cap));
+ // Replace '\n' with an improbable character from Private Use Area-A
+ // and then return to '\n' after the regex replacement.
+ docstring const capstr = subst(cap.str, char_type('\n'), 0xffffd);
+ cap.str = subst(from_utf8(regex_replace(to_utf8(capstr), reg, new_cap)),
+ 0xffffd, char_type('\n'));
return cap;
}