From 28968b1f0de85aae1a8b11ffc9e6e872abcc8fa4 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Tue, 7 Jul 2020 09:49:48 +0200 Subject: [PATCH] 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 a8c1451d40..60d4593482 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/Buffer.cpp b/src/Buffer.cpp index 03368dc876..eb2a4ef6d1 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 << "\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 += "\n"; preamble += "\n"; preamble += "\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 << "\n"; diff --git a/src/Converter.cpp b/src/Converter.cpp index 3487f4b45e..5de38b6cca 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 ee4f7f464b..bdedcac14f 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 177832178a..f26aa52263 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 f5abd44f85..313be9d88c 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 2630670bb9..a5cc9d4a3e 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 << "" ; else os << " format=\"" << format << "\">" ; os << ""; - 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 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 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 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 << ""; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index e007e59174..fb9f64a7d2 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 2dcd43af78..d9f314b3c7 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 9eaad0c033..3e1bc0290a 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 << ""; else os << "\">";