]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Limit the nopassthurchars case in beamer to URL
[lyx.git] / src / Paragraph.cpp
index 5ac03fa474429cbfecfbcbb0394e0ec53fb04677..a63017db328bc0c549c6f8a938719ffcb60de211 100644 (file)
@@ -354,6 +354,7 @@ public:
                                   Font const & running_font,
                                   string & alien_script,
                                   Layout const & style,
+                                  InsetLayout const & il,
                                   pos_type & i,
                                   pos_type end_pos,
                                   unsigned int & column) const;
@@ -1172,6 +1173,8 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
                        ? textinset->hasCProtectContent(runparams.moving_arg)
                          && !textinset->text().isMainText()
                          && inset->lyxCode() != BRANCH_CODE
+                         && !runparams.no_cprotect
+                         && !inset->getLayout().noCProtect()
                        : false;
                unsigned int count2 = basefont.latexWriteStartChanges(os, bparams,
                                                      rp, running_font,
@@ -1233,15 +1236,27 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                                          Font const & running_font,
                                          string & alien_script,
                                          Layout const & style,
+                                         InsetLayout const & il,
                                          pos_type & i,
                                          pos_type end_pos,
                                          unsigned int & column) const
 {
        char_type const c = owner_->getUChar(bparams, runparams, i);
 
-       if (style.pass_thru || runparams.pass_thru || runparams.find_effective()
+       // Special case: URLs with hyperref need to escape backslash, # and % (#13012).
+       // Both a layout tag and a dedicated inset seem too much effort for this.
+       string const hr_url_escape_chars = "\\#%";
+       if (contains(hr_url_escape_chars, c) && runparams.use_hyperref && il.latexname() == "url"
+           && il.required().find("url") != il.required().end()) {
+               os << "\\";
+               os.put(c);
+               return;
+       }
+
+       if ((style.pass_thru || runparams.pass_thru || runparams.find_effective()
            || contains(style.pass_thru_chars, c)
-           || contains(runparams.pass_thru_chars, c)) {
+           || contains(runparams.pass_thru_chars, c))
+           && !contains(runparams.no_pass_thru_chars, c)) {
                if (runparams.find_effective()) {
                        switch (c) {
                        case '\\':
@@ -2375,8 +2390,8 @@ bool Paragraph::allowedInContext(Cursor const & cur, InsetLayout const & il) con
        if (in_allowed_inset && inInset().asInsetText() && il.allowedOccurrences() != -1) {
                ParagraphList & pars = cur.text()->paragraphs();
                        for (Paragraph const & par : pars) {
-                               for (auto const & table : par.insetList())
-                               if (table.inset->getLayout().name() == il.name())
+                               for (auto const & elem : par.insetList())
+                               if (elem.inset->getLayout().name() == il.name())
                                        ++have_ins;
                        }
                if (have_ins >= il.allowedOccurrences())
@@ -2412,8 +2427,8 @@ bool Paragraph::allowedInContext(Cursor const & cur, InsetLayout const & il) con
                for (; pit <= lastpit; ++pit) {
                        if (&pars[pit].layout() != d->layout_)
                                break;
-                       for (auto const & table : pars[pit].insetList())
-                               if (table.inset->getLayout().name() == il.name())
+                       for (auto const & elem : pars[pit].insetList())
+                               if (elem.inset->getLayout().name() == il.name())
                                        ++have_ins;
                }
                if (have_ins >= il.allowedOccurrences())
@@ -3014,6 +3029,7 @@ void Paragraph::latex(BufferParams const & bparams,
                                        ? textinset->hasCProtectContent(runparams.moving_arg)
                                          && !textinset->text().isMainText()
                                          && inInset().lyxCode() != BRANCH_CODE
+                                         && !runparams.no_cprotect
                                        : false;
                                column += current_font.latexWriteStartChanges(ots, bparams,
                                                                              runparams, basefont, last_font, false,
@@ -3150,8 +3166,9 @@ void Paragraph::latex(BufferParams const & bparams,
                                }
                        }
                } else if (i >= start_pos && (end_pos == -1 || i < end_pos)) {
-                       if (!bparams.useNonTeXFonts)
-                         script = Encodings::isKnownScriptChar(c);
+                       if (!bparams.useNonTeXFonts && !runparams.pass_thru
+                           && !contains(runparams.pass_thru_chars, c))
+                               script = Encodings::isKnownScriptChar(c);
                        if (script != alien_script) {
                                if (!alien_script.empty()) {
                                        os << "}";
@@ -3166,8 +3183,8 @@ void Paragraph::latex(BufferParams const & bparams,
                                }
                        }
                        try {
-                               d->latexSpecialChar(os, bparams, rp, running_font,
-                                                                       alien_script, style, i, end_pos, column);
+                               d->latexSpecialChar(os, bparams, rp, running_font, alien_script,
+                                                   style, inInset().getLayout(), i, end_pos, column);
                        } catch (EncodingException & e) {
                                if (runparams.dryrun) {
                                        os << "<" << _("LyX Warning: ")
@@ -4283,9 +4300,10 @@ bool Paragraph::isHardHyphenOrApostrophe(pos_type pos) const
 bool Paragraph::needsCProtection(bool const fragile) const
 {
        // first check the layout of the paragraph, but only in insets
+       // and not in tables
        InsetText const * textinset = inInset().asInsetText();
        bool const maintext = textinset
-               ? textinset->text().isMainText()
+               ? textinset->text().isMainText() || inInset().lyxCode() == CELL_CODE
                : false;
 
        if (!maintext && layout().needcprotect) {
@@ -4423,7 +4441,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out
                else if (c == META_INSET && (options & AS_STR_INSETS)) {
                        if (c == META_INSET && (options & AS_STR_PLAINTEXT)) {
                                LASSERT(runparams != nullptr, return docstring());
-                               if (runparams->find_effective() && getInset(i)->hasToString())
+                               if (runparams->find_effective() && getInset(i)->findUsesToString())
                                        getInset(i)->toString(os);
                                else
                                        getInset(i)->plaintext(os, *runparams);