From 0bd2978ac99d894ea876d38336192246537a0594 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Wed, 7 Oct 2020 06:05:22 +0200 Subject: [PATCH] DocBook: add DocBookInnerTag and family. This allows old DocBook documents to be valid when output. --- autotests/export/docbook/olddb_article.xml | 2 +- autotests/export/docbook/olddb_book.xml | 2 +- lib/layouts/db_stdtitle.inc | 2 + lib/scripts/layout2layout.py | 7 +++- src/Layout.cpp | 46 ++++++++++++++++++++++ src/Layout.h | 12 ++++++ src/TextClass.cpp | 2 +- src/output_docbook.cpp | 5 ++- 8 files changed, 72 insertions(+), 6 deletions(-) diff --git a/autotests/export/docbook/olddb_article.xml b/autotests/export/docbook/olddb_article.xml index 8ebaba6ff7..cf592a35f9 100644 --- a/autotests/export/docbook/olddb_article.xml +++ b/autotests/export/docbook/olddb_article.xml @@ -8,7 +8,7 @@ Article author -Article author group +Article author group Article date diff --git a/autotests/export/docbook/olddb_book.xml b/autotests/export/docbook/olddb_book.xml index 71befec57f..aa0e3bf87b 100644 --- a/autotests/export/docbook/olddb_book.xml +++ b/autotests/export/docbook/olddb_book.xml @@ -8,7 +8,7 @@ Book author -Book author group +Book author group Book date diff --git a/lib/layouts/db_stdtitle.inc b/lib/layouts/db_stdtitle.inc index 9adc1bb1ae..7943de8b05 100644 --- a/lib/layouts/db_stdtitle.inc +++ b/lib/layouts/db_stdtitle.inc @@ -17,6 +17,8 @@ Style Authorgroup # TODO: missing a DocBookInnerTag to be valid (authorgroup > author > personname). DocBookTag author DocBookTagType paragraph + DocBookInnerTag personname + DocBookInnerTagType inline DocBookWrapperTag authorgroup DocBookWrapperTagType paragraph End diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index fd0c193dd6..9da2572d50 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -11,7 +11,7 @@ # This script will update a .layout file to current format # The latest layout format is also defined in src/TextClass.cpp -currentFormat = 84 +currentFormat = 85 # Incremented to format 4, 6 April 2007, lasgouttes @@ -289,6 +289,9 @@ currentFormat = 84 # DocBookItemWrapperTagTagType, DocBookItemTagTagType, # DocBookLabelTag +# Incremented to format 85, 7 October 2020 by tcuvelier +# New tags DocBookInnerTag, DocBookInnerAttr, +# DocBookInnerTagType # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -538,7 +541,7 @@ def convert(lines, end_format): i += 1 continue - if 82 <= format <= 84: + if 82 <= format <= 85: # nothing to do. i += 1 continue diff --git a/src/Layout.cpp b/src/Layout.cpp index 01c4f16286..8dec223c8c 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -107,6 +107,9 @@ enum LayoutTags { LT_DOCBOOKTAG, LT_DOCBOOKATTR, LT_DOCBOOKTAGTYPE, + LT_DOCBOOKINNERATTR, + LT_DOCBOOKINNERTAG, + LT_DOCBOOKINNERTAGTYPE, LT_DOCBOOKININFO, LT_DOCBOOKABSTRACT, LT_DOCBOOKWRAPPERTAG, @@ -234,6 +237,9 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, { "docbookattr", LT_DOCBOOKATTR }, { "docbookforceabstracttag", LT_DOCBOOKFORCEABSTRACTTAG }, { "docbookininfo", LT_DOCBOOKININFO }, + { "docbookinnerattr", LT_DOCBOOKINNERATTR }, + { "docbookinnertag", LT_DOCBOOKINNERTAG }, + { "docbookinnertagtype", LT_DOCBOOKINNERTAGTYPE }, { "docbookitemattr", LT_DOCBOOKITEMATTR }, { "docbookiteminnerattr", LT_DOCBOOKITEMINNERATTR }, { "docbookiteminnertag", LT_DOCBOOKITEMINNERTAG }, @@ -750,6 +756,18 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass, lex >> docbooktagtype_; break; + case LT_DOCBOOKINNERTAG: + lex >> docbookinnertag_; + break; + + case LT_DOCBOOKINNERATTR: + lex >> docbookinnerattr_; + break; + + case LT_DOCBOOKINNERTAGTYPE: + lex >> docbookinnertagtype_; + break; + case LT_DOCBOOKFORCEABSTRACTTAG: lex >> docbookforceabstracttag_; break; @@ -1638,6 +1656,12 @@ void Layout::write(ostream & os) const os << "\tDocBookAttr \"" << docbookattr_ << "\"\n"; if(!docbooktagtype_.empty()) os << "\tDocBookTagType " << docbooktagtype_ << '\n'; + if(!docbookinnertag_.empty()) + os << "\tDocBookInnerTag " << docbookinnertag_ << '\n'; + if(!docbookinnerattr_.empty()) + os << "\tDocBookInnerAttr \"" << docbookinnerattr_ << "\"\n"; + if(!docbookinnertagtype_.empty()) + os << "\tDocBookInnerTagType " << docbookinnertagtype_ << '\n'; if(!docbookininfo_.empty()) os << "\tDocBookInInfo " << docbookininfo_ << '\n'; os << "\tDocBookAbstract " << docbookabstract_ << '\n'; @@ -1857,6 +1881,28 @@ string const & Layout::docbooktagtype() const } +string const & Layout::docbookinnertag() const +{ + if (docbookinnertag_.empty()) + docbookinnertag_ = "NONE"; + return docbookinnertag_; +} + + +string const & Layout::docbookinnerattr() const +{ + return docbookinnerattr_; +} + + +string const & Layout::docbookinnertagtype() const +{ + if (!isValidTagType(docbookinnertagtype_)) + docbookinnertagtype_ = "block"; + return docbookinnertagtype_; +} + + string const & Layout::docbookininfo() const { // Indeed, a trilean. Only titles should be "maybe": otherwise, metadata is "always", content is "never". diff --git a/src/Layout.h b/src/Layout.h index a3390219fa..63184cd849 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -199,6 +199,12 @@ public: /// std::string const & docbooktagtype() const; /// + std::string const & docbookinnertag() const; + /// + std::string const & docbookinnerattr() const; + /// + std::string const & docbookinnertagtype() const; + /// std::string const & docbookininfo() const; /// bool docbookabstract() const { return docbookabstract_; } @@ -509,6 +515,12 @@ private: mutable std::string docbookattr_; /// DocBook tag type corresponding to this layout (block, paragraph, or inline; default: block). mutable std::string docbooktagtype_; + /// DocBook inner tag corresponding to this layout. + mutable std::string docbookinnertag_; + /// Roles to add to docbookinnertag_, if any (default: none). + mutable std::string docbookinnerattr_; + /// DocBook inner-tag type corresponding to this layout (block, paragraph, or inline; default: block). + mutable std::string docbookinnertagtype_; /// DocBook tag corresponding to this item (mainly for lists). mutable std::string docbookitemtag_; /// Roles to add to docbookitemtag_, if any (default: none). diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 3628872ae3..03a7624a9a 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -62,7 +62,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 84; // tcuvelier: DocBook*TagType. +int const LAYOUT_FORMAT = 85; // tcuvelier: DocBookInnerTag. // Layout format for the current lyx file format. Controls which format is diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index 0d0aa108d0..a8d509adb7 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -309,10 +309,12 @@ void openParTag(XMLStream & xs, const Paragraph * par, const Paragraph * prevpar 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. + 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()); + openTag(xs, lay.docbookinnertag(), lay.docbookinnerattr(), lay.docbookinnertagtype()); + } } openTag(xs, lay.docbookitemtag(), lay.docbookitemattr(), lay.docbookitemtagtype()); @@ -342,6 +344,7 @@ void closeParTag(XMLStream & xs, Paragraph const * par, Paragraph const * nextpa // Main logic. closeTag(xs, lay.docbookiteminnertag(), lay.docbookiteminnertagtype()); closeTag(xs, lay.docbookitemtag(), lay.docbookitemtagtype()); + closeTag(xs, lay.docbookinnertag(), lay.docbookinnertagtype()); closeTag(xs, lay.docbooktag(), lay.docbooktagtype()); if (closeWrapper) closeTag(xs, lay.docbookwrappertag(), lay.docbookwrappertagtype());