[LyX features/feature/docbook] DocBook: rewrite makeListEnvironment.
Thibaut Cuvelier
tcuvelier at lyx.org
Sat Aug 29 01:42:57 UTC 2020
The branch, feature/docbook, has been updated.
discards 47ce2b2f69a7da79951d627a82b6d4b6412c81a6 (commit)
discards e08d94883b346e5e121b27285c2cd07d19212836 (commit)
discards 99cfceb0904249c50ec7916899aae2bcdc2aa1a5 (commit)
discards 15ed212126f7299a855de47f2709b77ce897ab3a (commit)
discards 50d5a1ffcbafc1909d6a26718783d8d0b28719a1 (commit)
discards a412f4e4d4bd0569c7652a3c12dd8d699705add4 (commit)
discards 7cd8196c19c76e53c088c5efdf46b5e5b0db569f (commit)
discards 65a8ea8a3f86f58669bdb6d7bf0dd783a5249771 (commit)
discards 54e11837056cbd66b806c86e41361388b995b8ea (commit)
discards bd274b5ffce1cca4949584c8c988f1a15312fedf (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (47ce2b2f69a7da79951d627a82b6d4b6412c81a6)
\
N -- N -- N (9710083657ce41b5c1516bb13d97e2a11d2f0380)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
- Log -----------------------------------------------------------------
commit 9710083657ce41b5c1516bb13d97e2a11d2f0380
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Thu Aug 27 00:52:06 2020 +0200
DocBook: rewrite makeListEnvironment.
diff --git a/autotests/export/docbook/lists.lyx b/autotests/export/docbook/lists.lyx
index f4a58c2..3e8e72a 100644
--- a/autotests/export/docbook/lists.lyx
+++ b/autotests/export/docbook/lists.lyx
@@ -102,11 +102,59 @@ Second item on two lines
I'm the second line
\end_layout
+\begin_layout Itemize
+Third item
+\end_layout
+
\begin_layout Standard
-\begin_inset Note Note
-status collapsed
+A simple enumerated list:
+\end_layout
+
+\begin_layout Enumerate
+First item
+\end_layout
+
+\begin_layout Enumerate
+Second item on two lines
+\begin_inset Newline newline
+\end_inset
+
+I'm the second line
+\end_layout
+
+\begin_layout Standard
+Nested lists:
+\end_layout
+
+\begin_layout Itemize
+First item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+First first item
+\end_layout
+
+\begin_layout Itemize
+First second item
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+Second item
+\end_layout
+
+\begin_deeper
+\begin_layout Itemize
+Second first item
+\end_layout
+
+\begin_layout Itemize
+Second second item
+\end_layout
-\begin_layout Plain Layout
+\end_deeper
+\begin_layout Standard
A complex list:
\end_layout
@@ -123,7 +171,7 @@ First first item
First second item
\end_layout
-\begin_layout Plain Layout
+\begin_layout Standard
Text after first item
\end_layout
@@ -133,23 +181,58 @@ Second item
\end_layout
\begin_deeper
-\begin_layout Enumerate
+\begin_layout Itemize
Second first item
\end_layout
-\begin_layout Enumerate
+\begin_layout Itemize
Second second item
\end_layout
-\begin_layout Plain Layout
+\begin_layout Standard
Text after second item
\end_layout
\end_deeper
-\end_inset
+\begin_layout Standard
+A very complex list:
+\end_layout
+\begin_layout Itemize
+First item
+\end_layout
+\begin_deeper
+\begin_layout Itemize
+First first item
\end_layout
+\begin_layout Itemize
+First second item
+\end_layout
+
+\begin_layout Standard
+Text after first item
+\end_layout
+
+\end_deeper
+\begin_layout Itemize
+Second item
+\end_layout
+
+\begin_deeper
+\begin_layout Enumerate
+Second first item
+\end_layout
+
+\begin_layout Enumerate
+Second second item
+\end_layout
+
+\begin_layout Standard
+Text after second item
+\end_layout
+
+\end_deeper
\end_body
\end_document
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index d7b24f6..c0dad39 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -12,5 +12,97 @@
<para>Second item on two lines</para>
<para>I'm the second line</para>
</listitem>
+<listitem>
+<para>Third item</para>
+</listitem>
+</itemizedlist>
+<para>A simple enumerated list: </para>
+<orderedlist>
+<listitem>
+<para>First item</para>
+</listitem>
+<listitem>
+<para>Second item on two lines</para>
+<para>I'm the second line</para>
+</listitem>
+</orderedlist>
+<para>Nested lists:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
+</itemizedlist>
+</listitem>
+<listitem>
+<para>Second item</para>
+<itemizedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</itemizedlist>
+</listitem>
+</itemizedlist>
+<para>A complex list:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
+</itemizedlist>
+<para>Text after first item</para>
+</listitem>
+<listitem>
+<para>Second item</para>
+<itemizedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</itemizedlist>
+<para>Text after second item</para>
+</listitem>
+</itemizedlist>
+<para>A very complex list:</para>
+<itemizedlist>
+<listitem>
+<para>First item</para>
+<itemizedlist>
+<listitem>
+<para>First first item</para>
+</listitem>
+<listitem>
+<para>First second item</para>
+</listitem>
+</itemizedlist>
+<para>Text after first item</para>
+</listitem>
+<listitem>
+<para>Second item</para>
+<orderedlist>
+<listitem>
+<para>Second first item</para>
+</listitem>
+<listitem>
+<para>Second second item</para>
+</listitem>
+</orderedlist>
+<para>Text after second item</para>
+</listitem>
</itemizedlist>
</article>
\ No newline at end of file
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index c0b346d..700402f 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -43,9 +43,7 @@ Style Itemize
Color latex
EndFont
EndArgument
- DocBookWrapperTag itemizedlist
- DocBookWrapperMergeWithPrevious true
- DocBookTag NONE
+ DocBookTag itemizedlist
DocBookItemTag listitem
DocBookItemInnerTag para
End
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index da59d74..016c022 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -273,7 +273,7 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar
Layout const & prevlay = prevpar->layout();
if (prevlay.docbookwrappertag() != "NONE") {
openWrapper = prevlay.docbookwrappertag() == lay.docbookwrappertag()
- && !lay.docbookwrappermergewithprevious();
+ && !lay.docbookwrappermergewithprevious();
}
}
@@ -306,32 +306,8 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
if (nextpar != nullptr) {
Layout const & nextlay = nextpar->layout();
if (nextlay.docbookwrappertag() != "NONE") {
- if (nextpar->getDepth() == par->getDepth()) {
- // Same depth: the basic condition applies.
- closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
- && !nextlay.docbookwrappermergewithprevious();
- } else if (nextpar->getDepth() > par->getDepth()) {
- // The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
- closeWrapper = 0;
- } else {
- // This paragraph is deeper than the next one: close the wrapper,
- // disregarding docbookwrappermergewithprevious.
- // Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
- closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
- }
- } else {
- if (nextpar->getDepth() == par->getDepth()) {
- // This is not wrapped: this must be the rest of the item, still within the wrapper.
- closeWrapper = 1;
- } else if (nextpar->getDepth() > par->getDepth()) {
- // The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
- closeWrapper = 0;
- } else {
- // This paragraph is deeper than the next one: close the wrapper,
- // disregarding docbookwrappermergewithprevious.
- // Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
- closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
- }
+ closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
+ && !nextlay.docbookwrappermergewithprevious();
}
}
@@ -626,7 +602,6 @@ ParagraphList::const_iterator findEndOfEnvironment(
ParagraphList::const_iterator const & pend)
{
// Copy-paste from XHTML. Should be factored out at some point...
-
ParagraphList::const_iterator p = pstart;
Layout const & bstyle = p->layout();
size_t const depth = p->params().depth();
@@ -660,25 +635,24 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
Buffer const &buf,
XMLStream &xs,
OutputParams const &runparams,
- ParagraphList::const_iterator const & par)
+ ParagraphList::const_iterator const & begin)
{
+ auto par = begin;
auto const end = text.paragraphs().end();
+ auto const envend = findEndOfEnvironment(par, end);
- // Output the opening tag for this environment, but only if it has not been previously opened (condition
- // implemented in openParTag).
- auto prevpar = text.paragraphs().getParagraphBefore(par);
- openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
+ // Output the opening tag for this environment.
+ Layout const & envstyle = par->layout();
+ openTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrapperattr(), envstyle.docbookwrappertagtype());
+ openTag(xs, envstyle.docbooktag(), envstyle.docbookattr(), envstyle.docbooktagtype());
- // Generate the contents of this environment. There is a special case if this is like some environment.
- Layout const & style = par->layout();
- if (style.latextype == LATEX_COMMAND) {
- // Nothing to do (otherwise, infinite loops).
- } else if (style.latextype == LATEX_ENVIRONMENT ||
- style.latextype == LATEX_LIST_ENVIRONMENT ||
- style.latextype == LATEX_ITEM_ENVIRONMENT) {
- // Open a wrapper tag if needed.
- if (style.docbookitemwrappertag() != "NONE")
- openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
+ // Handle the content of the list environment, item by item.
+ while (par != envend) {
+ Layout const & style = par->layout();
+
+ // Open the item.
+ openTag(xs, style.docbookitemtag(), style.docbookitemattr(), style.docbookitemtagtype());
+ openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
// Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
// character after the label.
@@ -706,49 +680,33 @@ ParagraphList::const_iterator makeListEnvironment(Text const &text,
}
}
- // 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
- // of more text.
- bool emptyItem = false;
- if (sep == par->size()) { // If the separator is already at the end of this paragraph...
- 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();
+ // Generate the content of the item.
+ auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+ for (auto & p : pars) {
+ openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
+ xs << XMLStream::ESCAPE_NONE << p;
+ closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
}
- if (emptyItem) {
- // Avoid having an empty item, this is not valid DocBook. A single character is enough to force
- // generation of a full <para>.
- // TODO: this always worked only by magic...
- xs << ' ';
- } else {
- // Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
- auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
- auto p = pars.begin();
- while (true) {
- xs << XMLStream::ESCAPE_NONE << *p;
- ++p;
- if (p != pars.end()) {
- closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
- openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
- } else
- break;
- }
- }
- } else {
- makeAny(text, buf, xs, runparams, par);
+ // If the next item is deeper, it must go entirely within this item (do it recursively).
+ // By construction, with findEndOfEnvironment, depth can only stay constant or increase, never decrease.
+ depth_type currentDepth = par->getDepth();
+ ++par;
+ while (par != envend && par->getDepth() != currentDepth)
+ par = makeAny(text, buf, xs, runparams, par);
+ // Usually, this loop only makes one iteration, except in complex scenarios, like an item with a paragraph,
+ // a list, and another paragraph.
+
+ // Close the item.
+ closeTag(xs, style.docbookitemwrappertag(), style.docbookitemwrappertagtype());
+ closeTag(xs, style.docbookitemtag(), style.docbookitemtagtype());
}
- // Close the environment.
- auto nextpar = par;
- ++nextpar;
- closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+ // Close this environment in exactly the same way as it was opened.
+ closeTag(xs, envstyle.docbooktag(), envstyle.docbooktagtype());
+ closeTag(xs, envstyle.docbookwrappertag(), envstyle.docbookwrappertagtype());
- return nextpar;
+ return envend;
}
@@ -802,6 +760,7 @@ ParagraphList::const_iterator makeAny(Text const &text,
makeBibliography(text, buf, xs, runparams, par);
break;
}
+ ++par;
return par;
}
diff --git a/src/xml.cpp b/src/xml.cpp
index 2f49667..0daa9d8 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -185,6 +185,12 @@ void XMLStream::writeError(docstring const &s)
}
+XMLStream::TagPtr XMLStream::getLastStackTag()
+{
+ return tag_stack_.back();
+}
+
+
bool XMLStream::closeFontTags()
{
if (isTagPending(xml::parsep_tag))
diff --git a/src/xml.h b/src/xml.h
index cdc3b56..bbf5b58 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -127,7 +127,6 @@ private:
// own these pointers and how they will be deleted, so we use shared
// pointers.
///
- typedef std::shared_ptr<xml::StartTag> TagPtr;
typedef std::deque<TagPtr> TagDeque;
///
template <typename T>
commit 0a1f6ffba7ecc870a8acdfd1e714e45ff9ae8f2e
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Aug 29 03:46:30 2020 +0200
DocBook: make all make* functions have the same argument order.
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 0b4c9b9..da59d74 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -375,11 +375,11 @@ ParagraphList::const_iterator makeAny(Text const &,
ParagraphList::const_iterator);
-void makeParagraphBibliography(
+void makeBibliography(
+ Text const & text,
Buffer const & buf,
XMLStream & xs,
OutputParams const & runparams,
- Text const & text,
ParagraphList::const_iterator const & par)
{
// If this is the first paragraph in a bibliography, open the bibliography tag.
@@ -430,10 +430,10 @@ void makeParagraphBibliography(
void makeParagraph(
+ Text const & text,
Buffer const & buf,
XMLStream & xs,
OutputParams const & runparams,
- Text const & text,
ParagraphList::const_iterator const & par)
{
auto const begin = text.paragraphs().begin();
@@ -528,10 +528,10 @@ void makeParagraph(
}
-void makeEnvironment(Buffer const &buf,
+void makeEnvironment(Text const &text,
+ Buffer const &buf,
XMLStream &xs,
OutputParams const &runparams,
- Text const &text,
ParagraphList::const_iterator const & par)
{
// TODO: simplify me!
@@ -656,10 +656,10 @@ ParagraphList::const_iterator findEndOfEnvironment(
}
-ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
+ParagraphList::const_iterator makeListEnvironment(Text const &text,
+ Buffer const &buf,
XMLStream &xs,
OutputParams const &runparams,
- Text const &text,
ParagraphList::const_iterator const & par)
{
auto const end = text.paragraphs().end();
@@ -753,10 +753,10 @@ ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
void makeCommand(
+ Text const & text,
Buffer const & buf,
XMLStream & xs,
OutputParams const & runparams,
- Text const & text,
ParagraphList::const_iterator const & par)
{
// Unlike XHTML, no need for labels, as they are handled by DocBook tags.
@@ -781,25 +781,25 @@ void makeCommand(
ParagraphList::const_iterator makeAny(Text const &text,
Buffer const &buf,
XMLStream &xs,
- OutputParams const &ourparams,
+ OutputParams const &runparams,
ParagraphList::const_iterator par)
{
switch (par->layout().latextype) {
case LATEX_COMMAND:
- makeCommand(buf, xs, ourparams, text, par);
+ makeCommand(text, buf, xs, runparams, par);
break;
case LATEX_ENVIRONMENT:
- makeEnvironment(buf, xs, ourparams, text, par);
+ makeEnvironment(text, buf, xs, runparams, par);
break;
case LATEX_LIST_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
// Only case when makeAny() might consume more than one paragraph.
- return makeListEnvironment(buf, xs, ourparams, text, par);
+ return makeListEnvironment(text, buf, xs, runparams, par);
case LATEX_PARAGRAPH:
- makeParagraph(buf, xs, ourparams, text, par);
+ makeParagraph(text, buf, xs, runparams, par);
break;
case LATEX_BIB_ENVIRONMENT:
- makeParagraphBibliography(buf, xs, ourparams, text, par);
+ makeBibliography(text, buf, xs, runparams, par);
break;
}
return par;
commit 683f7af7dedb768237194b73b603cc294feb9743
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Aug 29 03:03:16 2020 +0200
DocBook: start splitting environment handling in two, to have proper things for lists.
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 625b206..0b4c9b9 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -368,12 +368,11 @@ void closeItemTag(XMLStream & xs, Layout const & lay)
}
-void makeAny(
- Text const &,
- Buffer const &,
- XMLStream &,
- OutputParams const &,
- ParagraphList::const_iterator);
+ParagraphList::const_iterator makeAny(Text const &,
+ Buffer const &,
+ XMLStream &,
+ OutputParams const &,
+ ParagraphList::const_iterator);
void makeParagraphBibliography(
@@ -662,7 +661,6 @@ ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
OutputParams const &runparams,
Text const &text,
ParagraphList::const_iterator const & par)
->>>>>>> be6480e59c... DocBook: same refactoring for docbookSimpleAllParagraphs.
{
auto const end = text.paragraphs().end();
@@ -749,6 +747,8 @@ ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
auto nextpar = par;
++nextpar;
closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+
+ return nextpar;
}
@@ -778,22 +778,23 @@ void makeCommand(
}
-void makeAny(
- Text const &text,
- Buffer const &buf,
- XMLStream &xs,
- OutputParams const &ourparams,
- ParagraphList::const_iterator par)
+ParagraphList::const_iterator makeAny(Text const &text,
+ Buffer const &buf,
+ XMLStream &xs,
+ OutputParams const &ourparams,
+ ParagraphList::const_iterator par)
{
switch (par->layout().latextype) {
case LATEX_COMMAND:
makeCommand(buf, xs, ourparams, text, par);
break;
case LATEX_ENVIRONMENT:
- case LATEX_LIST_ENVIRONMENT:
- case LATEX_ITEM_ENVIRONMENT:
makeEnvironment(buf, xs, ourparams, text, par);
break;
+ case LATEX_LIST_ENVIRONMENT:
+ case LATEX_ITEM_ENVIRONMENT:
+ // Only case when makeAny() might consume more than one paragraph.
+ return makeListEnvironment(buf, xs, ourparams, text, par);
case LATEX_PARAGRAPH:
makeParagraph(buf, xs, ourparams, text, par);
break;
@@ -801,6 +802,7 @@ void makeAny(
makeParagraphBibliography(buf, xs, ourparams, text, par);
break;
}
+ return par;
}
@@ -1207,7 +1209,7 @@ void docbookParagraphs(Text const &text,
}
// Generate this paragraph.
- makeAny(text, buf, xs, ourparams, par);
+ par = makeAny(text, buf, xs, ourparams, par);
}
// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning
commit 656911f2091957ea7af9fa3787b2df11392496e6
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Aug 29 02:55:47 2020 +0200
DocBook: partially remove use of bpit/epit in docbookParagraphs and docbookSimpleAllParagraphs.
This will help with the next refactoring to be much cleaner (only work with iterators, don't maintain twice the same information).
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 6668ee7..625b206 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -306,8 +306,32 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa
if (nextpar != nullptr) {
Layout const & nextlay = nextpar->layout();
if (nextlay.docbookwrappertag() != "NONE") {
- closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
- && !nextlay.docbookwrappermergewithprevious();
+ if (nextpar->getDepth() == par->getDepth()) {
+ // Same depth: the basic condition applies.
+ closeWrapper = nextlay.docbookwrappertag() == lay.docbookwrappertag()
+ && !nextlay.docbookwrappermergewithprevious();
+ } else if (nextpar->getDepth() > par->getDepth()) {
+ // The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
+ closeWrapper = 0;
+ } else {
+ // This paragraph is deeper than the next one: close the wrapper,
+ // disregarding docbookwrappermergewithprevious.
+ // Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
+ closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
+ }
+ } else {
+ if (nextpar->getDepth() == par->getDepth()) {
+ // This is not wrapped: this must be the rest of the item, still within the wrapper.
+ closeWrapper = 1;
+ } else if (nextpar->getDepth() > par->getDepth()) {
+ // The next paragraph is deeper: no need to close the wrapper, only to open it (cf. openParTag).
+ closeWrapper = 0;
+ } else {
+ // This paragraph is deeper than the next one: close the wrapper,
+ // disregarding docbookwrappermergewithprevious.
+ // Hypothesis: nextlay.docbookwrappertag() == lay.docbookwrappertag(). TODO: THIS IS WRONG! Loop back until a layout with the right depth is found?
+ closeWrapper = 1L + (long long) par->getDepth() - (long long) nextpar->getDepth(); // > 0, as nextpar->getDepth() < par->getDepth()
+ }
}
}
@@ -505,12 +529,140 @@ void makeParagraph(
}
-void makeEnvironment(
- Buffer const &buf,
- XMLStream &xs,
- OutputParams const &runparams,
- Text const &text,
- ParagraphList::const_iterator const & par)
+void makeEnvironment(Buffer const &buf,
+ XMLStream &xs,
+ OutputParams const &runparams,
+ Text const &text,
+ ParagraphList::const_iterator const & par)
+{
+ // TODO: simplify me!
+ auto const end = text.paragraphs().end();
+
+ // Output the opening tag for this environment, but only if it has not been previously opened (condition
+ // implemented in openParTag).
+ auto prevpar = text.paragraphs().getParagraphBefore(par);
+ openParTag(xs, &*par, prevpar); // TODO: switch in layout for par/block?
+
+ // Generate the contents of this environment. There is a special case if this is like some environment.
+ Layout const & style = par->layout();
+ if (style.latextype == LATEX_COMMAND) {
+ // Nothing to do (otherwise, infinite loops).
+ } else if (style.latextype == LATEX_ENVIRONMENT) {
+ // Open a wrapper tag if needed.
+ if (style.docbookitemwrappertag() != "NONE")
+ openTag(xs, style.docbookitemwrappertag(), style.docbookitemwrapperattr(), style.docbookitemwrappertagtype());
+
+ // Generate the label, if need be. If it is taken from the text, sep != 0 and corresponds to the first
+ // character after the label.
+ pos_type sep = 0;
+ if (style.labeltype != LABEL_NO_LABEL && style.docbookitemlabeltag() != "NONE") {
+ // At least one condition must be met:
+ // - this environment is not a list
+ // - if this is a list, the label must not be manual (i.e. it must be taken from the layout)
+ if (style.latextype != LATEX_LIST_ENVIRONMENT || style.labeltype != LABEL_MANUAL) {
+ // Usual cases: maybe there is something specified at the layout level. Highly unlikely, though.
+ docstring const lbl = par->params().labelString();
+
+ if (lbl.empty()) {
+ xs << xml::CR();
+ } else {
+ openLabelTag(xs, style);
+ xs << lbl;
+ closeLabelTag(xs, style);
+ }
+ } else {
+ // Only variablelist gets here (or similar items defined as an extension in the layout).
+ openLabelTag(xs, style);
+ sep = par->firstWordDocBook(xs, runparams);
+ closeLabelTag(xs, style);
+ }
+ }
+
+ // 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
+ // of more text.
+ bool emptyItem = false;
+ if (sep == par->size()) { // If the separator is already at the end of this paragraph...
+ 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>.
+ // TODO: this always worked only by magic...
+ xs << ' ';
+ } else {
+ // Generate the rest of the paragraph, if need be. Open as many inner tags as necessary.
+ auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(std::distance(text.paragraphs().begin(), par)), sep);
+ auto p = pars.begin();
+ while (true) {
+ xs << XMLStream::ESCAPE_NONE << *p;
+ ++p;
+ if (p != pars.end()) {
+ closeTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnertagtype());
+ openTag(xs, par->layout().docbookiteminnertag(), par->layout().docbookiteminnerattr(), par->layout().docbookiteminnertagtype());
+ } else
+ break;
+ }
+ }
+ } else {
+ makeAny(text, buf, xs, runparams, par);
+ }
+
+ // Close the environment.
+ auto nextpar = par;
+ ++nextpar;
+ closeParTag(xs, &*par, (nextpar != end) ? &*nextpar : nullptr); // TODO: switch in layout for par/block?
+}
+
+
+ParagraphList::const_iterator findEndOfEnvironment(
+ ParagraphList::const_iterator const & pstart,
+ ParagraphList::const_iterator const & pend)
+{
+ // Copy-paste from XHTML. Should be factored out at some point...
+
+ ParagraphList::const_iterator p = pstart;
+ Layout const & bstyle = p->layout();
+ size_t const depth = p->params().depth();
+ for (++p; p != pend; ++p) {
+ Layout const & style = p->layout();
+ // It shouldn't happen that e.g. a section command occurs inside
+ // a quotation environment, at a higher depth, but as of 6/2009,
+ // it can happen. We pretend that it's just at lowest depth.
+ if (style.latextype == LATEX_COMMAND)
+ return p;
+
+ // If depth is down, we're done
+ if (p->params().depth() < depth)
+ return p;
+
+ // If depth is up, we're not done
+ if (p->params().depth() > depth)
+ continue;
+
+ // FIXME I am not sure about the first check.
+ // Surely we *could* have different layouts that count as
+ // LATEX_PARAGRAPH, right?
+ if (style.latextype == LATEX_PARAGRAPH || style != bstyle)
+ return p;
+ }
+ return pend;
+}
+
+
+ParagraphList::const_iterator makeListEnvironment(Buffer const &buf,
+ XMLStream &xs,
+ OutputParams const &runparams,
+ Text const &text,
+ ParagraphList::const_iterator const & par)
+>>>>>>> be6480e59c... DocBook: same refactoring for docbookSimpleAllParagraphs.
{
auto const end = text.paragraphs().end();
@@ -919,12 +1071,13 @@ void docbookSimpleAllParagraphs(
outputDocBookInfo(text, buf, xs, runparams, paragraphs, info);
// Then, the content. It starts where the <info> ends.
- bpit = info.epit;
- while (bpit < epit) {
- auto par = paragraphs.iterator_at(bpit);
+ auto par = text.paragraphs().iterator_at(info.epit);
+ auto end = text.paragraphs().iterator_at(epit);
+ while (par != end) {
if (!hasOnlyNotes(*par))
- makeAny(text, buf, xs, runparams, par);
- bpit += 1;
+ par = makeAny(text, buf, xs, runparams, par);
+ else
+ ++par;
}
}
@@ -965,21 +1118,20 @@ void docbookParagraphs(Text const &text,
bool currentlyInAppendix = false;
- while (bpit < epit) {
+ auto par = text.paragraphs().iterator_at(bpit);
+ auto end = text.paragraphs().iterator_at(epit);
+ while (par != end) {
OutputParams ourparams = runparams;
- auto par = paragraphs.iterator_at(bpit);
if (par->params().startOfAppendix())
currentlyInAppendix = true;
- Layout const &style = par->layout();
- ParagraphList::const_iterator const lastStartedPar = par;
- ParagraphList::const_iterator send;
-
if (hasOnlyNotes(*par)) {
- bpit += 1;
+ ++par;
continue;
}
+ Layout const &style = par->layout();
+
// Think about adding <section> and/or </section>s.
const bool isLayoutSectioning = style.category() == from_utf8("Sectioning");
if (isLayoutSectioning) {
@@ -1056,7 +1208,6 @@ void docbookParagraphs(Text const &text,
// Generate this paragraph.
makeAny(text, buf, xs, ourparams, par);
- bpit += 1;
}
// If need be, close <section>s, but only at the end of the document (otherwise, dealt with at the beginning
commit e4a05340b43fa612545d56cfb61f9de207a93ed9
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Aug 29 02:43:30 2020 +0200
XML: use the new mechanisms for CR detection with errors.
This helps tracking down line problems even in the presence of errors.
diff --git a/src/xml.cpp b/src/xml.cpp
index b4004af..2f49667 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -167,17 +167,21 @@ bool FontTag::operator==(StartTag const & tag) const
} // namespace xml
-void XMLStream::writeError(std::string const &s) const
+void XMLStream::writeError(std::string const &s)
{
LYXERR0(s);
- os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
+ *this << ESCAPE_NONE << from_utf8("<!-- Output Error: " + s + " -->");
+ *this << xml::CR();
}
-void XMLStream::writeError(docstring const &s) const
+void XMLStream::writeError(docstring const &s)
{
LYXERR0(s);
- os_ << from_utf8("<!-- Output Error: ") << s << from_utf8(" -->\n");
+ *this << ESCAPE_NONE << from_utf8("<!-- Output Error: ");
+ *this << s;
+ *this << ESCAPE_NONE << from_utf8(" -->");
+ *this << xml::CR();
}
diff --git a/src/xml.h b/src/xml.h
index 576a4f2..cdc3b56 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -105,9 +105,13 @@ public:
/// that simplifies the logic using this code.
bool isLastTagCR() const { return is_last_tag_cr_; };
///
- void writeError(std::string const &) const;
+ void writeError(std::string const &);
///
- void writeError(docstring const &) const;
+ void writeError(docstring const &);
+ ///
+ typedef std::shared_ptr<xml::StartTag> TagPtr;
+ /// Returns the last element on the tag stack. XMLStream keeps ownership of the item.
+ TagPtr getLastStackTag();
private:
///
void clearTagDeque();
-----------------------------------------------------------------------
Summary of changes:
src/output_docbook.cpp | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
hooks/post-receive
--
Repository for new features
More information about the lyx-cvs
mailing list