diff --git a/lib/layouts/stdlayouts.inc b/lib/layouts/stdlayouts.inc index 16706956b7..e550518a60 100644 --- a/lib/layouts/stdlayouts.inc +++ b/lib/layouts/stdlayouts.inc @@ -7,7 +7,7 @@ # quotations and such. -Format 82 +Format 84 Style Quotation Category MainText diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc index 16a9e8188f..c0b346dbd1 100644 --- a/lib/layouts/stdlists.inc +++ b/lib/layouts/stdlists.inc @@ -6,7 +6,7 @@ # This include files contains various standard environments for lists. -Format 82 +Format 84 Input stdlyxlist.inc diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc index c8b7eb4cbd..2a81117354 100644 --- a/lib/layouts/stdstruct.inc +++ b/lib/layouts/stdstruct.inc @@ -8,7 +8,7 @@ # a document, like abstract, bibliography and such. -Format 82 +Format 84 Style Abstract Margin Static diff --git a/lib/layouts/stdtitle.inc b/lib/layouts/stdtitle.inc index ad989a6767..44b1b8e067 100644 --- a/lib/layouts/stdtitle.inc +++ b/lib/layouts/stdtitle.inc @@ -8,7 +8,7 @@ # a document, like title, author and such. -Format 82 +Format 84 Style Title Margin Static @@ -29,6 +29,7 @@ Style Title HTMLTag h1 HTMLTitle true DocBookTag title + DocBookTagType paragraph DocBookInInfo maybe End @@ -50,7 +51,9 @@ Style Author Size Large EndFont DocBookTag personname + DocBookTagType paragraph DocBookWrapperTag author + DocBookWrapperTagType inline DocBookInInfo always End @@ -72,5 +75,6 @@ Style Date Size Large EndFont DocBookTag date + DocBookTagType paragraph DocBookInInfo always End diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index 00b276ea47..7cba0f756a 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -181,7 +181,7 @@ void InsetNewline::docbook(XMLStream & xs, OutputParams const & runparams) const // about the paragraph's layout... Good for now, though, this should not happen in DocBook, only maybe // extensions. xs << XMLStream::ESCAPE_NONE << from_utf8(""); - xs << XMLStream::ESCAPE_NONE << from_utf8("\n\n"); // TODO: that's a hack... // xs << xml::EndTag("para"); // xs << xml::CR(); diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index b29da56c34..b7b59413ad 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -43,8 +43,6 @@ #include #include -// #define DOCBOOK_DEBUG_NEWLINES - using namespace std; using namespace lyx::support; @@ -189,14 +187,100 @@ xml::EndFontTag docbookEndFontTag(xml::FontTypes type) namespace { -// convenience functions +// Convenience functions to open and close tags. First, very low-level ones to ensure a consistent new-line behaviour. +// Block style: +// Content before +// +// Contents of the block. +// +// Content after +// Paragraph style: +// Content before +// Contents of the paragraph. +// Content after +// Inline style: +// Content beforeContents of the paragraph.Content after + +void openInlineTag(XMLStream & xs, const std::string & tag, const std::string & attr) +{ + xs << xml::StartTag(tag, attr); +} + + +void closeInlineTag(XMLStream & xs, const std::string & tag) +{ + xs << xml::EndTag(tag); +} + + +void openParTag(XMLStream & xs, const std::string & tag, const std::string & attr) +{ + if (!xs.isLastTagCR()) + xs << xml::CR(); + xs << xml::StartTag(tag, attr); +} + + +void closeParTag(XMLStream & xs, const std::string & tag) +{ + xs << xml::EndTag(tag); + xs << xml::CR(); +} + + +void openBlockTag(XMLStream & xs, const std::string & tag, const std::string & attr) +{ + if (!xs.isLastTagCR()) + xs << xml::CR(); + xs << xml::StartTag(tag, attr); + xs << xml::CR(); +} + + +void closeBlockTag(XMLStream & xs, const std::string & tag) +{ + xs << xml::CR(); + xs << xml::EndTag(tag); + xs << xml::CR(); +} + + +void openTag(XMLStream & xs, const std::string & tag, const std::string & attr, const std::string & tagtype) +{ + if (tag.empty() || tag == "NONE") + return; + + if (tag == "para" || tagtype == "paragraph") // Special case for : always considered as a paragraph. + openParTag(xs, tag, attr); + else if (tagtype == "block") + openBlockTag(xs, tag, attr); + else if (tagtype == "inline") + openInlineTag(xs, tag, attr); + else + xs.writeError("Unrecognised tag type '" + tagtype + "' for '" + tag + " " + attr + "'"); +} + + +void closeTag(XMLStream & xs, const std::string & tag, const std::string & tagtype) +{ + if (tag.empty() || tag == "NONE") + return; + + if (tag == "para" || tagtype == "paragraph") // Special case for : always considered as a paragraph. + closeParTag(xs, tag); + else if (tagtype == "block") + closeBlockTag(xs, tag); + else if (tagtype == "inline") + closeInlineTag(xs, tag); + else + xs.writeError("Unrecognised tag type '" + tagtype + "' for '" + tag + "'"); +} + + +// Higher-level convenience functions. void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar) { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - Layout const & lay = par->layout(); if (par == prevpar) @@ -218,38 +302,25 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar } // Main logic. - if (openWrapper) { - xs << xml::StartTag(lay.docbookwrappertag(), lay.docbookwrapperattr()); - xs << xml::CR(); - } + if (openWrapper) + openTag(xs, lay.docbookwrappertag(), lay.docbookwrapperattr(), lay.docbookwrappertagtype()); - string tag = lay.docbooktag(); + const string & tag = lay.docbooktag(); if (tag != "NONE") { auto xmltag = xml::ParTag(tag, lay.docbookattr()); - if (!xs.isTagOpen(xmltag, 1)) // Don't nest a paragraph directly in a paragraph. TODO: required or not? - xs << xmltag; + if (!xs.isTagOpen(xmltag, 1)) // Don't nest a paragraph directly in a paragraph. + // TODO: required or not? + // TODO: avoid creating a ParTag object just for this query... + openTag(xs, lay.docbooktag(), lay.docbookattr(), lay.docbooktagtype()); } - if (lay.docbookitemtag() != "NONE") { - xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr()); - xs << xml::CR(); - } - - if (lay.docbookiteminnertag() != "NONE") - xs << xml::StartTag(lay.docbookiteminnertag(), lay.docbookiteminnerattr()); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype()); + openTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnerattr(), lay.docbookiteminnertagtype()); } void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpar) { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - if (par == nextpar) nextpar = nullptr; @@ -265,119 +336,35 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa } // Main logic. - if (lay.docbookiteminnertag() != "NONE") { - xs << xml::EndTag(lay.docbookiteminnertag()); - xs << xml::CR(); - } - - if (lay.docbookitemtag() != "NONE") { - xs << xml::EndTag(lay.docbookitemtag()); - xs << xml::CR(); - } - - if (lay.docbooktag() != "NONE") { - xs << xml::EndTag(lay.docbooktag()); - xs << xml::CR(); - } - - if (closeWrapper) { - xs << xml::EndTag(lay.docbookwrappertag()); - xs << xml::CR(); - } - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif -} - - -void openBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar) -{ -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - // Similar as openParTag, but with a line feed after. - openParTag(xs, par, prevpar); - xs << xml::CR(); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif -} - - -void closeBlockTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar) -{ -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - // Similar as closeParTag, but with a line feed before. - xs << xml::CR(); - closeParTag(xs, par, prevpar); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + closeTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnertagtype()); + closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype()); + closeTag(xs, lay.docbooktag(), lay.docbooktagtype()); + if (closeWrapper) + closeTag(xs, lay.docbookwrappertag(), lay.docbookwrappertagtype()); } void openLabelTag(XMLStream & xs, Layout const & lay) // Mostly for definition lists. { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - xs << xml::StartTag(lay.docbookitemlabeltag(), lay.docbookitemlabelattr()); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + openTag(xs, lay.docbookitemlabeltag(), lay.docbookitemlabelattr(), lay.docbookitemlabeltagtype()); } void closeLabelTag(XMLStream & xs, Layout const & lay) { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - xs << xml::EndTag(lay.docbookitemlabeltag()); - xs << xml::CR(); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + closeTag(xs, lay.docbookitemlabeltag(), lay.docbookitemlabeltagtype()); } void openItemTag(XMLStream & xs, Layout const & lay) { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - xs << xml::StartTag(lay.docbookitemtag(), lay.docbookitemattr()); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype()); } void closeItemTag(XMLStream & xs, Layout const & lay) { -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif - - xs << xml::EndTag(lay.docbookitemtag()); - xs << xml::CR(); - -#ifdef DOCBOOK_DEBUG_NEWLINES - xs << XMLStream::ESCAPE_NONE << ""; -#endif + closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype()); } diff --git a/src/xml.h b/src/xml.h index 581cca57a8..0948143c57 100644 --- a/src/xml.h +++ b/src/xml.h @@ -100,13 +100,13 @@ public: bool isTagPending(xml::StartTag const &, int maxdepth = -1) const; /// bool isLastTagCR() const { return is_last_tag_cr_; }; -private: - /// - void clearTagDeque(); /// void writeError(std::string const &) const; /// void writeError(docstring const &) const; +private: + /// + void clearTagDeque(); /// odocstream & os_; ///