DocBook: fix line issues around programlisting.

This commit is contained in:
Thibaut Cuvelier 2020-08-30 23:56:16 +02:00
parent 9d3a717ef1
commit 654559feb8
5 changed files with 15 additions and 8 deletions

View File

@ -5,6 +5,5 @@
<title>Test document</title> <title>Test document</title>
<para>This is a programlisting: </para> <para>This is a programlisting: </para>
<programlisting>First line of programlisting <programlisting>First line of programlisting
Second line of programlisting Second line of programlisting</programlisting>
</programlisting>
</article> </article>

View File

@ -3332,7 +3332,8 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf, std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams, OutputParams const & runparams,
Font const & outerfont, Font const & outerfont,
pos_type initial) const pos_type initial,
bool is_last_par) const
{ {
// Track whether we have opened these tags // Track whether we have opened these tags
DocBookFontState fs; 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 // I'm worried about what happens if a branch, say, is itself
// wrapped in some font stuff. I think that will not work. // wrapped in some font stuff. I think that will not work.
xs->closeFontTags(); 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(); *xs << xml::CR();
// Finalise the last (and most likely only) paragraph. // Finalise the last (and most likely only) paragraph.

View File

@ -213,7 +213,8 @@ public:
std::vector<docstring> simpleDocBookOnePar(Buffer const & buf, std::vector<docstring> simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams, OutputParams const & runparams,
Font const & outerfont, 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 /// \return any material that has had to be deferred until after the
/// paragraph has closed. /// paragraph has closed.

View File

@ -485,6 +485,9 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
{ {
InsetLayout const & il = getLayout(); InsetLayout const & il = getLayout();
if (!xs.isLastTagCR())
xs << xml::CR();
// Forge the attributes. // Forge the attributes.
string attrs; string attrs;
if (!il.docbookattr().empty()) if (!il.docbookattr().empty())
@ -517,6 +520,7 @@ void InsetListings::docbook(XMLStream & xs, OutputParams const & rp) const
// Done with the listing. // Done with the listing.
xs.endDivision(); xs.endDivision();
xs << xml::EndTag(il.docbooktag()); xs << xml::EndTag(il.docbooktag());
xs << xml::CR();
} }

View File

@ -504,8 +504,6 @@ void makeParagraph(
// or we're not in the last paragraph, anyway. // or we're not in the last paragraph, anyway.
// (ii) We didn't open it and docbook_in_par is true, // (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. // 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); 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 // 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. // 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. // std::all_of allows doing this check without having to copy the string.
// Open and close tags around each contained paragraph. // 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) { for (auto & parXML : pars) {
if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) { if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
if (open_par) if (open_par)