[LyX/master] DocBook: fix line issues around programlisting.
Thibaut Cuvelier
tcuvelier at lyx.org
Sat Sep 19 18:18:56 UTC 2020
commit 654559feb8b4ed357647554b4043b6c631482b4e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sun Aug 30 23:56:16 2020 +0200
DocBook: fix line issues around programlisting.
---
autotests/export/docbook/listings.xml | 3 +--
src/Paragraph.cpp | 7 +++++--
src/Paragraph.h | 3 ++-
src/insets/InsetListings.cpp | 4 ++++
src/output_docbook.cpp | 6 +++---
5 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/autotests/export/docbook/listings.xml b/autotests/export/docbook/listings.xml
index e65de60..1ed2694 100644
--- a/autotests/export/docbook/listings.xml
+++ b/autotests/export/docbook/listings.xml
@@ -5,6 +5,5 @@
<title>Test document</title>
<para>This is a programlisting: </para>
<programlisting>First line of programlisting
-Second line of programlisting
-</programlisting>
+Second line of programlisting</programlisting>
</article>
\ No newline at end of file
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b4e4bc3..b88c381 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3332,7 +3332,8 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams,
Font const & outerfont,
- pos_type initial) const
+ pos_type initial,
+ bool is_last_par) const
{
// Track whether we have opened these tags
DocBookFontState fs;
@@ -3409,7 +3410,9 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
// I'm worried about what happens if a branch, say, is itself
// wrapped in some font stuff. I think that will not work.
xs->closeFontTags();
- if (runparams.docbook_in_listing)
+
+ // In listings, new lines are very important. Avoid generating one for the last line.
+ if (runparams.docbook_in_listing && !is_last_par)
*xs << xml::CR();
// Finalise the last (and most likely only) paragraph.
diff --git a/src/Paragraph.h b/src/Paragraph.h
index ee31403..96c19c0 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -213,7 +213,8 @@ public:
std::vector<docstring> simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams,
Font const & outerfont,
- pos_type initial = 0) const;
+ pos_type initial = 0,
+ bool is_last_par = false) const;
/// \return any material that has had to be deferred until after the
/// paragraph has closed.
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index 848e4ae..93daab4 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -485,6 +485,9 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
{
InsetLayout const & il = getLayout();
+ if (!xs.isLastTagCR())
+ xs << xml::CR();
+
// Forge the attributes.
string attrs;
if (!il.docbookattr().empty())
@@ -517,6 +520,7 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
// Done with the listing.
xs.endDivision();
xs << xml::EndTag(il.docbooktag());
+ xs << xml::CR();
}
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index d672144..808b4cf 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -504,8 +504,6 @@ void makeParagraph(
// or we're not in the last paragraph, anyway.
// (ii) We didn't open it and docbook_in_par is true,
// but we are in the first par, and there is a next par.
- auto nextpar = par;
- ++nextpar;
bool const close_par = open_par && (!runparams.docbook_in_par);
// Determine if this paragraph has some real content. Things like new pages are not caught
@@ -513,7 +511,9 @@ void makeParagraph(
// Thus, remove all spaces (including new lines: \r, \n) before checking for emptiness.
// std::all_of allows doing this check without having to copy the string.
// Open and close tags around each contained paragraph.
- auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0);
+ auto nextpar = par;
+ ++nextpar;
+ auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end);
for (auto & parXML : pars) {
if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
if (open_par)
More information about the lyx-cvs
mailing list