From d4095dc0e65d292c3ae0772a429d1db662573f14 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 9 Dec 2022 01:25:34 +0100 Subject: [PATCH] =?utf8?q?Export=20'=20(straight)=20as=20=E2=80=99=20(curl?= =?utf8?q?y)=20in=20DocBook?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is similar to what LaTeX does in its output. See the (long) discussion in ticket #11244. Port of ad3e6c69b2ce for DocBook. This patch requires delaying entire strings instead of just characters, so that the DocBook code path can be as similar to the XHTML one as possible. --- src/Paragraph.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 6b156b9dac..3f1f814b47 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3552,7 +3552,7 @@ std::tuple, std::vector, std::vector delayedChars; // When a font tag ends with a space, output it after the closing font tag. + std::vector delayedChars; // When a font tag ends with a space, output it after the closing font tag. // This requires to store delayed characters at some point. DocBookFontState fs; // Track whether we have opened font tags @@ -3610,8 +3610,8 @@ std::tuple, std::vector, std::vector, std::vector, std::vectorparams(), rp, i); - if (lyx::isSpace(c) && !ignore_fonts) - delayedChars.push_back(c); - else - *xs << c; + if (lyx::isSpace(c) && !ignore_fonts) { // Delay spaces *after* the font-tag closure for cleaner output. + if (c == ' ' && (style.free_spacing || rp.free_spacing)) { + delayedChars.push_back(from_ascii(" ")); + } else { + delayedChars.emplace_back(1, c); + } + } else { // No need to delay the character. + if (c == '\'') + *xs << XMLStream::ESCAPE_NONE << "’"; + else + *xs << c; + } } font_old = font.fontInfo(); } @@ -3657,9 +3665,11 @@ std::tuple, std::vector, std::vectorcloseFontTags(); // Deal with the delayed characters *after* closing font tags. - if (!delayedChars.empty()) - for (char_type c: delayedChars) - *xs << c; + if (!delayedChars.empty()) { + for (const docstring &c: delayedChars) + *xs << XMLStream::ESCAPE_NONE << c; + delayedChars.clear(); + } // In listings, new lines (i.e. \n characters in the output) are very important. Avoid generating one for the // last line to get a clean output. -- 2.39.5