commit 85946aae2b94fedf5ce9bd35e91ba500986b5121
Author: Thibaut Cuvelier <[email protected]>
Date: Sat Aug 1 00:02:36 2020 +0200
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 e9e692d..be6e335 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 e5933ae..1d9b725 100644
--- a/autotests/export/docbook/deutsches_ert.xml
+++ b/autotests/export/docbook/deutsches_ert.xml
@@ -10,7 +10,7 @@
<chapter>
<chapter>Einleitung</chapter>
<para>Wählen Sie hierfür <emphasis
role='sans'>Dokument⇒Einstellungen⇒LaTeX-Vorspann. Dies öffnet
ein Editierfenster, in das Sie Ihre bevorzugten Befehle schreiben
können.<footnote><para>Das Editierverhalten in diesem Fenster ist spezifisch,
also erwarten Sie nicht, dass die LyX<!-- „= -->Tastenkombinationen darin
funktionieren.</para>
-</footnote> LyX fügt alles im <emphasis role='sans'>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: <emphasis>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!.</emphasis></emphasis></emphasis></para>
+</footnote> LyX fügt alles im <emphasis role='sans'>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: <emphasis>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!. <!-- --
--></emphasis></emphasis></emphasis></para>
</chapter>
</book>
\ No newline at end of file
diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp
index 57fc1e3..a023f7a 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 << "<!-- ";
+ odocstringstream os2;
+ XMLStream xs2(os2);
+
+ // Recreate the logic of makeParagraphs in output_docbook.cpp, but much
simplified: never open <para>
+ // in an ERT, use simple line breaks.
while (par != end) {
- // Recreate the logic of makeParagraphs in output_docbook.cpp,
but much simplified: never open <para>
- // in an ERT, use simple line breaks.
- par->simpleDocBookOnePar(buffer(), xs, runparams,
text().outerFont(distance(begin, par)));
+ par->simpleDocBookOnePar(buffer(), xs2, runparams,
text().outerFont(distance(begin, par)));
// New line after each paragraph of the ERT, save the last one.
++par;
if (par != end)
xs << "\n";
}
+
+ // Output the ERT as a comment with the appropriate escaping.
+ xs << XMLStream::ESCAPE_NONE << "<!-- ";
+ xs << XMLStream::ESCAPE_COMMENTS << os2.str();
xs << XMLStream::ESCAPE_NONE << " -->";
}
diff --git a/src/xml.cpp b/src/xml.cpp
index 3864a3f..0816bf8 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<unsigned char>(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 5478a66..5afdcf5 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;
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs