[LyX/master] Add required elements in the layouts to support DocBook.
Pavel Sanda
sanda at lyx.org
Tue Jul 7 07:36:42 UTC 2020
commit 28968b1f0de85aae1a8b11ffc9e6e872abcc8fa4
Author: Pavel Sanda <sanda at lyx.org>
Date: Tue Jul 7 09:49:48 2020 +0200
Add required elements in the layouts to support DocBook.
Slightly modified patch from Thibaut Cuvelier.
---
lib/scripts/layout2layout.py | 30 +++++++++++++++++++++++++++---
lib/ui/stdmenus.inc | 1 -
src/Buffer.cpp | 10 +++++-----
src/Converter.cpp | 2 +-
src/Format.cpp | 2 +-
src/OutputParams.h | 2 +-
src/Text3.cpp | 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/mathed/InsetMathHull.cpp | 4 ++--
src/mathed/InsetMathRef.cpp | 2 +-
16 files changed, 65 insertions(+), 41 deletions(-)
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index a8c1451..60d4593 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 4a4aa4e..e958178 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/Buffer.cpp b/src/Buffer.cpp
index 03368dc..eb2a4ef 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -2141,7 +2141,7 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const &
output == FullSource || output == OnlyBody;
if (output_preamble) {
- if (runparams.flavor == OutputParams::XML)
+ if (runparams.flavor == OutputParams::DOCBOOK5)
os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
// FIXME UNICODE
@@ -2150,14 +2150,14 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const &
// FIXME UNICODE
if (! tclass.class_header().empty())
os << from_ascii(tclass.class_header());
- else if (runparams.flavor == OutputParams::XML)
+ else if (runparams.flavor == OutputParams::DOCBOOK5)
os << "PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\" "
<< "\"https://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\"";
else
os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
docstring preamble = params().preamble;
- if (runparams.flavor != OutputParams::XML ) {
+ if (runparams.flavor != OutputParams::DOCBOOK5 ) {
preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
preamble += "<!ENTITY % output.print.eps \"IGNORE\">\n";
@@ -2178,7 +2178,7 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const &
if (output_body) {
string top = top_element;
top += " lang=\"";
- if (runparams.flavor == OutputParams::XML)
+ if (runparams.flavor == OutputParams::DOCBOOK5)
top += params().language->code();
else
top += params().language->code().substr(0, 2);
@@ -2189,7 +2189,7 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const &
top += params().options;
}
- os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML")
+ os << "<!-- " << ((runparams.flavor == OutputParams::DOCBOOK5)? "XML" : "SGML")
<< " file was created by LyX " << lyx_version
<< "\n See https://www.lyx.org/ for more information -->\n";
diff --git a/src/Converter.cpp b/src/Converter.cpp
index 3487f4b..5de38b6 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -277,7 +277,7 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path,
return OutputParams::PDFLATEX;
}
if (conv.xml())
- return OutputParams::XML;
+ return OutputParams::DOCBOOK5;
}
return buffer ? buffer->params().getOutputFlavor()
: OutputParams::LATEX;
diff --git a/src/Format.cpp b/src/Format.cpp
index ee4f7f4..bdedcac 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -827,7 +827,7 @@ FlavorTranslator initFlavorTranslator()
f.addPair(OutputParams::LUATEX, "luatex");
f.addPair(OutputParams::PDFLATEX, "pdflatex");
f.addPair(OutputParams::XETEX, "xetex");
- f.addPair(OutputParams::XML, "docbook-xml");
+ f.addPair(OutputParams::DOCBOOK5, "docbook-xml");
f.addPair(OutputParams::HTML, "xhtml");
f.addPair(OutputParams::TEXT, "text");
f.addPair(OutputParams::LYX, "lyx");
diff --git a/src/OutputParams.h b/src/OutputParams.h
index 1778321..f26aa52 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -34,7 +34,7 @@ public:
LUATEX,
PDFLATEX,
XETEX,
- XML,
+ DOCBOOK5,
HTML,
TEXT,
LYX
diff --git a/src/Text3.cpp b/src/Text3.cpp
index f5abd44..313be9d 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -3065,7 +3065,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
if (il.lyxtype() != InsetLayout::CHARSTYLE &&
il.lyxtype() != InsetLayout::CUSTOM &&
- il.lyxtype() != InsetLayout::ELEMENT &&
il.lyxtype ()!= InsetLayout::STANDARD)
enable = false;
break;
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index 2630670..a5cc9d4 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 7fd96cb..8531e56 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 68bf2c1..0daae4c 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 7bb8b17..ce0d25a 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 3bab0a4..00e3ba6 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 ac4a3a9..d4cdaac 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 e007e59..fb9f64a 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/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 2dcd43a..d9f314b 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2431,7 +2431,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
odocstringstream ls;
otexstream ols(ls);
- if (runparams.flavor == OutputParams::XML) {
+ if (runparams.flavor == OutputParams::DOCBOOK5) {
ms << MTag("alt role='tex' ");
// Workaround for db2latex: db2latex always includes equations with
// \ensuremath{} or \begin{display}\end{display}
@@ -2459,7 +2459,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
else
ms << xml::uniqueID(from_ascii("anon"));
- if (runparams.flavor == OutputParams::XML)
+ if (runparams.flavor == OutputParams::DOCBOOK5)
ms << from_ascii("\"/>");
else
ms << from_ascii("\">");
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index 9eaad0c..3e1bc02 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -187,7 +187,7 @@ int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
if (cell(1).empty()) {
os << "<xref linkend=\""
<< xml::cleanID(asString(cell(0)));
- if (runparams.flavor == OutputParams::XML)
+ if (runparams.flavor == OutputParams::DOCBOOK5)
os << "\"/>";
else
os << "\">";
More information about the lyx-cvs
mailing list