From 4405f0164a7a2596f76f6c3c8462b4be1cca910a Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 25 Oct 2020 15:38:08 +0100 Subject: [PATCH] DocBook: implement algorithm floats. Now that https://github.com/docbook/docbook/pull/185 has been merged into DocBook 5.2. --- src/Floating.cpp | 25 +++++++++---------------- src/Floating.h | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Floating.cpp b/src/Floating.cpp index 6ae52b4d22..ff1667f5e7 100644 --- a/src/Floating.cpp +++ b/src/Floating.cpp @@ -52,8 +52,6 @@ std::string Floating::docbookFloatType() const } else if (floattype_ == "table" || floattype_ == "tableau") { return "table"; } else if (floattype_ == "algorithm") { - // TODO: no good translation for now! Figures are the closest match, as they can contain text. - // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer. return "algorithm"; } else { // If nothing matches, return something that will not be valid. @@ -101,23 +99,23 @@ string Floating::defaultCSSClass() const } -string const & Floating::docbookAttr() const +string Floating::docbookAttr() const { - return docbook_attr_; + // For algorithms, a type attribute must be mentioned, if not already present in docbook_attr_. + if (docbookFloatType() == "algorithm" && docbook_attr_.find("type=") != std::string::npos) + return docbook_attr_ + " type='algorithm'"; + else + return docbook_attr_; } string Floating::docbookTag(bool hasTitle) const { // TODO: configure this in the layouts? - if (docbookFloatType() == "figure") { + if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm") { return hasTitle ? "figure" : "informalfigure"; } else if (docbookFloatType() == "table") { return hasTitle ? "table" : "informaltable"; - } else if (docbookFloatType() == "algorithm") { - // TODO: no good translation for now! Figures are the closest match, as they can contain text. - // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer. - return "figure"; } else { // If nothing matches, return something that will not be valid. LYXERR0("Unrecognised float type: " + floattype()); @@ -137,15 +135,10 @@ string const & Floating::docbookTagType() const string const & Floating::docbookCaption() const { docbook_caption_ = ""; - if (floattype_ == "figure") { + if (floattype_ == "figure" || floattype_ == "algorithm") docbook_caption_ = "title"; - } else if (floattype_ == "table" || floattype_ == "tableau") { + else if (floattype_ == "table" || floattype_ == "tableau") docbook_caption_ = "caption"; - } else if (floattype_ == "algorithm") { - // TODO: no good translation for now! Figures are the closest match, as they can contain text. - // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer. - docbook_caption_ = "title"; - } return docbook_caption_; } diff --git a/src/Floating.h b/src/Floating.h index 0a2eb50bc9..a6f2ec3431 100644 --- a/src/Floating.h +++ b/src/Floating.h @@ -85,7 +85,7 @@ public: /// std::string docbookTag(bool hasTitle = false) const; /// - std::string const & docbookAttr() const; + std::string docbookAttr() const; /// std::string const & docbookTagType() const; /// -- 2.39.5