]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.cpp
Better TOC output for XHTML, per Rob and Pavel.
[lyx.git] / src / insets / InsetCommandParams.cpp
index a0cbd6e785be498fdc71b2ec85d1d54b55fc3245..bb4882874af1b0220dba13776023ab8e34f1250e 100644 (file)
@@ -23,6 +23,7 @@
 #include "InsetInclude.h"
 #include "InsetIndex.h"
 #include "InsetLabel.h"
+#include "InsetLine.h"
 #include "InsetNomencl.h"
 #include "InsetRef.h"
 #include "InsetTOC.h"
@@ -70,6 +71,8 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
                return InsetPrintIndex::findInfo(cmdName);
        case LABEL_CODE:
                return InsetLabel::findInfo(cmdName);
+       case LINE_CODE:
+               return InsetLine::findInfo(cmdName);
        case NOMENCL_CODE:
                return InsetNomencl::findInfo(cmdName);
        case NOMENCL_PRINT_CODE:
@@ -81,7 +84,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
        default:
                LASSERT(false, /**/);
        }
-       static const ParamInfo pi;
+       static ParamInfo pi;
        return pi; // to silence the warning
 }
 
@@ -200,6 +203,8 @@ string InsetCommandParams::getDefaultCmd(InsetCode code)
                        return InsetPrintIndex::defaultCommand();
                case LABEL_CODE:
                        return InsetLabel::defaultCommand();
+               case LINE_CODE:
+                       return InsetLine::defaultCommand();
                case NOMENCL_CODE:
                        return InsetNomencl::defaultCommand();
                case NOMENCL_PRINT_CODE:
@@ -234,6 +239,8 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s)
                        return InsetPrintIndex::isCompatibleCommand(s);
                case LABEL_CODE:
                        return InsetLabel::isCompatibleCommand(s);
+               case LINE_CODE:
+                       return InsetLine::isCompatibleCommand(s);
                case NOMENCL_CODE:
                        return InsetNomencl::isCompatibleCommand(s);
                case NOMENCL_PRINT_CODE:
@@ -358,17 +365,25 @@ bool InsetCommandParams::writeEmptyOptional(ParamInfo::const_iterator ci) const
 }
 
 
-
 docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                                             docstring const & command,
                                             ParamInfo::ParamHandling handling) const
 {
        docstring result;
-       if (handling == ParamInfo::HANDLING_LATEXIFY) {
+       switch (handling) {
+       case ParamInfo::HANDLING_LATEXIFY: {
                docstring uncodable;
                for (size_t n = 0; n < command.size(); ++n) {
                        try {
-                               result += runparams.encoding->latexChar(command[n]);
+                               char_type const c = command[n];
+                               docstring const latex = runparams.encoding->latexChar(c);
+                               result += latex;
+                               if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
+                                       // Prevent eating of a following
+                                       // space or command corruption by
+                                       // following characters
+                                       result +=  "{}";
+                               }
                        } catch (EncodingException & /* e */) {
                                LYXERR0("Uncodable character in command inset!");
                                if (runparams.dryrun) {
@@ -388,10 +403,15 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                                          "representable in the current encoding and therefore have been omitted:\n%2$s."),
                                        from_utf8(insetType()), uncodable));
                }
-       } else if (handling == ParamInfo::HANDLING_ESCAPE)
+               break;
+       } 
+       case ParamInfo::HANDLING_ESCAPE:
                result = escape(command);
-       else
+               break;
+       case ParamInfo::HANDLING_NONE:
                result = command;
+               break;
+       } // switch
 
        return result;
 }
@@ -410,14 +430,14 @@ docstring InsetCommandParams::getCommand(OutputParams const & runparams) const
                        break;
 
                case ParamInfo::LATEX_REQUIRED: {
-                       docstring const data =
+                       docstring const data =
                                prepareCommand(runparams, (*this)[name], it->handling());
                        s += '{' + data + '}';
                        noparam = false;
                        break;
                }
                case ParamInfo::LATEX_OPTIONAL: {
-                       docstring const data =
+                       docstring const data =
                                prepareCommand(runparams, (*this)[name], it->handling());
                        if (!data.empty()) {
                                s += '[' + data + ']';