commit 76f49fad78db5ed768db163feef4e3b3c062228f Author: Juergen Spitzmueller <sp...@lyx.org> Date: Mon Oct 23 08:20:58 2017 +0200
Implement ParamInfo::HANDLING_LTRIM and use it to ltrim InsetBibitem output See #9847. --- src/insets/InsetBibitem.cpp | 3 ++- src/insets/InsetCommandParams.cpp | 27 ++++++++++++++++----------- src/insets/InsetCommandParams.h | 7 ++++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index d5ebaf7..08e8c76 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -112,7 +112,8 @@ ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */) param_info_.add("label", ParamInfo::LATEX_OPTIONAL, ParamInfo::HANDLING_LATEXIFY); param_info_.add("key", ParamInfo::LATEX_REQUIRED, - ParamInfo::HANDLING_ESCAPE); + ParamInfo::ParamHandling(ParamInfo::HANDLING_ESCAPE + | ParamInfo::HANDLING_LTRIM)); param_info_.add("literal", ParamInfo::LYX_INTERNAL); } return param_info_; diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp index 9d34808..aa2458c 100644 --- a/src/insets/InsetCommandParams.cpp +++ b/src/insets/InsetCommandParams.cpp @@ -432,12 +432,21 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, docstring const & command, ParamInfo::ParamHandling handling) const { - if (handling == ParamInfo::HANDLING_LATEXIFY) + docstring result; + bool ltrimmed = false; + // Trimming can be done on top of any of the other handlings + // We check this here since handling might be changed below. + if (handling & ParamInfo::HANDLING_LTRIM) { + // this is used if no other handling is done + result = command; + ltrimmed = true; + } + if (handling & ParamInfo::HANDLING_LATEXIFY) if ((*this)["literal"] == "true") handling = ParamInfo::HANDLING_NONE; - docstring result; - switch (handling) { - case ParamInfo::HANDLING_LATEXIFY: { + + // LATEXIFY, ESCAPE and NONE are mutually exclusive + if (handling & ParamInfo::HANDLING_LATEXIFY) { // First handle backslash result = subst(command, from_ascii("\\"), from_ascii("\\textbackslash{}")); // Then get LaTeX macros @@ -476,17 +485,13 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, result.replace(pos, 1, backslash + chars_escape[k] + term); } } - break; } - case ParamInfo::HANDLING_ESCAPE: + else if (handling & ParamInfo::HANDLING_ESCAPE) result = escape(command); - break; - case ParamInfo::HANDLING_NONE: + else if (handling & ParamInfo::HANDLING_NONE) result = command; - break; - } // switch - return result; + return ltrimmed ? ltrim(result) : result; } diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h index 121fdac..e823205 100644 --- a/src/insets/InsetCommandParams.h +++ b/src/insets/InsetCommandParams.h @@ -42,9 +42,10 @@ public: }; /// Special handling on output enum ParamHandling { - HANDLING_NONE, /// no special handling - HANDLING_ESCAPE, /// escape special characters - HANDLING_LATEXIFY /// transform special characters to LaTeX macros + HANDLING_NONE = 1, /// no special handling + HANDLING_ESCAPE = 2, /// escape special characters + HANDLING_LATEXIFY = 4, /// transform special characters to LaTeX macros + HANDLING_LTRIM = 8 /// trim blanks on the left }; /// class ParamData {