Add required elements in the layouts to support DocBook.

Slightly modified patch from Thibaut Cuvelier.
This commit is contained in:
Pavel Sanda 2020-07-07 09:49:48 +02:00
parent 0bddf448ef
commit 28968b1f0d
16 changed files with 65 additions and 41 deletions

View File

@ -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

View File

@ -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

View File

@ -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";

View File

@ -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;

View File

@ -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");

View File

@ -34,7 +34,7 @@ public:
LUATEX,
PDFLATEX,
XETEX,
XML,
DOCBOOK5,
HTML,
TEXT,
LYX

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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_;

View File

@ -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"))
<< "\" />";

View File

@ -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;

View File

@ -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("\">");

View File

@ -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 << "\">";