From 3aaa2f742bc05fd6acac5431553141d7b470b1e6 Mon Sep 17 00:00:00 2001
From: Thibaut Cuvelier <cuvelier.thibaut@gmail.com>
Date: Mon, 8 Jun 2020 23:27:01 +0200
Subject: [PATCH 4/9] Add required elements in the layouts to support DocBook.

---
 development/FORMAT           |  4 ++++
 lib/lyx2lyx/lyx_2_4.py       | 12 ++++++++++--
 lib/scripts/layout2layout.py | 30 +++++++++++++++++++++++++++---
 lib/ui/stdmenus.inc          |  1 -
 src/frontends/qt/Menus.cpp   | 13 -------------
 src/insets/InsetExternal.cpp |  2 +-
 src/insets/InsetGraphics.cpp | 10 +++++-----
 src/insets/InsetLayout.cpp   | 12 ++++++++++--
 src/insets/InsetLayout.h     | 11 +++++++++--
 src/insets/InsetRef.cpp      |  2 +-
 src/insets/InsetTabular.cpp  |  2 +-
 src/version.h                |  4 ++--
 12 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index f903ed3ae9..227162a169 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2017-06-04 Thibaut Cuvelier <cuvelier.thibaut@gmail.com>
+ 	* Format incremented to 595: Remove the \outputformat docbook option, as DocBook support is
+          now enabled for all documents.
+
 2020-03-13 Jürgen Spitzmüller <spitz@lyx.org>
  	* Format incremented to 593: Buffer param \maintain_unincluded_children is not longer a bool
           (true|false) but has three states: "no" (formerly "false"), "strict" (formerly "true") and
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py
index 206365185e..b6448f6183 100644
--- a/lib/lyx2lyx/lyx_2_4.py
+++ b/lib/lyx2lyx/lyx_2_4.py
@@ -3753,7 +3753,14 @@ def revert_counter_inset(document):
     if pretext:
         add_to_preamble(document, pretext)
 
-        
+
+def convert_docbook(document):
+    """Remove the DocBook output format"""
+    i = find_token(document.header, "\\outputformat docbook", 0)
+    if i != -1:
+        document.header.pop(i)
+
+
 ##
 # Conversion hub
 #
@@ -3809,7 +3816,8 @@ convert = [
            [591, [convert_postpone_fragile]],
            [592, []],
            [593, [convert_counter_maintenance]],
-           [594, []]
+           [594, []],
+           [595, [convert_docbook]],
           ]
 
 revert =  [[593, [revert_counter_inset]],
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index a8c1451d40..4909a1ec78 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 = 81
+currentFormat = 82
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -268,9 +268,19 @@ currentFormat = 81
 # Incremented to format 80, 12 August 2019 by spitz
 # New float option Requires
 
-# Incremented to format 80, 12 August 2019 by rikiheck
+# Incremented to format 81, 12 August 2019 by rikiheck
 # New tag GuiName for counters
 
+# Incremented to format 82, 4 June 2017 by dourouc05
+# - Add new tags for Layout:
+#   DocBookTag, DocBookAttr, DocBookInInfo,
+#   DocBookWrapperTag, DocBookWrapperAttr,
+#   DocBookItemWrapperTag, DocBookItemWrapperAttr,
+#   DocBookItemTag, DocBookItemAttr,
+#   DocBookLabelTag, DocBookLabelAttr
+# - Removed tag Header from ClassOptionsClassOptions
+# - Removed tag Element for flex insets
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -520,7 +530,21 @@ def convert(lines, end_format):
                 i += 1
             continue
 
-        if format >= 65 and format <= 80:
+        if format == 81:
+            match = re.compile(b'(\\s*Header\\s+)(\\w+)', re.IGNORECASE).match(lines[i])
+            if match:
+                del lines[i]
+                continue
+
+            match = re.compile(b'(\\s*LyXType\\s+)(\\w+)(\\s*Element\\s+)', re.IGNORECASE).match(lines[i])
+            if match:
+                del lines[i]
+                continue
+
+            i += 1
+            continue
+
+        if 65 <= format <= 80:
             # nothing to do.
             i += 1
             continue
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index 4a4aa4e886..e958178a7e 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -194,7 +194,6 @@ Menuset
 	Menu "edit_textstyles"
 		OptItem "Dissolve Text Style" "inset-dissolve charstyle"
 		CharStyles
-		Elements
 	End
 
 # not much we can do to help here
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index cb30e07536..ddd73bf562 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -148,9 +148,6 @@ public:
 		/** This is the list of user-configurable
 		insets to insert into document */
 		Custom,
-		/** This is the list of XML elements to
-		insert into the document */
-		Elements,
 		/** This is the list of floats that we can
 		    insert a list for. */
 		FloatListInsert,
@@ -461,7 +458,6 @@ void MenuDefinition::read(Lexer & lex)
 		md_bookmarks,
 		md_charstyles,
 		md_custom,
-		md_elements,
 		md_endmenu,
 		md_exportformat,
 		md_exportformats,
@@ -504,7 +500,6 @@ void MenuDefinition::read(Lexer & lex)
 		{ "citestyles", md_citestyles },
 		{ "custom", md_custom },
 		{ "documents", md_documents },
-		{ "elements", md_elements },
 		{ "end", md_endmenu },
 		{ "environmentseparators", md_env_separators },
 		{ "environmentseparatorscontext", md_env_separatorscontext },
@@ -574,10 +569,6 @@ void MenuDefinition::read(Lexer & lex)
 			add(MenuItem(MenuItem::Custom));
 			break;
 
-		case md_elements:
-			add(MenuItem(MenuItem::Elements));
-			break;
-
 		case md_documents:
 			add(MenuItem(MenuItem::Documents));
 			break;
@@ -2329,10 +2320,6 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
 			tomenu.expandFlexInsert(buf, InsetLayout::CUSTOM);
 			break;
 
-		case MenuItem::Elements:
-			tomenu.expandFlexInsert(buf, InsetLayout::ELEMENT);
-			break;
-
 		case MenuItem::FloatListInsert:
 			tomenu.expandFloatListInsert(buf);
 			break;
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index 7fd96cbb1d..8531e56694 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -832,7 +832,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const
 	case OutputParams::XETEX:
 		format = "PDFLaTeX";
 		break;
-	case OutputParams::XML:
+	case OutputParams::DOCBOOK5:
 		format = "DocBook";
 		break;
 	case OutputParams::HTML:
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index 68bf2c13f3..0daae4c921 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -939,7 +939,7 @@ static int writeImageObject(char const * format, odocstream & os,
 	OutputParams const & runparams, docstring const & graphic_label,
 	docstring const & attributes)
 {
-	if (runparams.flavor != OutputParams::XML)
+	if (runparams.flavor != OutputParams::DOCBOOK5)
 		os << "<![ %output.print." << format
 		   << "; [" << endl;
 
@@ -950,17 +950,17 @@ static int writeImageObject(char const * format, odocstream & os,
 	   << "\" "
 	   << attributes;
 
-	if (runparams.flavor == OutputParams::XML)
+	if (runparams.flavor == OutputParams::DOCBOOK5)
 		os <<  " role=\"" << format << "\"/>" ;
 	else
 		os << " format=\"" << format << "\">" ;
 
 	os << "</imageobject>";
 
-	if (runparams.flavor != OutputParams::XML)
+	if (runparams.flavor != OutputParams::DOCBOOK5)
 		os << endl << "]]>" ;
 
-	return runparams.flavor == OutputParams::XML ? 0 : 2;
+	return runparams.flavor == OutputParams::DOCBOOK5 ? 0 : 2;
 }
 
 
@@ -973,7 +973,7 @@ int InsetGraphics::docbook(odocstream & os,
 	// In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
 	// need to switch to MediaObject. However, for now this is sufficient and
 	// easier to use.
-	if (runparams.flavor == OutputParams::XML)
+	if (runparams.flavor == OutputParams::DOCBOOK5)
 		runparams.exportdata->addExternalFile("docbook-xml",
 						      params().filename);
 	else
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 7bb8b175f1..ce0d25a13a 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -109,6 +109,8 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		IL_HTMLLABEL,
 		IL_HTMLSTYLE,
 		IL_HTMLPREAMBLE,
+		IL_DOCBOOKTAG,
+		IL_DOCBOOKATTR,
 		IL_INTOC,
 		IL_ISTOCCAPTION,
 		IL_LABELFONT,
@@ -153,6 +155,8 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		{ "custompars", IL_CUSTOMPARS },
 		{ "decoration", IL_DECORATION },
 		{ "display", IL_DISPLAY },
+		{ "docbookattr", IL_DOCBOOKATTR },
+		{ "docbooktag", IL_DOCBOOKTAG },
 		{ "editexternal", IL_EDITEXTERNAL },
 		{ "end", IL_END },
 		{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
@@ -493,6 +497,12 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		case IL_HTMLPREAMBLE:
 			htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
 			break;
+		case IL_DOCBOOKTAG:
+			lex >> docbooktag_;
+			break;
+		case IL_DOCBOOKATTR:
+			lex >> docbookattr_;
+			break;
 		case IL_REQUIRES: {
 			lex.eatLine();
 			vector<string> const req
@@ -544,8 +554,6 @@ InsetLayout::InsetLyXType translateLyXType(std::string const & str)
 		return InsetLayout::CHARSTYLE;
 	if (compare_ascii_no_case(str, "custom") == 0)
 		return InsetLayout::CUSTOM;
-	if (compare_ascii_no_case(str, "element") == 0)
-		return InsetLayout::ELEMENT;
 	if (compare_ascii_no_case(str, "end") == 0)
 		return InsetLayout::END;
 	if (compare_ascii_no_case(str, "standard") == 0)
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index 3bab0a4898..00e3ba64d7 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -44,7 +44,6 @@ public:
 		NOLYXTYPE,
 		CHARSTYLE,
 		CUSTOM,
-		ELEMENT,
 		END,
 		STANDARD
 	};
@@ -149,6 +148,10 @@ public:
 	/// Defaults to true.
 	bool htmlisblock() const { return htmlisblock_; }
 	///
+	std::string docbooktag() const { return docbooktag_; }
+	///
+	std::string docbookattr() const { return docbookattr_; }
+	///
 	std::set<std::string> required() const { return required_; }
 	///
 	bool isMultiPar() const { return multipar_; }
@@ -213,7 +216,7 @@ private:
 	/**
 		* This is only used (at present) to decide where to put them on the menus.
 		* Values are 'charstyle', 'custom' (things that by default look like a
-		* footnote), 'element' (docbook), 'standard'.
+		* footnote), 'standard'.
 		*/
 	InsetLyXType lyxtype_;
 	///
@@ -276,6 +279,10 @@ private:
 	///
 	bool htmlisblock_;
 	///
+	std::string docbooktag_;
+	///
+	std::string docbookattr_;
+	///
 	std::set<std::string> required_;
 	///
 	bool multipar_;
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index ac4a3a93d7..d4cdaac30c 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -313,7 +313,7 @@ int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const
 {
 	docstring const & name = getParam("name");
 	if (name.empty()) {
-		if (runparams.flavor == OutputParams::XML) {
+		if (runparams.flavor == OutputParams::DOCBOOK5) {
 			os << "<xref linkend=\""
 			   << xml::cleanID(getParam("reference"))
 			   << "\" />";
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index a0a86f54a5..7e635c4138 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -3575,7 +3575,7 @@ int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
 			break;
 		}
 		os << '"';
-		if (runparams.flavor == OutputParams::XML)
+		if (runparams.flavor == OutputParams::DOCBOOK5)
 			os << '/';
 		os << ">\n";
 		++ret;
diff --git a/src/version.h b/src/version.h
index 866fe10e95..6143e9360c 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 594 // rikiheck: counter insets
-#define LYX_FORMAT_TEX2LYX 594
+#define LYX_FORMAT_LYX 595 // dourouc05: improved DocBook support
+#define LYX_FORMAT_TEX2LYX 595
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER
-- 
2.26.1.windows.1

