From 85946aae2b94fedf5ce9bd35e91ba500986b5121 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 1 Aug 2020 00:02:36 +0200 Subject: [PATCH] DocBook: fix XML in comments (-- forbidden for some historical reason). --- autotests/export/docbook/deutsches_ert.lyx | 14 +++- autotests/export/docbook/deutsches_ert.xml | 2 +- src/insets/InsetERT.cpp | 14 ++-- src/xml.cpp | 80 +++++++++++----------- src/xml.h | 5 +- 5 files changed, 68 insertions(+), 47 deletions(-) diff --git a/autotests/export/docbook/deutsches_ert.lyx b/autotests/export/docbook/deutsches_ert.lyx index e9e692db33..be6e3358b9 100644 --- a/autotests/export/docbook/deutsches_ert.lyx +++ b/autotests/export/docbook/deutsches_ert.lyx @@ -200,7 +200,7 @@ LaTeX-Vorspann. Dies öffnet ein Editierfenster, in das Sie Ihre bevorzugten Befehle schreiben können. \begin_inset Foot -status collapsed +status open \begin_layout Plain Layout Das Editierverhalten in diesem Fenster ist spezifisch, also erwarten Sie @@ -256,6 +256,18 @@ begin{document} . Sollten Sie diese jemals bekommen, prüfen Sie Ihren Vorspann!. + +\begin_inset ERT +status open + +\begin_layout Plain Layout + +-- +\end_layout + +\end_inset + + \begin_inset CommandInset index_print LatexCommand printindex type "idx" diff --git a/autotests/export/docbook/deutsches_ert.xml b/autotests/export/docbook/deutsches_ert.xml index e5933aee0f..1d9b725e5f 100644 --- a/autotests/export/docbook/deutsches_ert.xml +++ b/autotests/export/docbook/deutsches_ert.xml @@ -10,7 +10,7 @@ Einleitung Wählen Sie hierfür Dokument⇒Einstellungen⇒LaTeX-Vorspann. Dies öffnet ein Editierfenster, in das Sie Ihre bevorzugten Befehle schreiben können.Das Editierverhalten in diesem Fenster ist spezifisch, also erwarten Sie nicht, dass die LyXTastenkombinationen darin funktionieren. - LyX fügt alles im LaTeX-Vorspann-Fenster zu seinem eingebauten Vorspann hinzu. Bevor Sie Ihre eigenen Deklarationen zum Vorspann hinzufügen, sollten Sie prüfen, ob LyX das nicht bereits unterstützt (Erinnern Sie sich, was wir über das Rad noch einmal erfinden sagten?). Außerdem: stellen Sie sicher, dass Ihre Vorspannzeilen richtig sind. LyX prüft das nicht. Wenn der Vorspann fehlerhaft ist, bekommen Sie sehr wahrscheinlich die Fehlermeldung Missing \begin{document}. Sollten Sie diese jemals bekommen, prüfen Sie Ihren Vorspann!. + LyX fügt alles im LaTeX-Vorspann-Fenster zu seinem eingebauten Vorspann hinzu. Bevor Sie Ihre eigenen Deklarationen zum Vorspann hinzufügen, sollten Sie prüfen, ob LyX das nicht bereits unterstützt (Erinnern Sie sich, was wir über das Rad noch einmal erfinden sagten?). Außerdem: stellen Sie sicher, dass Ihre Vorspannzeilen richtig sind. LyX prüft das nicht. Wenn der Vorspann fehlerhaft ist, bekommen Sie sehr wahrscheinlich die Fehlermeldung Missing \begin{document}. Sollten Sie diese jemals bekommen, prüfen Sie Ihren Vorspann!. \ No newline at end of file diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index 57fc1e3419..a023f7a464 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -98,17 +98,23 @@ void InsetERT::docbook(XMLStream & xs, OutputParams const & runparams) const auto par = begin; auto const end = paragraphs().end(); - xs << XMLStream::ESCAPE_NONE << ""; } diff --git a/src/xml.cpp b/src/xml.cpp index 3864a3f400..0816bf8918 100644 --- a/src/xml.cpp +++ b/src/xml.cpp @@ -44,40 +44,30 @@ docstring escapeChar(char_type c, XMLStream::EscapeSettings e) { docstring str; switch (e) { // For HTML: always ESCAPE_NONE. For XML: it depends, hence the parameter. - case XMLStream::ESCAPE_NONE: - str += c; + case XMLStream::ESCAPE_NONE: + case XMLStream::ESCAPE_COMMENTS: + str += c; + break; + case XMLStream::ESCAPE_ALL: + if (c == '<') { + str += "<"; break; - case XMLStream::ESCAPE_ALL: - if (c == '<') { - str += "<"; - break; - } else if (c == '>') { - str += ">"; - break; - } - // fall through - case XMLStream::ESCAPE_AND: - if (c == '&') - str += "&"; - else - str +=c ; + } else if (c == '>') { + str += ">"; break; + } + // fall through + case XMLStream::ESCAPE_AND: + if (c == '&') + str += "&"; + else + str +=c ; + break; } return str; } -// escape what needs escaping -docstring xmlize(docstring const &str, XMLStream::EscapeSettings e) { - odocstringstream d; - docstring::const_iterator it = str.begin(); - docstring::const_iterator en = str.end(); - for (; it != en; ++it) - d << escapeChar(*it, e); - return d.str(); -} - - docstring escapeChar(char c, XMLStream::EscapeSettings e) { LATTEST(static_cast(c) < 0x80); @@ -85,6 +75,29 @@ docstring escapeChar(char c, XMLStream::EscapeSettings e) } +docstring xml::escapeString(docstring const & raw, XMLStream::EscapeSettings e) +{ + docstring bin; + bin.reserve(raw.size() * 2); // crude approximation is sufficient + for (size_t i = 0; i != raw.size(); ++i) { + char_type c = raw[i]; + if (e == XMLStream::ESCAPE_COMMENTS && c == '-' && i > 0 && raw[i - 1] == '-') + bin += "-"; + else + bin += xml::escapeChar(c, e); + } + + return bin; +} + + +// escape what needs escaping +docstring xmlize(docstring const &str, XMLStream::EscapeSettings e) +{ + return xml::escapeString(str, e); +} + + docstring cleanAttr(docstring const & str) { docstring newname; @@ -567,18 +580,7 @@ XMLStream &XMLStream::operator<<(xml::EndTag const &etag) } -docstring xml::escapeString(docstring const & raw, XMLStream::EscapeSettings e) -{ - docstring bin; - bin.reserve(raw.size() * 2); // crude approximation is sufficient - for (size_t i = 0; i != raw.size(); ++i) - bin += xml::escapeChar(raw[i], e); - - return bin; -} - - -docstring const xml::uniqueID(docstring const & label) +docstring xml::uniqueID(docstring const & label) { // thread-safe static atomic_uint seed(1000); diff --git a/src/xml.h b/src/xml.h index 5478a66361..5afdcf53e9 100644 --- a/src/xml.h +++ b/src/xml.h @@ -82,7 +82,8 @@ public: enum EscapeSettings { ESCAPE_NONE, ESCAPE_AND, // meaning & - ESCAPE_ALL // meaning <, >, &, at present + ESCAPE_ALL, // meaning <, >, &, at present + ESCAPE_COMMENTS // Anything that is forbidden within comments }; /// Sets what we are going to escape on the NEXT write. /// Everything is reset for the next time. @@ -151,7 +152,7 @@ docstring escapeChar(char c, XMLStream::EscapeSettings e); docstring cleanID(docstring const &orig); /// returns a unique numeric ID -docstring const uniqueID(docstring const & label); +docstring uniqueID(docstring const & label); struct FontTag; struct EndFontTag; -- 2.39.2