From 2be72a1534af143bda34b382189198667c10136b Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Feb 2024 15:50:12 +0100 Subject: [PATCH] DocBook: in bibliographies, fix support for editors. Also, add TODOs for similar problems lurking around. --- autotests/export/docbook/basic.xml | 57 +++++++++++++++--------------- src/insets/InsetBibtex.cpp | 38 +++++++++++++++++++- 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml index b589ee63b9..87c951f359 100644 --- a/autotests/export/docbook/basic.xml +++ b/autotests/export/docbook/basic.xml @@ -1,7 +1,7 @@ -
+
I am a title @@ -24,43 +24,39 @@ - - - w - i - t - h - - a - - f - o - r - m - u - l - a - + + w + i + t + h + + a + + f + o + r + m + u + l + a . -Now, we're outside quotes. +Now, we’re outside quotes. Formula! - - F - o - r - m - u - l - a - ! - + F + o + r + m + u + l + a + ! @@ -420,6 +416,9 @@ I am no more code. + +The editor + An optional note diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index b073f619e6..6d38631f81 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -1128,6 +1128,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const make_pair("url", "uri") }; // Relations between documents. + // TODO: some elements should be mutually exclusive; right now, all of them are output. vector> relations = { // make_pair("journal", "journal"), make_pair("journaltitle", "journal"), @@ -1144,9 +1145,11 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const toDocBookTag["fullnames:author"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["publisher"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["address"] = "SPECIFIC"; // No direct translation to DocBook: . - toDocBookTag["editor"] = "editor"; + toDocBookTag["editor"] = "SPECIFIC"; // No direct translation to DocBook: . + toDocBookTag["fullbynames:editor"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["institution"] = "SPECIFIC"; // No direct translation to DocBook: . + // TODO: some elements should be mutually exclusive; right now, all of them are output. toDocBookTag["title"] = "title"; toDocBookTag["fulltitle"] = "title"; toDocBookTag["quotetitle"] = "title"; @@ -1159,6 +1162,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const toDocBookTag["year"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["month"] = "SPECIFIC"; // No direct translation to DocBook: . + // TODO: some elements should be mutually exclusive; right now, all of them are output. toDocBookTag["journal"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["journaltitle"] = "SPECIFIC"; // No direct translation to DocBook: . toDocBookTag["fulljournaltitle"] = "SPECIFIC"; // No direct translation to DocBook: . @@ -1359,6 +1363,38 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const eraseTag("fullnames:author"); } + // + // Example: http://tdg.docbook.org/tdg/5.1/editor.html + if (hasTag("editor") || hasTag("fullbynames:editor")) { + // If several editor tags are present, only output one. + const docstring editorName = getTag(hasTag("editor") ? "editor" : "fullbynames:editor"); + + // Arbitrarily decide that the editor is always a person. There is no reliable information in the input + // to make the distinction between a person () and an organisation (). + xs << xml::StartTag("editor"); + xs << xml::CR(); + xs << xml::StartTag("personname"); + xs << editorName; + xs << xml::EndTag("personname"); + xs << xml::CR(); + xs << xml::EndTag("editor"); + xs << xml::CR(); + + if (hasTag("editor") && hasTag("fullbynames:editor")) { + xs << XMLStream::ESCAPE_NONE << + from_utf8("\n"); + } + + // Erase all editor tags that might be present, even if only one is output. + if (hasTag("editor")) { + eraseTag("editor"); + } + if (hasTag("fullbynames:editor")) { + eraseTag("fullbynames:editor"); + } + } + // if (hasTag("abstract")) { // Split the paragraphs on new line.