]> git.lyx.org Git - features.git/commitdiff
DocBook: fix XML in comments (-- forbidden for some historical reason).
authorThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 31 Jul 2020 22:02:36 +0000 (00:02 +0200)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 31 Jul 2020 22:02:36 +0000 (00:02 +0200)
autotests/export/docbook/deutsches_ert.lyx
autotests/export/docbook/deutsches_ert.xml
src/insets/InsetERT.cpp
src/xml.cpp
src/xml.h

index e9e692db335c20403e17989d1c74ecdd6e3c5ca2..be6e3358b945bc9fd7c99ecb8f8e6113bc08d5d4 100644 (file)
@@ -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"
index e5933aee0f2fa324ed540b9b133475904163d5f2..1d9b725e5f43f5ed4212c2d13dd77762f84293a8 100644 (file)
@@ -10,7 +10,7 @@
 <chapter>
 <chapter>Einleitung</chapter>
 <para>Wählen Sie hierfür <emphasis role='sans'>Dokument&#x21D2;Einstellungen&#x21D2;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<!-- &#8222;= -->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!. <!-- -&#45; --></emphasis></emphasis></emphasis></para>
 </chapter>
 
 </book>
\ No newline at end of file
index 57fc1e3419ebc1c9f281ebe76dde0aa93dae38a5..a023f7a464af403154af95fa6ae37737f977997e 100644 (file)
@@ -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 << " -->";
 }
 
index 3864a3f4009426bc3be163d423e5d35bcfb0182e..0816bf8918bd9ae94d5225c150c44f4abb2d542e 100644 (file)
@@ -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 += "&lt;";
                        break;
-               case XMLStream::ESCAPE_ALL:
-                       if (c == '<') {
-                               str += "&lt;";
-                               break;
-                       } else if (c == '>') {
-                               str += "&gt;";
-                               break;
-                       }
-                       // fall through
-               case XMLStream::ESCAPE_AND:
-                       if (c == '&')
-                               str += "&amp;";
-                       else
-                               str     +=c ;
+               } else if (c == '>') {
+                       str += "&gt;";
                        break;
+               }
+               // fall through
+       case XMLStream::ESCAPE_AND:
+               if (c == '&')
+                       str += "&amp;";
+               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 += "&#45;";
+               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);
index 5478a66361d8fe099d70a030967a556634c9a662..5afdcf53e921995621f6b8f938eff4a0e86feaf8 100644 (file)
--- 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;