[LyX/master] amend 9291fc465b0d
Juergen Spitzmueller
spitz at lyx.org
Wed Jul 24 19:44:17 UTC 2024
commit 823d2900362abcc22a259cce6773d0bb9a3263dc
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Wed Jul 24 21:42:56 2024 +0200
amend 9291fc465b0d
XHTML wants LaTeX math, nothing converted to unicode
---
src/BiblioInfo.cpp | 13 +++++++------
src/BiblioInfo.h | 6 ++++--
src/Encoding.cpp | 16 +++++++++++++++-
src/Encoding.h | 3 ++-
src/insets/InsetBibtex.cpp | 2 +-
5 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index d933bda4c9..9458984f96 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -915,7 +915,8 @@ docstring BibTeXInfo::expandFormat(docstring const & format,
docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
- Buffer const & buf, CiteItem const & ci, docstring const & format_in) const
+ Buffer const & buf, CiteItem const & ci, docstring const & format_in,
+ bool const for_xhtml) const
{
bool const richtext = ci.richtext;
@@ -933,7 +934,7 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
}
if (!richtext && !info_.empty()) {
- info_ = Encodings::convertLaTeXCommands(processRichtext(info_, false));
+ info_ = Encodings::convertLaTeXCommands(processRichtext(info_, false), for_xhtml);
return info_;
}
if (richtext && !info_richtext_.empty())
@@ -955,11 +956,11 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
}
if (richtext) {
- info_richtext_ = Encodings::convertLaTeXCommands(processRichtext(info_, true));
+ info_richtext_ = Encodings::convertLaTeXCommands(processRichtext(info_, true), for_xhtml);
return info_richtext_;
}
- info_ = Encodings::convertLaTeXCommands(processRichtext(info_, false));
+ info_ = Encodings::convertLaTeXCommands(processRichtext(info_, false), for_xhtml);
return info_;
}
@@ -1376,7 +1377,7 @@ docstring const BiblioInfo::getYear(docstring const & key, Buffer const & buf, b
docstring const BiblioInfo::getInfo(docstring const & key,
- Buffer const & buf, CiteItem const & ci, docstring const & format) const
+ Buffer const & buf, CiteItem const & ci, docstring const & format, bool const for_xhtml) const
{
BiblioInfo::const_iterator it = find(key);
if (it == end())
@@ -1388,7 +1389,7 @@ docstring const BiblioInfo::getInfo(docstring const & key,
if (xrefit != end())
xrefptrs.push_back(&(xrefit->second));
}
- return data.getInfo(xrefptrs, buf, ci, format);
+ return data.getInfo(xrefptrs, buf, ci, format, for_xhtml);
}
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index 6092894b40..7b7a80e058 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -81,7 +81,8 @@ public:
/// \param vector of pointers to crossref/xdata information
docstring const & getInfo(BibTeXInfoList const & xrefs,
Buffer const & buf, CiteItem const & ci,
- docstring const & format = docstring()) const;
+ docstring const & format = docstring(),
+ bool const for_xhtml = false) const;
/// \return formatted BibTeX data for a citation label
docstring const getLabel(BibTeXInfoList const & xrefs,
Buffer const & buf, docstring const & format,
@@ -236,7 +237,8 @@ public:
/// output any richtext tags marked in the citation format and escape < and >
/// elsewhere, and the general output context.
docstring const getInfo(docstring const & key, Buffer const & buf,
- CiteItem const & ci, docstring const & format = docstring()) const;
+ CiteItem const & ci, docstring const & format = docstring(),
+ bool const for_xhtml = false) const;
/// \return formatted BibTeX data for citation labels.
/// Citation labels can have more than one key.
docstring const getLabel(std::vector<docstring> keys, Buffer const & buf,
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index 54a5aebd15..675834f63f 100644
--- a/src/Encoding.cpp
+++ b/src/Encoding.cpp
@@ -614,7 +614,7 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
}
-docstring Encodings::convertLaTeXCommands(docstring const & str)
+docstring Encodings::convertLaTeXCommands(docstring const & str, bool const for_xhtml)
{
docstring val = str;
docstring ret;
@@ -630,6 +630,20 @@ docstring Encodings::convertLaTeXCommands(docstring const & str)
// if we're scanning math, we collect everything until we
// find an unescaped $, and then try to convert this piecewise.
if (scanning_math) {
+ if (for_xhtml) {
+ // with xhtml, we output everything until we
+ // find an unescaped $, at which point we break out.
+ if (escaped)
+ escaped = false;
+ else if (ch == '\\')
+ escaped = true;
+ else if (ch == '$')
+ scanning_math = false;
+ ret += ch;
+ val = val.substr(1);
+ continue;
+ }
+
if (escaped)
escaped = false;
else if (ch == '\\')
diff --git a/src/Encoding.h b/src/Encoding.h
index 3177132514..1321a5ff61 100644
--- a/src/Encoding.h
+++ b/src/Encoding.h
@@ -351,7 +351,8 @@ public:
std::set<std::string> * req = nullptr);
/// converts a string containing LaTeX commands into unicode
/// for display.
- static docstring convertLaTeXCommands(docstring const & str);
+ static docstring convertLaTeXCommands(docstring const & str,
+ bool const for_xhtml = false);
///
enum LatexCmd {
///
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index d452434ab5..a6482d9315 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -1075,7 +1075,7 @@ docstring InsetBibtex::xhtml(XMLStream & xs, OutputParams const &) const
// entry, so there's a lot of repetition. This should be fixed.
xs << xml::StartTag("span", "class='bibtexinfo'")
<< XMLStream::ESCAPE_AND
- << bibinfo.getInfo(entry.key(), buffer(), ci)
+ << bibinfo.getInfo(entry.key(), buffer(), ci, docstring(), true)
<< xml::EndTag("span")
<< xml::EndTag("div")
<< xml::CR();
More information about the lyx-cvs
mailing list