mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
DocBook: fix XML in comments (-- forbidden for some historical reason).
This commit is contained in:
parent
f2e69c165e
commit
85946aae2b
@ -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"
|
||||
|
@ -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>
|
@ -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 << " -->";
|
||||
}
|
||||
|
||||
|
80
src/xml.cpp
80
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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user