[LyX/master] DocBook: fix issues with nested labeling lists.
Thibaut Cuvelier
tcuvelier at lyx.org
Sun Jul 26 02:19:13 UTC 2020
commit e0b8bac36e4bd52330a3b3ca06f2b3404760af7d
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sun Jul 26 04:44:04 2020 +0200
DocBook: fix issues with nested labeling lists.
---
autotests/export/docbook/Development.xml | 11 +-
.../export/docbook/description_list_nested.xml | 4 +-
autotests/export/docbook/labeling_list_nested.lyx | 150 ++++++++++++++++++++
autotests/export/docbook/labeling_list_nested.xml | 56 ++++++++
autotests/export/docbook/lists.xml | 1 +
src/output_docbook.cpp | 40 ++++--
6 files changed, 243 insertions(+), 19 deletions(-)
diff --git a/autotests/export/docbook/Development.xml b/autotests/export/docbook/Development.xml
index 8583459..9f3f3e9 100644
--- a/autotests/export/docbook/Development.xml
+++ b/autotests/export/docbook/Development.xml
@@ -50,6 +50,7 @@
</varlistentry>
</variablelist>
</listitem>
+</varlistentry>
<varlistentry>
<term>New inset</term>
@@ -71,9 +72,7 @@
<para> If a style or inset layout is removed in any layout file or module shipped with LyX, a new file format is required.</para>
</listitem>
</varlistentry>
-<!-- Output Error: Closing tag `variablelist' when other tags are open, namely: -->
-<!-- Output Error: varlistentry -->
-</varlistentry></variablelist>
+</variablelist>
<para>However, <emphasis role='bold'>new</emphasis> layouts and modules do <emphasis role='bold'>not</emphasis> require a file format update (changed 03/16). </para>
<para>If you are still unsure, please ask on the development list.</para>
<section xml:id="par.export-test-output-formats-1">
@@ -109,6 +108,7 @@
</varlistentry>
</variablelist>
</listitem>
+</varlistentry>
<varlistentry>
<term>LyX + LaTeX:</term>
@@ -173,6 +173,7 @@
</varlistentry>
</variablelist>
</listitem>
+</varlistentry>
<varlistentry>
<term>LyX + LaTeX + postprocessing:</term>
@@ -195,6 +196,7 @@
</varlistentry>
</variablelist>
</listitem>
+</varlistentry>
<varlistentry>
<term>not tested:</term>
@@ -303,9 +305,6 @@
</listitem>
<!-- Output Error: Closing tag `variablelist' when other tags are open, namely: -->
<!-- Output Error: varlistentry -->
-</varlistentry><!-- Output Error: varlistentry -->
-</varlistentry><!-- Output Error: varlistentry -->
-</varlistentry><!-- Output Error: varlistentry -->
</varlistentry></variablelist>
</section>
</section>
diff --git a/autotests/export/docbook/description_list_nested.xml b/autotests/export/docbook/description_list_nested.xml
index c08bec4..fc50c2c 100644
--- a/autotests/export/docbook/description_list_nested.xml
+++ b/autotests/export/docbook/description_list_nested.xml
@@ -25,8 +25,8 @@
</listitem>
</varlistentry>
</variablelist>
-<!-- lastlay != nullptr; item tag: listitem; item wrapper tag: varlistentry --></listitem>
-<!-- has docbookwrappertag --></varlistentry>
+</listitem>
+</varlistentry>
<varlistentry>
<term>New inset</term>
diff --git a/autotests/export/docbook/labeling_list_nested.lyx b/autotests/export/docbook/labeling_list_nested.lyx
new file mode 100644
index 0000000..b948fee
--- /dev/null
+++ b/autotests/export/docbook/labeling_list_nested.lyx
@@ -0,0 +1,150 @@
+#LyX 2.4 created this file. For more info see https://www.lyx.org/
+\lyxformat 598
+\begin_document
+\begin_header
+\save_transient_properties true
+\origin unavailable
+\textclass scrartcl
+\options BCOR8mm,captions=tableheading
+\use_default_options false
+\begin_modules
+logicalmkup
+\end_modules
+\maintain_unincluded_children no
+\language english
+\language_package default
+\inputencoding utf8
+\fontencoding auto
+\font_roman "lmodern" "default"
+\font_sans "lmss" "default"
+\font_typewriter "lmtt" "default"
+\font_math "auto" "auto"
+\font_default_family default
+\use_non_tex_fonts false
+\font_sc false
+\font_roman_osf false
+\font_sans_osf false
+\font_typewriter_osf false
+\font_sf_scale 100 100
+\font_tt_scale 100 100
+\use_microtype false
+\use_dash_ligatures true
+\graphics default
+\default_output_format pdf2
+\output_sync 1
+\bibtex_command default
+\index_command default
+\paperfontsize 12
+\spacing single
+\use_hyperref true
+\pdf_title "LyX's Development manual"
+\pdf_author "LyX Team"
+\pdf_subject "LyX's development documentation"
+\pdf_keywords "LyX, Documentation, Development"
+\pdf_bookmarks true
+\pdf_bookmarksnumbered true
+\pdf_bookmarksopen true
+\pdf_bookmarksopenlevel 1
+\pdf_breaklinks false
+\pdf_pdfborder false
+\pdf_colorlinks true
+\pdf_backref false
+\pdf_pdfusetitle false
+\pdf_quoted_options "linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false"
+\papersize a4
+\use_geometry false
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 1
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 1
+\use_package mhchem 1
+\use_package stackrel 1
+\use_package stmaryrd 1
+\use_package undertilde 1
+\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\justification true
+\use_refstyle 0
+\use_minted 0
+\use_lineno 0
+\notefontcolor #0000ff
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\secnumdepth 4
+\tocdepth 4
+\paragraph_separation indent
+\paragraph_indentation default
+\is_math_indent 0
+\math_numbering_side default
+\quotes_style english
+\dynamic_quotes 0
+\papercolumns 1
+\papersides 2
+\paperpagestyle headings
+\tablestyle default
+\tracking_changes false
+\output_changes false
+\change_bars false
+\postpone_fragile_content false
+\html_math_output 0
+\html_css_as_file 0
+\html_be_strict true
+\docbook_table_output 0
+\end_header
+
+\begin_body
+
+\begin_layout Title
+Developing \SpecialChar LyX
+
+\end_layout
+
+\begin_layout Standard
+The following output formats are currently tested for each sample document:
+\end_layout
+
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+LyX:
+\end_layout
+
+\begin_deeper
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+lyx16 LyX 1.6 file format (lyx2lyx)
+\end_layout
+
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+lyx21
+\end_layout
+
+\end_deeper
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+LyX:
+\end_layout
+
+\begin_deeper
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+lyx16 LyX 1.6 file format (lyx2lyx)
+\end_layout
+
+\begin_layout Labeling
+\labelwidthstring 00.00.0000
+lyx21
+\end_layout
+
+\end_deeper
+\end_body
+\end_document
diff --git a/autotests/export/docbook/labeling_list_nested.xml b/autotests/export/docbook/labeling_list_nested.xml
new file mode 100644
index 0000000..261605c
--- /dev/null
+++ b/autotests/export/docbook/labeling_list_nested.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This DocBook file was created by LyX 2.4.0dev
+ See http://www.lyx.org/ for more information -->
+<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<title>Developing LyX</title>
+<para>The following output formats are currently tested for each sample document:</para>
+<variablelist>
+<varlistentry>
+<term>LyX:</term>
+
+<listitem>
+
+<variablelist>
+<varlistentry>
+<term>lyx16</term>
+
+<listitem>
+<para> LyX 1.6 file format (lyx2lyx)</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>lyx21</term>
+
+<listitem>
+<para> </para>
+</listitem>
+</varlistentry>
+</variablelist>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>LyX:</term>
+
+<listitem>
+
+<variablelist>
+<varlistentry>
+<term>lyx16</term>
+
+<listitem>
+<para> LyX 1.6 file format (lyx2lyx)</para>
+</listitem>
+</varlistentry>
+<varlistentry>
+<term>lyx21</term>
+
+<listitem>
+<para> </para>
+</listitem>
+</varlistentry>
+</variablelist>
+</listitem>
+</varlistentry>
+</variablelist>
+
+</article>
\ No newline at end of file
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index ae956c5..a00ab4f 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -30,4 +30,5 @@
<para>Text after second item</para>
</listitem>
</itemizedlist>
+
</article>
\ No newline at end of file
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 9c34115..489230d 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -508,10 +508,8 @@ ParagraphList::const_iterator makeEnvironment(
if (par->params().depth() == origdepth) {
LATTEST(bstyle == style);
if (lastlay != nullptr) {
- xs << XMLStream::ESCAPE_NONE << ("<!-- lastlay != nullptr; item tag: " + from_utf8(lastlay->docbookitemtag()) + "; item wrapper tag: " + from_utf8(lastlay->docbookitemwrappertag()) + " -->");
closeItemTag(xs, *lastlay);
if (lastlay->docbookitemwrappertag() != "NONE") {
- xs << XMLStream::ESCAPE_NONE << "<!-- has docbookwrappertag -->";
xs << xml::EndTag(lastlay->docbookitemwrappertag());
xs << xml::CR();
}
@@ -561,13 +559,35 @@ ParagraphList::const_iterator makeEnvironment(
}
} // end label output
+ // Start generating the item.
bool wasInParagraph = runparams.docbook_in_par;
openItemTag(xs, style);
bool getsIntoParagraph = openInnerItemTag(xs, style);
OutputParams rp = runparams;
rp.docbook_in_par = wasInParagraph | getsIntoParagraph;
- par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
+ // Maybe the item is completely empty, i.e. if the first word ends at the end of the current paragraph
+ // AND if the next paragraph doesn't have the same depth (if there is such a paragraph).
+ // Common case: there is only the first word on the line, but there is a nested list instead.
+ bool emptyItem = false;
+ if (sep == par->size()) {
+ auto next_par = par;
+ ++next_par;
+ if (next_par == text.paragraphs().end()) // There is no next paragraph.
+ emptyItem = true;
+ else // There is a next paragraph: check depth.
+ emptyItem = par->params().depth() > next_par->params().depth();
+ }
+
+ if (emptyItem) {
+ // Avoid having an empty item, this is not valid DocBook. A single character is enough to force
+ // generation of a full <para>.
+ xs << ' ';
+ } else {
+ // Generate the rest of the paragraph, if need be.
+ par->simpleDocBookOnePar(buf, xs, rp, text.outerFont(distance(begin, par)), true, true, sep);
+ }
+
++par;
if (getsIntoParagraph)
closeInnerItemTag(xs, style);
@@ -613,8 +633,13 @@ ParagraphList::const_iterator makeEnvironment(
}
}
- if (lastlay != 0)
+ if (lastlay != nullptr) {
closeItemTag(xs, *lastlay);
+ if (lastlay->docbookitemwrappertag() != "NONE") {
+ xs << xml::EndTag(lastlay->docbookitemwrappertag());
+ xs << xml::CR();
+ }
+ }
closeTag(xs, bstyle);
xs << xml::CR();
return pend;
@@ -731,10 +756,6 @@ DocBookInfoTag getParagraphsWithInfo(ParagraphList const ¶graphs, pit_type c
// Based on layout information, store this paragraph in one set: should be in <info>, must be.
Layout const &style = par.layout();
- std::cout << "Name: " << to_utf8(style.name()) << std::endl;
- std::cout << " DocBook tag: " << style.docbooktag() << std::endl;
- std::cout << " In info: " << style.docbookininfo() << std::endl;
-
if (style.docbookininfo() == "always") {
mustBeInInfo.emplace(cpit);
} else if (style.docbookininfo() == "maybe") {
@@ -796,14 +817,11 @@ pit_type generateDocBookParagraphWithoutSectioning(
(epit == (int) paragraphs.size()) ?
paragraphs.end() : paragraphs.iterator_at(epit);
- std::cout << "generateDocBookParagraphWithoutSectioning" << std::endl;
while (bpit < epit) {
- std::cout << "iteration; bpit: " << bpit << std::endl;
tie(par, send) = makeAny(text, buf, xs, runparams, par, send, pend);
bpit += distance(lastStartedPar, par);
lastStartedPar = par;
}
- std::cout << "generateDocBookParagraphWithoutSectioning has looped; bpit: " << bpit << std::endl;
return bpit;
}
More information about the lyx-cvs
mailing list