xml.cpp/h also merges functionalities from sgml.cpp/h.
../../src/Server.cpp \
../../src/ServerSocket.cpp \
../../src/Session.cpp \
-../../src/sgml.cpp \
+../../src/xml.cpp \
../../src/Spacing.cpp \
../../src/TexRow.cpp \
../../src/TexStream.cpp \
../../src/Server.h \
../../src/ServerSocket.h \
../../src/Session.h \
-../../src/sgml.h \
+../../src/xml.h \
../../src/Spacing.h \
../../src/TexRow.h \
../../src/TexStream.h \
}
if (cleanit)
- ret = html::cleanAttr(ret);
+ ret = xml::cleanAttr(ret);
// make sure it is not too big
support::truncateWithEllipsis(ret, maxsize);
#include "PDFOptions.h"
#include "Session.h"
#include "SpellChecker.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TexRow.h"
#include "Text.h"
params().documentClass().counters().reset();
- sgml::openTag(os, top);
+ xml::openTag(os, top);
os << '\n';
try {
docbookParagraphs(text(), *this, os, runparams);
}
catch (ConversionException const &) { return ExportKilled; }
- sgml::closeTag(os, top_element);
+ xml::closeTag(os, top_element);
}
return ExportSuccess;
}
os << "<title>"
<< (doctitle.empty() ?
from_ascii("LyX Document") :
- html::htmlize(doctitle, XHTMLStream::ESCAPE_ALL))
+ xml::xmlize(doctitle, XMLStream::ESCAPE_ALL))
<< "</title>\n";
docstring styles = features.getTClassHTMLPreamble();
bool const output_body_tag = (output != IncludedFile);
if (output_body_tag)
os << "<body dir=\"auto\">\n";
- XHTMLStream xs(os);
+ XMLStream xs(os);
if (output != IncludedFile)
// if we're an included file, the counters are in the master.
params().documentClass().counters().reset();
par.write(ods, params(), dt);
os << from_utf8(ods.str());
} else if (runparams.flavor == OutputParams::HTML) {
- XHTMLStream xs(os);
+ XMLStream xs(os);
setMathFlavor(runparams);
xhtmlParagraphs(text(), *this, xs, runparams);
} else if (runparams.flavor == OutputParams::TEXT) {
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
-# Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
+# Copyright (c) 2006-2011 Peter K�mmel, <syntheticpp@gmx.net>
#
project(${_lyx})
RowPainter.cpp \
Server.cpp \
ServerSocket.cpp \
- sgml.cpp \
+ xml.cpp \
Session.cpp \
Spacing.cpp \
TexRow.cpp \
Server.h \
ServerSocket.h \
Session.h \
- sgml.h \
+ xml.h \
Spacing.h \
SpellChecker.h \
TexRow.h \
#include "OutputParams.h"
#include "output_latex.h"
#include "output_xhtml.h"
+#include "output_docbook.h"
#include "ParagraphParameters.h"
#include "SpellChecker.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TextClass.h"
#include "TexRow.h"
}
-string Paragraph::getID(Buffer const & buf, OutputParams const & runparams)
+string Paragraph::getID(Buffer const &, OutputParams const &)
const
{
for (pos_type i = 0; i < size(); ++i) {
if (lyx_code == LABEL_CODE) {
InsetLabel const * const il = static_cast<InsetLabel const *>(inset);
docstring const & id = il->getParam("name");
- return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'";
+ return "id='" + to_utf8(xml::cleanID(id)) + "'";
}
}
}
char_type c = d->text_[i];
if (c == ' ')
break;
- os << sgml::escapeChar(c);
+ os << xml::escapeChar(c, XMLStream::ESCAPE_ALL);
}
}
return i;
}
-pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams)
+pos_type Paragraph::firstWordLyXHTML(XMLStream & xs, OutputParams const & runparams)
const
{
pos_type i;
if (style.pass_thru)
os.put(c);
else
- os << sgml::escapeChar(c);
+ os << xml::escapeChar(c, XMLStream::EscapeSettings::ESCAPE_ALL);
}
font_old = font.fontInfo();
}
namespace {
-void doFontSwitch(vector<html::FontTag> & tagsToOpen,
- vector<html::EndFontTag> & tagsToClose,
- bool & flag, FontState curstate, html::FontTypes type)
+
+void doFontSwitchXHTML(vector<xml::FontTag> & tagsToOpen,
+ vector<xml::EndFontTag> & tagsToClose,
+ bool & flag, FontState curstate, xml::FontTypes type)
{
if (curstate == FONT_ON) {
- tagsToOpen.push_back(html::FontTag(type));
+ tagsToOpen.push_back(xhtmlStartFontTag(type));
flag = true;
} else if (flag) {
- tagsToClose.push_back(html::EndFontTag(type));
+ tagsToClose.push_back(xhtmlEndFontTag(type));
flag = false;
}
}
-} // namespace
+
+} // anonymous namespace
docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
- XHTMLStream & xs,
- OutputParams const & runparams,
- Font const & outerfont,
- bool start_paragraph, bool close_paragraph,
- pos_type initial) const
+ XMLStream & xs,
+ OutputParams const & runparams,
+ Font const & outerfont,
+ bool start_paragraph, bool close_paragraph,
+ pos_type initial) const
{
docstring retval;
string const default_family =
buf.masterBuffer()->params().fonts_default_family;
- vector<html::FontTag> tagsToOpen;
- vector<html::EndFontTag> tagsToClose;
+ vector<xml::FontTag> tagsToOpen;
+ vector<xml::EndFontTag> tagsToClose;
// parsing main loop
for (pos_type i = initial; i < size(); ++i) {
// emphasis
FontState curstate = font.fontInfo().emph();
if (font_old.emph() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, emph_flag, curstate, html::FT_EMPH);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, emph_flag, curstate, xml::FT_EMPH);
// noun
curstate = font.fontInfo().noun();
if (font_old.noun() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, noun_flag, curstate, html::FT_NOUN);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, noun_flag, curstate, xml::FT_NOUN);
// underbar
curstate = font.fontInfo().underbar();
if (font_old.underbar() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, ubar_flag, curstate, html::FT_UBAR);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, ubar_flag, curstate, xml::FT_UBAR);
// strikeout
curstate = font.fontInfo().strikeout();
if (font_old.strikeout() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, sout_flag, curstate, html::FT_SOUT);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, sout_flag, curstate, xml::FT_SOUT);
// xout
curstate = font.fontInfo().xout();
if (font_old.xout() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, xout_flag, curstate, html::FT_XOUT);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, xout_flag, curstate, xml::FT_XOUT);
// double underbar
curstate = font.fontInfo().uuline();
if (font_old.uuline() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, dbar_flag, curstate, html::FT_DBAR);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, dbar_flag, curstate, xml::FT_DBAR);
// wavy line
curstate = font.fontInfo().uwave();
if (font_old.uwave() != curstate)
- doFontSwitch(tagsToOpen, tagsToClose, wave_flag, curstate, html::FT_WAVE);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, wave_flag, curstate, xml::FT_WAVE);
// bold
// a little hackish, but allows us to reuse what we have.
curstate = (font.fontInfo().series() == BOLD_SERIES ? FONT_ON : FONT_OFF);
if (font_old.series() != font.fontInfo().series())
- doFontSwitch(tagsToOpen, tagsToClose, bold_flag, curstate, html::FT_BOLD);
+ doFontSwitchXHTML(tagsToOpen, tagsToClose, bold_flag, curstate, xml::FT_BOLD);
// Font shape
curr_fs = font.fontInfo().shape();
FontShape old_fs = font_old.shape();
if (old_fs != curr_fs) {
- if (shap_flag) {
- switch (old_fs) {
- case ITALIC_SHAPE:
- tagsToClose.push_back(html::EndFontTag(html::FT_ITALIC));
- break;
- case SLANTED_SHAPE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SLANTED));
- break;
- case SMALLCAPS_SHAPE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SMALLCAPS));
- break;
- case UP_SHAPE:
- case INHERIT_SHAPE:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
- shap_flag = false;
- }
- switch (curr_fs) {
- case ITALIC_SHAPE:
- tagsToOpen.push_back(html::FontTag(html::FT_ITALIC));
- shap_flag = true;
- break;
- case SLANTED_SHAPE:
- tagsToOpen.push_back(html::FontTag(html::FT_SLANTED));
- shap_flag = true;
- break;
- case SMALLCAPS_SHAPE:
- tagsToOpen.push_back(html::FontTag(html::FT_SMALLCAPS));
- shap_flag = true;
- break;
- case UP_SHAPE:
- case INHERIT_SHAPE:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
+ if (shap_flag) {
+ switch (old_fs) {
+ case ITALIC_SHAPE:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_ITALIC), xml::FT_ITALIC));
+ break;
+ case SLANTED_SHAPE:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_SLANTED), xml::FT_SLANTED));
+ break;
+ case SMALLCAPS_SHAPE:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_SMALLCAPS), xml::FT_SMALLCAPS));
+ break;
+ case UP_SHAPE:
+ case INHERIT_SHAPE:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
+ shap_flag = false;
+ }
+ switch (curr_fs) {
+ case ITALIC_SHAPE:
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_ITALIC), xml::FT_ITALIC));
+ shap_flag = true;
+ break;
+ case SLANTED_SHAPE:
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_SLANTED), xml::FT_SLANTED));
+ shap_flag = true;
+ break;
+ case SMALLCAPS_SHAPE:
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_SMALLCAPS), xml::FT_SMALLCAPS));
+ shap_flag = true;
+ break;
+ case UP_SHAPE:
+ case INHERIT_SHAPE:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
}
// Font family
curr_fam = font.fontInfo().family();
FontFamily old_fam = font_old.family();
if (old_fam != curr_fam) {
- if (faml_flag) {
- switch (old_fam) {
- case ROMAN_FAMILY:
- tagsToClose.push_back(html::EndFontTag(html::FT_ROMAN));
- break;
- case SANS_FAMILY:
- tagsToClose.push_back(html::EndFontTag(html::FT_SANS));
- break;
- case TYPEWRITER_FAMILY:
- tagsToClose.push_back(html::EndFontTag(html::FT_TYPE));
- break;
- case INHERIT_FAMILY:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
- faml_flag = false;
- }
- switch (curr_fam) {
- case ROMAN_FAMILY:
- // we will treat a "default" font family as roman, since we have
- // no other idea what to do.
- if (default_family != "rmdefault" && default_family != "default") {
- tagsToOpen.push_back(html::FontTag(html::FT_ROMAN));
- faml_flag = true;
- }
- break;
- case SANS_FAMILY:
- if (default_family != "sfdefault") {
- tagsToOpen.push_back(html::FontTag(html::FT_SANS));
- faml_flag = true;
- }
- break;
- case TYPEWRITER_FAMILY:
- if (default_family != "ttdefault") {
- tagsToOpen.push_back(html::FontTag(html::FT_TYPE));
- faml_flag = true;
- }
- break;
- case INHERIT_FAMILY:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
+ if (faml_flag) {
+ switch (old_fam) {
+ case ROMAN_FAMILY:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_ROMAN), xml::FT_ROMAN));
+ break;
+ case SANS_FAMILY:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_SANS), xml::FT_SANS));
+ break;
+ case TYPEWRITER_FAMILY:
+ tagsToClose.push_back(xml::EndFontTag(fontToHtmlTag(xml::FT_TYPE), xml::FT_TYPE));
+ break;
+ case INHERIT_FAMILY:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
+ faml_flag = false;
+ }
+ switch (curr_fam) {
+ case ROMAN_FAMILY:
+ // we will treat a "default" font family as roman, since we have
+ // no other idea what to do.
+ if (default_family != "rmdefault" && default_family != "default") {
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_ROMAN), xml::FT_ROMAN));
+ faml_flag = true;
+ }
+ break;
+ case SANS_FAMILY:
+ if (default_family != "sfdefault") {
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_SANS), xml::FT_SANS));
+ faml_flag = true;
+ }
+ break;
+ case TYPEWRITER_FAMILY:
+ if (default_family != "ttdefault") {
+ tagsToOpen.push_back(xml::FontTag(fontToHtmlTag(xml::FT_TYPE), xml::FT_TYPE));
+ faml_flag = true;
+ }
+ break;
+ case INHERIT_FAMILY:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
}
// Font size
curr_size = font.fontInfo().size();
FontSize old_size = font_old.size();
if (old_size != curr_size) {
- if (size_flag) {
- switch (old_size) {
- case TINY_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_TINY));
- break;
- case SCRIPT_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_SCRIPT));
- break;
- case FOOTNOTE_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_FOOTNOTE));
- break;
- case SMALL_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_SMALL));
- break;
- case LARGE_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGE));
- break;
- case LARGER_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGER));
- break;
- case LARGEST_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_LARGEST));
- break;
- case HUGE_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_HUGE));
- break;
- case HUGER_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_HUGER));
- break;
- case INCREASE_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_INCREASE));
- break;
- case DECREASE_SIZE:
- tagsToClose.push_back(html::EndFontTag(html::FT_SIZE_DECREASE));
- break;
- case INHERIT_SIZE:
- case NORMAL_SIZE:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
- size_flag = false;
- }
- switch (curr_size) {
- case TINY_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_TINY));
- size_flag = true;
- break;
- case SCRIPT_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_SCRIPT));
- size_flag = true;
- break;
- case FOOTNOTE_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_FOOTNOTE));
- size_flag = true;
- break;
- case SMALL_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_SMALL));
- size_flag = true;
- break;
- case LARGE_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGE));
- size_flag = true;
- break;
- case LARGER_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGER));
- size_flag = true;
- break;
- case LARGEST_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_LARGEST));
- size_flag = true;
- break;
- case HUGE_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_HUGE));
- size_flag = true;
- break;
- case HUGER_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_HUGER));
- size_flag = true;
- break;
- case INCREASE_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_INCREASE));
- size_flag = true;
- break;
- case DECREASE_SIZE:
- tagsToOpen.push_back(html::FontTag(html::FT_SIZE_DECREASE));
- size_flag = true;
- break;
- case NORMAL_SIZE:
- case INHERIT_SIZE:
- break;
- default:
- // the other tags are for internal use
- LATTEST(false);
- break;
- }
+ if (size_flag) {
+ switch (old_size) {
+ case TINY_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_TINY), xml::FT_SIZE_TINY);
+ break;
+ case SCRIPT_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_SCRIPT), xml::FT_SIZE_SCRIPT);
+ break;
+ case FOOTNOTE_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_FOOTNOTE), xml::FT_SIZE_FOOTNOTE);
+ break;
+ case SMALL_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_SMALL), xml::FT_SIZE_SMALL);
+ break;
+ case LARGE_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGE), xml::FT_SIZE_LARGE);
+ break;
+ case LARGER_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGER), xml::FT_SIZE_LARGER);
+ break;
+ case LARGEST_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGEST), xml::FT_SIZE_LARGEST);
+ break;
+ case HUGE_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_HUGE), xml::FT_SIZE_HUGE);
+ break;
+ case HUGER_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_HUGER), xml::FT_SIZE_HUGER);
+ break;
+ case INCREASE_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_INCREASE), xml::FT_SIZE_INCREASE);
+ break;
+ case DECREASE_SIZE:
+ tagsToClose.emplace_back(fontToHtmlTag(xml::FT_SIZE_DECREASE), xml::FT_SIZE_DECREASE);
+ break;
+ case INHERIT_SIZE:
+ case NORMAL_SIZE:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
+ size_flag = false;
+ }
+ switch (curr_size) {
+ case TINY_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_TINY), xml::FT_SIZE_TINY);
+ size_flag = true;
+ break;
+ case SCRIPT_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_SCRIPT), xml::FT_SIZE_SCRIPT);
+ size_flag = true;
+ break;
+ case FOOTNOTE_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_FOOTNOTE), xml::FT_SIZE_FOOTNOTE);
+ size_flag = true;
+ break;
+ case SMALL_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_SMALL), xml::FT_SIZE_SMALL);
+ size_flag = true;
+ break;
+ case LARGE_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGE), xml::FT_SIZE_LARGE);
+ size_flag = true;
+ break;
+ case LARGER_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGER), xml::FT_SIZE_LARGER);
+ size_flag = true;
+ break;
+ case LARGEST_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_LARGEST), xml::FT_SIZE_LARGEST);
+ size_flag = true;
+ break;
+ case HUGE_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_HUGE), xml::FT_SIZE_HUGE);
+ size_flag = true;
+ break;
+ case HUGER_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_HUGER), xml::FT_SIZE_HUGER);
+ size_flag = true;
+ break;
+ case INCREASE_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_INCREASE), xml::FT_SIZE_INCREASE);
+ size_flag = true;
+ break;
+ case DECREASE_SIZE:
+ tagsToOpen.emplace_back(fontToHtmlTag(xml::FT_SIZE_DECREASE), xml::FT_SIZE_DECREASE);
+ size_flag = true;
+ break;
+ case INHERIT_SIZE:
+ case NORMAL_SIZE:
+ break;
+ default:
+ // the other tags are for internal use
+ LATTEST(false);
+ break;
+ }
}
// FIXME XHTML
// Other such tags? What about the other text ranges?
- vector<html::EndFontTag>::const_iterator cit = tagsToClose.begin();
- vector<html::EndFontTag>::const_iterator cen = tagsToClose.end();
+ vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+ vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
for (; cit != cen; ++cit)
xs << *cit;
- vector<html::FontTag>::const_iterator sit = tagsToOpen.begin();
- vector<html::FontTag>::const_iterator sen = tagsToOpen.end();
+ vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
+ vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
for (; sit != sen; ++sit)
xs << *sit;
char_type c = getUChar(buf.masterBuffer()->params(),
runparams, i);
if (c == ' ' && (style.free_spacing || runparams.free_spacing))
- xs << XHTMLStream::ESCAPE_NONE << " ";
+ xs << XMLStream::ESCAPE_NONE << " ";
else
xs << c;
}
class ParagraphParameters;
class TocBackend;
class WordLangTuple;
-class XHTMLStream;
+class XMLStream;
class otexstream;
class FontSpan {
pos_type firstWordDocBook(odocstream & os, OutputParams const & runparams) const;
/// Output the first word of a paragraph, return the position where it left.
- pos_type firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const;
+ pos_type firstWordLyXHTML(XMLStream & xs, OutputParams const & runparams) const;
/// Writes to stream the docbook representation
void simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams,
Font const & outerfont,
pos_type initial = 0) const;
+
/// \return any material that has had to be deferred until after the
/// paragraph has closed.
docstring simpleLyXHTMLOnePar(Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams,
Font const & outerfont,
bool start_paragraph = true,
#include "LyXRC.h"
#include "Row.h"
#include "OutputParams.h"
-#include "sgml.h"
+#include "xml.h"
#include "TextClass.h"
#include "TexRow.h"
}
-docstring Inset::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring Inset::xhtml(XMLStream & xs, OutputParams const &) const
{
xs << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
return docstring();
class Text;
class TocBackend;
class TocList;
-class XHTMLStream;
+class XMLStream;
class otexstream;
namespace graphics { class PreviewLoader; }
/// docbook output
virtual int docbook(odocstream & os, OutputParams const &) const;
/// XHTML output
- /// the inset is expected to write XHTML to the XHTMLStream
+ /// the inset is expected to write XHTML to the XMLStream
/// \return any "deferred" material that should be written outside the
/// normal stream, and which will in fact be written after the current
/// paragraph closes. this is appropriate e.g. for floats.
- virtual docstring xhtml(XHTMLStream & xs, OutputParams const &) const;
+ virtual docstring xhtml(XMLStream &, OutputParams const &) const;
/// Writes a string representation of the inset to the odocstream.
/// This one should be called when you want the whole contents of
///
int docbook(odocstream &, OutputParams const &) const { return 0; }
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const
+ docstring xhtml(XMLStream &, OutputParams const &) const
{ return docstring(); }
///
void write(std::ostream & os) const;
}
-docstring InsetBibitem::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetBibitem::xhtml(XMLStream & xs, OutputParams const &) const
{
// FIXME XHTML
// XHTML 1.1 doesn't have the "name" attribute for <a>, so we have to use
// handle jumping to ids. If we don't do that, though, we can just put the
// id into the span tag.
string const attrs =
- "id='LyXCite-" + to_utf8(html::cleanAttr(getParam("key"))) + "'";
- xs << html::CompTag("a", attrs);
- xs << html::StartTag("span", "class='bibitemlabel'");
+ "id='LyXCite-" + to_utf8(xml::cleanAttr(getParam("key"))) + "'";
+ xs << xml::CompTag("a", attrs);
+ xs << xml::StartTag("span", "class='bibitemlabel'");
xs << bibLabel();
- xs << html::EndTag("span");
+ xs << xml::EndTag("span");
return docstring();
}
int plaintext(odocstringstream &, OutputParams const &,
size_t max_length = INT_MAX) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
/// update the counter of this inset
#include "LaTeXFeatures.h"
#include "output_latex.h"
#include "output_xhtml.h"
+#include "xml.h"
#include "OutputParams.h"
#include "PDFOptions.h"
#include "texstream.h"
refoutput += "[" + entry.label() + "] ";
// FIXME Right now, we are calling BibInfo::getInfo on the key,
// which will give us all the cross-referenced info. But for every
- // entry, so there's a lot of repitition. This should be fixed.
+ // entry, so there's a lot of repetition. This should be fixed.
refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
}
os << refoutput;
// FIXME
// docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
// And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
-docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetBibtex::xhtml(XMLStream & xs, OutputParams const &) const
{
BiblioInfo const & bibinfo = buffer().masterBibInfo();
bool const all_entries = getParam("btprint") == "btPrintAll";
ci.richtext = true;
ci.max_key_size = UINT_MAX;
- xs << html::StartTag("h2", "class='bibtex'")
+ xs << xml::StartTag("h2", "class='bibtex'")
<< reflabel
- << html::EndTag("h2")
- << html::StartTag("div", "class='bibtex'");
+ << xml::EndTag("h2")
+ << xml::StartTag("div", "class='bibtex'");
// Now we loop over the entries
vector<docstring>::const_iterator vit = cites.begin();
BibTeXInfo const & entry = biit->second;
string const attr = "class='bibtexentry' id='LyXCite-"
- + to_utf8(html::cleanAttr(entry.key())) + "'";
- xs << html::StartTag("div", attr);
+ + to_utf8(xml::cleanAttr(entry.key())) + "'";
+ xs << xml::StartTag("div", attr);
// don't print labels if we're outputting all entries
if (!all_entries) {
- xs << html::StartTag("span", "class='bibtexlabel'")
+ xs << xml::StartTag("span", "class='bibtexlabel'")
<< entry.label()
- << html::EndTag("span");
+ << xml::EndTag("span");
}
// FIXME Right now, we are calling BibInfo::getInfo on the key,
// which will give us all the cross-referenced info. But for every
// entry, so there's a lot of repitition. This should be fixed.
- xs << html::StartTag("span", "class='bibtexinfo'")
- << XHTMLStream::ESCAPE_AND
+ xs << xml::StartTag("span", "class='bibtexinfo'")
+ << XMLStream::ESCAPE_AND
<< bibinfo.getInfo(entry.key(), buffer(), ci)
- << html::EndTag("span")
- << html::EndTag("div")
- << html::CR();
+ << xml::EndTag("span")
+ << xml::EndTag("div")
+ << xml::CR();
}
- xs << html::EndTag("div");
+ xs << xml::EndTag("div");
return docstring();
}
///
void validate(LaTeXFeatures &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
+ ///
+ docstring docbook(XMLStream &, OutputParams const &) const;
///
std::string contextMenuName() const;
//@}
}
-docstring InsetBox::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
+docstring InsetBox::xhtml(XMLStream & xs, OutputParams const & runparams) const
{
// construct attributes
string attrs = "class='" + params_.type + "'";
if (!style.empty())
attrs += " style='" + style + "'";
- xs << html::StartTag("div", attrs);
+ xs << xml::StartTag("div", attrs);
XHTMLOptions const opts = InsetText::WriteLabel | InsetText::WriteInnerTag;
docstring defer = InsetText::insetAsXHTML(xs, runparams, opts);
- xs << html::EndTag("div");
+ xs << xml::EndTag("div");
xs << defer;
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
}
-docstring InsetBranch::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetBranch::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (producesOutput()) {
OutputParams newrp = rp;
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
}
-docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetCaption::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (rp.html_disable_captions)
return docstring();
else
attr = attr + " class='" + our_class + "'";
}
- xs << html::StartTag(tag, attr);
+ xs << xml::StartTag(tag, attr);
docstring def = getCaptionAsHTML(xs, rp);
- xs << html::EndTag(tag);
+ xs << xml::EndTag(tag);
return def;
}
}
-docstring InsetCaption::getCaptionAsHTML(XHTMLStream & xs,
+docstring InsetCaption::getCaptionAsHTML(XMLStream & xs,
OutputParams const & runparams) const
{
xs << full_label_ << ' ';
/// return the caption text
int getCaptionAsPlaintext(odocstream & os, OutputParams const &) const;
/// return the caption text as HTML
- docstring getCaptionAsHTML(XHTMLStream & os, OutputParams const &) const;
+ docstring getCaptionAsHTML(XMLStream & os, OutputParams const &) const;
///
std::string contextMenuName() const;
private:
///
int docbook(odocstream & os, OutputParams const & runparams) const;
///
- docstring xhtml(XHTMLStream & os, OutputParams const & runparams) const;
+ docstring xhtml(XMLStream & os, OutputParams const & runparams) const;
///
void addToToc(DocIterator const & di, bool output_active, UpdateType utype,
TocBackend & backend) const;
return docstring();
odocstringstream ods;
- XHTMLStream xs(ods);
+ XMLStream xs(ods);
docstring def = ins->getCaptionAsHTML(xs, runparams);
if (!def.empty())
// should already have been escaped
- xs << XHTMLStream::ESCAPE_NONE << def << '\n';
+ xs << XMLStream::ESCAPE_NONE << def << '\n';
return ods.str();
}
return content;
// we have to do the escaping here, because we will ultimately
// write this as a raw string, so as not to escape the tags.
- return "<a href='#LyXCite-" + html::cleanAttr(key) + "'>" +
- html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
+ return "<a href='#LyXCite-" + xml::cleanAttr(key) + "'>" +
+ xml::xmlize(content, XMLStream::ESCAPE_ALL) + "</a>";
}
} // anonymous namespace
}
-docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetCitation::xhtml(XMLStream & xs, OutputParams const &) const
{
string const & cmd = getCmdName();
if (cmd == "nocite")
return docstring();
// have to output this raw, because generateLabel() will include tags
- xs << XHTMLStream::ESCAPE_NONE << generateLabel(true);
+ xs << XMLStream::ESCAPE_NONE << generateLabel(true);
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
#include "LaTeXFeatures.h"
#include "OutputParams.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TextClass.h"
}
-docstring InsetCounter::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetCounter::xhtml(XMLStream &, OutputParams const &) const
{
// Here, we need to track counter values ourselves,
// since unlike in the LaTeX case, there is no external
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
}
-docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const {}
/// should paragraph indendation be omitted in any case?
#include "output_latex.h"
#include "output_xhtml.h"
#include "texstream.h"
+#include "xml.h"
#include "TocBackend.h"
#include "frontends/alert.h"
}
-docstring InsetExternal::xhtml(XHTMLStream & xs,
+docstring InsetExternal::xhtml(XMLStream & xs,
OutputParams const & runparams) const
{
bool const external_in_tmpdir = !runparams.nice;
if (buffer().isClone() && buffer().isExporting())
throw ConversionException();
}
- xs << XHTMLStream::ESCAPE_NONE << ods.str();
+ xs << XMLStream::ESCAPE_NONE << ods.str();
return docstring();
}
int docbook(odocstream &, OutputParams const &) const;
/// For now, this does nothing. Someone who knows about this
/// should see what needs doing for XHTML output.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
/// Update needed features for this inset.
void validate(LaTeXFeatures & features) const;
///
*/
#include <config.h>
+#include <xml.h>
#include "InsetFloat.h"
#include "InsetCaption.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
+#include "InsetList.h"
#include "support/debug.h"
#include "support/docstream.h"
}
-docstring InsetFloat::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetFloat::xhtml(XMLStream & xs, OutputParams const & rp) const
{
FloatList const & floats = buffer().params().documentClass().floats();
Floating const & ftype = floats.getType(params_.type);
string const & attr = ftype.htmlAttrib();
odocstringstream ods;
- XHTMLStream newxs(ods);
- newxs << html::StartTag(htmltype, attr);
+ XMLStream newxs(ods);
+ newxs << xml::StartTag(htmltype, attr);
InsetText::XHTMLOptions const opts =
InsetText::WriteLabel | InsetText::WriteInnerTag;
docstring deferred = InsetText::insetAsXHTML(newxs, rp, opts);
- newxs << html::EndTag(htmltype);
+ newxs << xml::EndTag(htmltype);
if (rp.inFloat == OutputParams::NONFLOAT) {
// In this case, this float needs to be deferred, but we'll put it
// we can write to the stream.
// Note that things will already have been escaped, so we do not
// want to escape them again.
- xs << XHTMLStream::ESCAPE_NONE << ods.str();
+ xs << XMLStream::ESCAPE_NONE << ods.str();
}
return deferred;
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
bool insetAllowed(InsetCode) const;
/** returns false if, when outputing LaTeX, font changes should
}
-docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams const & op) const {
+docstring InsetFloatList::xhtml(XMLStream &, OutputParams const & op) const {
FloatList const & floats = buffer().params().documentClass().floats();
FloatList::const_iterator cit = floats[to_ascii(getParam("type"))];
// that's how we deal with the fact that we're probably inside a standard
// paragraph, and we don't want to be.
odocstringstream ods;
- XHTMLStream xs(ods);
+ XMLStream xs(ods);
InsetLayout const & il = getLayout();
string const & tag = il.htmltag();
- xs << html::StartTag("div", "class='toc toc-floats'");
- xs << html::StartTag(tag, tocattr)
+ xs << xml::StartTag("div", "class='toc toc-floats'");
+ xs << xml::StartTag(tag, tocattr)
<< toclabel
- << html::EndTag(tag);
+ << xml::EndTag(tag);
Toc::const_iterator it = toc->begin();
Toc::const_iterator const en = toc->end();
continue;
Paragraph const & par = it->dit().innerParagraph();
string const attr = "class='lyxtoc-floats lyxtoc-" + toctype + "'";
- xs << html::StartTag("div", attr);
+ xs << xml::StartTag("div", attr);
string const parattr = "href='#" + par.magicLabel() + "' class='lyxtoc-floats'";
- xs << html::StartTag("a", parattr)
+ xs << xml::StartTag("a", parattr)
<< it->str()
- << html::EndTag("a");
- xs << html::EndTag("div");
+ << xml::EndTag("a");
+ xs << xml::EndTag("div");
}
- xs << html::EndTag("div");
+ xs << xml::EndTag("div");
return ods.str();
}
int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
#include "Mover.h"
#include "OutputParams.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
namespace {
/// Find the most suitable image format for images in \p format
-/// Note that \p format may be unknown (i. e. an empty string)
+/// Note that \p format may be unknown (i.e. an empty string)
string findTargetFormat(string const & format, OutputParams const & runparams)
{
// Are we latexing to DVI or PDF?
InsetGraphics::InsetGraphics(Buffer * buf)
- : Inset(buf), graphic_label(sgml::uniqueID(from_ascii("graph"))),
+ : Inset(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(this))
{
}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
: Inset(ig),
- graphic_label(sgml::uniqueID(from_ascii("graph"))),
+ graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(*ig.graphic_, this))
{
setParams(ig.params());
// Calculate the options part of the command, we must do it to a string
// stream since we copied the code from createLatexParams() ;-)
- // FIXME: av: need to translate spec -> Docbook XSL spec
- // (http://www.sagehill.net/docbookxsl/ImageSizing.html)
- // Right now it only works with my version of db2latex :-)
-
odocstringstream options;
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
{
if (runparams.flavor != OutputParams::XML)
os << "<![ %output.print." << format
- << "; [" << endl;
+ << "; [" << endl;
os <<"<imageobject><imagedata fileref=\"&"
- << graphic_label
- << ";."
- << format
- << "\" "
- << attributes;
+ << graphic_label
+ << ";."
+ << format
+ << "\" "
+ << attributes;
if (runparams.flavor == OutputParams::XML)
os << " role=\"" << format << "\"/>" ;
}
-docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const
+docstring InsetGraphics::xhtml(XMLStream & xs, OutputParams const & op) const
{
string const output_file = op.dryrun ? string() : prepareHTMLFile(op);
<< params().filename << "' for output. File missing?");
string const attr = "src='" + params().filename.absFileName()
+ "' alt='image: " + output_file + "'";
- xs << html::CompTag("img", attr);
+ xs << xml::CompTag("img", attr);
return docstring();
}
string const attr = imgstyle + "src='" + output_file + "' alt='image: "
+ output_file + "'";
- xs << html::CompTag("img", attr);
+ xs << xml::CompTag("img", attr);
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream & os, OutputParams const &) const;
+ docstring xhtml(XMLStream & os, OutputParams const &) const;
/** Tell LyX what the latex features you need i.e. what latex packages
you need to be included.
*/
#include "LaTeXFeatures.h"
#include "OutputParams.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "support/docstream.h"
os << "<ulink url=\""
<< subst(getParam("target"), from_ascii("&"), from_ascii("&"))
<< "\">"
- << sgml::escapeString(getParam("name"))
+ << xml::escapeString(getParam("name"))
<< "</ulink>";
return 0;
}
-docstring InsetHyperlink::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetHyperlink::xhtml(XMLStream & xs, OutputParams const &) const
{
docstring const & target =
- html::htmlize(getParam("target"), XHTMLStream::ESCAPE_AND);
+ xml::xmlize(getParam("target"), XMLStream::ESCAPE_AND);
docstring const & name = getParam("name");
- xs << html::StartTag("a", to_utf8("href=\"" + target + "\""));
+ xs << xml::StartTag("a", to_utf8("href=\"" + target + "\""));
xs << (name.empty() ? target : name);
- xs << html::EndTag("a");
+ xs << xml::EndTag("a");
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
//@}
/// \name Static public methods obligated for InsetCommand derived classes
}
-docstring InsetIPA::xhtml(XHTMLStream & xs, OutputParams const & runparams_in) const
+docstring InsetIPA::xhtml(XMLStream & xs, OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
runparams.inIPA = true;
///
void latex(otexstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream & xs, OutputParams const &) const;
+ docstring xhtml(XMLStream & xs, OutputParams const &) const;
///
void validate(LaTeXFeatures & features) const;
///
}
-docstring InsetIPADeco::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
+docstring InsetIPADeco::xhtml(XMLStream & xs, OutputParams const & runparams) const
{
// FIXME: Like in plaintext, the combining characters "͡" (toptiebar)
// or "͜" (bottomtiebar) would need to be inserted just in the mid
}
-docstring InsetIPAChar::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetIPAChar::xhtml(XMLStream & xs, OutputParams const &) const
{
switch (kind_) {
case TONE_FALLING:
- xs << XHTMLStream::ESCAPE_NONE << "˥"
- << XHTMLStream::ESCAPE_NONE << "˩";
+ xs << XMLStream::ESCAPE_NONE << "˥"
+ << XMLStream::ESCAPE_NONE << "˩";
break;
case TONE_RISING:
- xs << XHTMLStream::ESCAPE_NONE << "˩"
- << XHTMLStream::ESCAPE_NONE << "˥";
+ xs << XMLStream::ESCAPE_NONE << "˩"
+ << XMLStream::ESCAPE_NONE << "˥";
break;
case TONE_HIGH_RISING:
- xs << XHTMLStream::ESCAPE_NONE << "˧"
- << XHTMLStream::ESCAPE_NONE << "˥";
+ xs << XMLStream::ESCAPE_NONE << "˧"
+ << XMLStream::ESCAPE_NONE << "˥";
break;
case TONE_LOW_RISING:
- xs << XHTMLStream::ESCAPE_NONE << "˩"
- << XHTMLStream::ESCAPE_NONE << "˧";
+ xs << XMLStream::ESCAPE_NONE << "˩"
+ << XMLStream::ESCAPE_NONE << "˧";
break;
case TONE_HIGH_RISING_FALLING:
- xs << XHTMLStream::ESCAPE_NONE << "˨"
- << XHTMLStream::ESCAPE_NONE << "˥"
- << XHTMLStream::ESCAPE_NONE << "˨";
+ xs << XMLStream::ESCAPE_NONE << "˨"
+ << XMLStream::ESCAPE_NONE << "˥"
+ << XMLStream::ESCAPE_NONE << "˨";
break;
}
return docstring();
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
}
-docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetInclude::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (rp.inComment)
return docstring();
bool const listing = isListings(params());
if (listing || isVerbatim(params())) {
if (listing)
- xs << html::StartTag("pre");
+ xs << xml::StartTag("pre");
// FIXME: We don't know the encoding of the file, default to UTF-8.
xs << includedFileName(buffer(), params()).fileContents("UTF-8");
if (listing)
- xs << html::EndTag("pre");
+ xs << xml::EndTag("pre");
return docstring();
}
op.par_end = 0;
ibuf->writeLyXHTMLSource(xs.os(), op, Buffer::IncludedFile);
} else
- xs << XHTMLStream::ESCAPE_NONE
+ xs << XMLStream::ESCAPE_NONE
<< "<!-- Included file: "
<< from_utf8(included_file.absFileName())
- << XHTMLStream::ESCAPE_NONE
+ << XMLStream::ESCAPE_NONE
<< " -->";
return docstring();
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
/// get the text displayed on the button
docstring screenLabel() const;
//@}
-
- /// holds the entity name that defines the file location (SGML)
+
+ /// holds the entity name that defines the file location (XML)
docstring const include_label;
/// The pointer never changes although *preview_'s contents may.
#include "Lexer.h"
#include "output_latex.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TextClass.h"
#include "TocBackend.h"
InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
- : InsetCollapsible(buf), params_(params)
+ : InsetCollapsible(buf), params_(params)
{}
otexstringstream os;
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
- && params_.index != "idx") {
+ && params_.index != "idx") {
os << "\\sindex[";
os << escape(params_.index);
os << "]{";
LYXERR0("The `|' separator was not found in the plaintext version!");
}
- // Separate the entires and subentries, i.e., split on "!"
+ // Separate the entries and subentries, i.e., split on "!"
// FIXME This would do the wrong thing with escaped ! characters
std::vector<docstring> const levels =
- getVectorFromString(latexstr, from_ascii("!"), true);
+ getVectorFromString(latexstr, from_ascii("!"), true);
std::vector<docstring> const levels_plain =
- getVectorFromString(plainstr, from_ascii("!"), true);
+ getVectorFromString(plainstr, from_ascii("!"), true);
vector<docstring>::const_iterator it = levels.begin();
vector<docstring>::const_iterator end = levels.end();
if (contains(*it, '\\') && !contains(*it, '@')) {
// Plaintext might return nothing (e.g. for ERTs)
docstring const spart =
- (it2 < levels_plain.end() && !(*it2).empty())
- ? *it2 : *it;
+ (it2 < levels_plain.end() && !(*it2).empty())
+ ? *it2 : *it;
// Now we need to validate that all characters in
// the sorting part are representable in the current
// encoding. If not try the LaTeX macro which might
// or might not be a good choice, and issue a warning.
pair<docstring, docstring> spart_latexed =
- runparams.encoding->latexString(spart, runparams.dryrun);
+ runparams.encoding->latexString(spart, runparams.dryrun);
if (!spart_latexed.second.empty())
- LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
+ LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
if (spart != spart_latexed.first && !runparams.dryrun) {
// FIXME: warning should be passed to the error dialog
frontend::Alert::warning(_("Index sorting failed"),
- bformat(_("LyX's automatic index sorting algorithm faced\n"
- "problems with the entry '%1$s'.\n"
- "Please specify the sorting of this entry manually, as\n"
- "explained in the User Guide."), spart));
+ bformat(_("LyX's automatic index sorting algorithm faced\n"
+ "problems with the entry '%1$s'.\n"
+ "Please specify the sorting of this entry manually, as\n"
+ "explained in the User Guide."), spart));
}
// remove remaining \'s for the sorting part
docstring const ppart =
- subst(spart_latexed.first, from_ascii("\\"), docstring());
+ subst(spart_latexed.first, from_ascii("\\"), docstring());
os << ppart;
os << '@';
}
}
-docstring InsetIndex::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetIndex::xhtml(XMLStream & xs, OutputParams const &) const
{
// we just print an anchor, taking the paragraph ID from
// our own interior paragraph, which doesn't get printed
std::string const magic = paragraphs().front().magicLabel();
std::string const attr = "id='" + magic + "'";
- xs << html::CompTag("a", attr);
+ xs << xml::CompTag("a", attr);
return docstring();
}
} // namespace
-docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
+docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const
{
BufferParams const & bp = buffer().masterBuffer()->params();
// that's how we deal with the fact that we're probably inside a standard
// paragraph, and we don't want to be.
odocstringstream ods;
- XHTMLStream xs(ods);
+ XMLStream xs(ods);
- xs << html::StartTag("div", tocattr);
- xs << html::StartTag(lay.htmltag(), lay.htmlattr())
+ xs << xml::StartTag("div", tocattr);
+ xs << xml::StartTag(lay.htmltag(), lay.htmlattr())
<< translateIfPossible(from_ascii("Index"),
op.local_font->language()->lang())
- << html::EndTag(lay.htmltag());
- xs << html::StartTag("ul", "class='main'");
+ << xml::EndTag(lay.htmltag());
+ xs << xml::StartTag("ul", "class='main'");
Font const dummy;
vector<IndexEntry>::const_iterator eit = entries.begin();
// close last entry or entries, depending.
if (level == 3) {
// close this sub-sub-entry
- xs << html::EndTag("li") << html::CR();
+ xs << xml::EndTag("li") << xml::CR();
// is this another sub-sub-entry within the same sub-entry?
if (!eit->same_sub(last)) {
// close this level
- xs << html::EndTag("ul") << html::CR();
+ xs << xml::EndTag("ul") << xml::CR();
level = 2;
}
}
// sub-entry. In that case, we do not want to close anything.
if (level == 2 && !eit->same_sub(last)) {
// close sub-entry
- xs << html::EndTag("li") << html::CR();
+ xs << xml::EndTag("li") << xml::CR();
// is this another sub-entry with the same main entry?
if (!eit->same_main(last)) {
// close this level
- xs << html::EndTag("ul") << html::CR();
+ xs << xml::EndTag("ul") << xml::CR();
level = 1;
}
}
// close the entry.
if (level == 1 && !eit->same_main(last)) {
// close entry
- xs << html::EndTag("li") << html::CR();
+ xs << xml::EndTag("li") << xml::CR();
}
}
// We need to use our own stream, since we will have to
// modify what we get back.
odocstringstream ent;
- XHTMLStream entstream(ent);
+ XMLStream entstream(ent);
OutputParams ours = op;
ours.for_toc = true;
par.simpleLyXHTMLOnePar(buffer(), entstream, ours, dummy);
if (level == 3) {
// another subsubentry
- xs << html::StartTag("li", "class='subsubentry'")
- << XHTMLStream::ESCAPE_NONE << subsub;
+ xs << xml::StartTag("li", "class='subsubentry'")
+ << XMLStream::ESCAPE_NONE << subsub;
} else if (level == 2) {
// there are two ways we can be here:
// (i) we can actually be inside a sub-entry already and be about
// note that in this case, too, though, the sub-entry might already
// have a sub-sub-entry.
if (eit->sub != last.sub)
- xs << html::StartTag("li", "class='subentry'")
- << XHTMLStream::ESCAPE_NONE << sub;
+ xs << xml::StartTag("li", "class='subentry'")
+ << XMLStream::ESCAPE_NONE << sub;
if (!subsub.empty()) {
// it's actually a subsubentry, so we need to start that list
- xs << html::CR()
- << html::StartTag("ul", "class='subsubentry'")
- << html::StartTag("li", "class='subsubentry'")
- << XHTMLStream::ESCAPE_NONE << subsub;
+ xs << xml::CR()
+ << xml::StartTag("ul", "class='subsubentry'")
+ << xml::StartTag("li", "class='subsubentry'")
+ << XMLStream::ESCAPE_NONE << subsub;
level = 3;
}
} else {
// note that in this case, too, though, the main entry might already
// have a sub-entry, or even a sub-sub-entry.
if (eit->main != last.main)
- xs << html::StartTag("li", "class='main'") << main;
+ xs << xml::StartTag("li", "class='main'") << main;
if (!sub.empty()) {
// there's a sub-entry, too
- xs << html::CR()
- << html::StartTag("ul", "class='subentry'")
- << html::StartTag("li", "class='subentry'")
- << XHTMLStream::ESCAPE_NONE << sub;
+ xs << xml::CR()
+ << xml::StartTag("ul", "class='subentry'")
+ << xml::StartTag("li", "class='subentry'")
+ << XMLStream::ESCAPE_NONE << sub;
level = 2;
if (!subsub.empty()) {
// and a sub-sub-entry
- xs << html::CR()
- << html::StartTag("ul", "class='subsubentry'")
- << html::StartTag("li", "class='subsubentry'")
- << XHTMLStream::ESCAPE_NONE << subsub;
+ xs << xml::CR()
+ << xml::StartTag("ul", "class='subsubentry'")
+ << xml::StartTag("li", "class='subsubentry'")
+ << XMLStream::ESCAPE_NONE << subsub;
level = 3;
}
}
// finally, then, we can output the index link itself
string const parattr = "href='#" + par.magicLabel() + "'";
xs << (entry_number == 0 ? ":" : ",");
- xs << " " << html::StartTag("a", parattr)
- << ++entry_number << html::EndTag("a");
+ xs << " " << xml::StartTag("a", parattr)
+ << ++entry_number << xml::EndTag("a");
last = *eit;
}
// now we have to close all the open levels
while (level > 0) {
- xs << html::EndTag("li") << html::EndTag("ul") << html::CR();
+ xs << xml::EndTag("li") << xml::EndTag("ul") << xml::CR();
--level;
}
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
return ods.str();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void latex(otexstream &, OutputParams const &) const;
///
///
void latex(otexstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
#include "LyX.h"
#include "output_xhtml.h"
#include "ParIterator.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "Text.h"
#include "TextClass.h"
}
-int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
+int InsetLabel::docbook(odocstream & os, OutputParams const &) const
{
os << "<!-- anchor id=\""
- << sgml::cleanID(buffer(), runparams, getParam("name"))
+ << xml::cleanID(getParam("name"))
<< "\" -->";
return 0;
}
-docstring InsetLabel::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetLabel::xhtml(XMLStream & xs, OutputParams const &) const
{
// FIXME XHTML
// Unfortunately, the name attribute has been deprecated, so we have to use
// id here to get the document to validate as XHTML 1.1. This will cause a
// problem with some browsers, though, I'm sure. (Guess which!) So we will
// have to figure out what to do about this later.
- docstring const attr = "id=\"" + html::cleanAttr(getParam("name")) + '"';
- xs << html::CompTag("a", to_utf8(attr));
+ docstring const attr = "id=\"" + xml::cleanAttr(getParam("name")) + '"';
+ xs << xml::CompTag("a", to_utf8(attr));
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void updateBuffer(ParIterator const & it, UpdateType, bool const deleted = false);
///
}
-docstring InsetLine::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetLine::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << html::CompTag("hr") << html::CR();
+ xs << xml::CompTag("hr") << xml::CR();
return docstring();
}
InsetCode lyxCode() const { return LINE_CODE; }
int docbook(odocstream &, OutputParams const &) const;
/// Does nothing at the moment.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
bool hasSettings() const { return true; }
void metrics(MetricsInfo &, Dimension &) const;
void draw(PainterInfo & pi, int x, int y) const;
}
-docstring InsetListings::xhtml(XHTMLStream & os, OutputParams const & rp) const
+docstring InsetListings::xhtml(XMLStream & os, OutputParams const & rp) const
{
odocstringstream ods;
- XHTMLStream out(ods);
+ XMLStream out(ods);
bool const isInline = params().isInline();
if (isInline)
- out << html::CompTag("br");
+ out << xml::CompTag("br");
else {
- out << html::StartTag("div", "class='float-listings'");
+ out << xml::StartTag("div", "class='float-listings'");
docstring caption = getCaptionHTML(rp);
if (!caption.empty())
- out << html::StartTag("div", "class='listings-caption'")
- << XHTMLStream::ESCAPE_NONE
- << caption << html::EndTag("div");
+ out << xml::StartTag("div", "class='listings-caption'")
+ << XMLStream::ESCAPE_NONE
+ << caption << xml::EndTag("div");
}
InsetLayout const & il = getLayout();
if (!lang.empty())
attr += " " + lang;
attr += "'";
- out << html::StartTag(tag, attr);
+ out << xml::StartTag(tag, attr);
OutputParams newrp = rp;
newrp.html_disable_captions = true;
// We don't want to convert dashes here. That's the only conversion we
// do for XHTML, so this is safe.
newrp.pass_thru = true;
docstring def = InsetText::insetAsXHTML(out, newrp, InsetText::JustText);
- out << html::EndTag(tag);
+ out << xml::EndTag(tag);
if (isInline) {
- out << html::CompTag("br");
+ out << xml::CompTag("br");
// escaping will already have been done
- os << XHTMLStream::ESCAPE_NONE << ods.str();
+ os << XMLStream::ESCAPE_NONE << ods.str();
} else {
- out << html::EndTag("div");
+ out << xml::EndTag("div");
// In this case, this needs to be deferred, but we'll put it
// before anything the text itself deferred.
def = ods.str() + '\n' + def;
///
void latex(otexstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
}
-docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetNewline::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << html::CR() << html::CompTag("br") << html::CR();
+ xs << xml::CR() << xml::CompTag("br") << xml::CR();
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///
}
-docstring InsetNewpage::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetNewpage::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << html::CompTag("br");
+ xs << xml::CompTag("br");
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///
#include "LyX.h"
#include "OutputParams.h"
#include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
InsetNomencl::InsetNomencl(Buffer * buf, InsetCommandParams const & p)
: InsetCommand(buf, p),
- nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
+ nomenclature_entry_id(xml::uniqueID(from_ascii("nomen")))
{}
int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
{
os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
- << sgml::escapeString(getParam("symbol"))
+ << xml::escapeString(getParam("symbol"))
<< "</glossterm>";
return 0;
}
-docstring InsetNomencl::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetNomencl::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}
{
os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
<< "<glossterm>"
- << sgml::escapeString(getParam("symbol"))
+ << xml::escapeString(getParam("symbol"))
<< "</glossterm>\n"
<< "<glossdef><para>"
- << sgml::escapeString(getParam("description"))
+ << xml::escapeString(getParam("description"))
<< "</para></glossdef>\n"
<<"</glossentry>\n";
return 4;
typedef map<docstring, NomenclEntry > EntryMap;
-docstring InsetPrintNomencl::xhtml(XHTMLStream &, OutputParams const & op) const
+docstring InsetPrintNomencl::xhtml(XMLStream &, OutputParams const & op) const
{
shared_ptr<Toc const> toc = buffer().tocBackend().toc("nomencl");
// that's how we deal with the fact that we're probably inside a standard
// paragraph, and we don't want to be.
odocstringstream ods;
- XHTMLStream xs(ods);
+ XMLStream xs(ods);
InsetLayout const & il = getLayout();
string const & tag = il.htmltag();
docstring toclabel = translateIfPossible(from_ascii("Nomenclature"),
op.local_font->language()->lang());
- xs << html::StartTag("div", "class='nomencl'")
- << html::StartTag(tag, "class='nomencl'")
+ xs << xml::StartTag("div", "class='nomencl'")
+ << xml::StartTag(tag, "class='nomencl'")
<< toclabel
- << html::EndTag(tag)
- << html::CR()
- << html::StartTag("dl")
- << html::CR();
+ << xml::EndTag(tag)
+ << xml::CR()
+ << xml::StartTag("dl")
+ << xml::CR();
EntryMap::const_iterator eit = entries.begin();
EntryMap::const_iterator const een = entries.end();
for (; eit != een; ++eit) {
NomenclEntry const & ne = eit->second;
string const parid = ne.par->magicLabel();
- xs << html::StartTag("dt")
- << html::StartTag("a", "href='#" + parid + "' class='nomencl'")
+ xs << xml::StartTag("dt")
+ << xml::StartTag("a", "href='#" + parid + "' class='nomencl'")
<< ne.symbol
- << html::EndTag("a")
- << html::EndTag("dt")
- << html::CR()
- << html::StartTag("dd")
+ << xml::EndTag("a")
+ << xml::EndTag("dt")
+ << xml::CR()
+ << xml::StartTag("dd")
<< ne.desc
- << html::EndTag("dd")
- << html::CR();
+ << xml::EndTag("dd")
+ << xml::CR();
}
- xs << html::EndTag("dl")
- << html::CR()
- << html::EndTag("div")
- << html::CR();
+ xs << xml::EndTag("dl")
+ << xml::CR()
+ << xml::EndTag("div")
+ << xml::CR();
return ods.str();
}
///
int docbook(odocstream &, OutputParams const &) const;
/// Does nothing at the moment.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
//@}
/// \name Static public methods obligated for InsetCommand derived classes
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
InsetCode lyxCode() const;
///
}
-docstring InsetNote::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetNote::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (params_.type == InsetNoteParams::Note)
return docstring();
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
}
-docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetPhantom::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
/// Makes no sense fof XHTML.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
}
+docstring InsetQuotesParams::getXMLQuote(char_type c) const
+{
+ string res;
+
+ switch (c){
+ case 0x201a: // ,
+ res = "‚";
+ break;
+ case 0x2019: // '
+ res = "’";
+ break;
+ case 0x2018: // `
+ res = "‘";
+ break;
+ case 0x2039: // <
+ res = "‹";
+ break;
+ case 0x203a: // >
+ res = "›";
+ break;
+ case 0x0027: // ' (plain)
+ res = "'";
+ break;
+ case 0x201e: // ,,
+ res = "„";
+ break;
+ case 0x201d: // ''
+ res = "”";
+ break;
+ case 0x201c: // ``
+ res = "“";
+ break;
+ case 0x00ab: // <<
+ res = "«";
+ break;
+ case 0x00bb: // >>
+ res = "»";
+ break;
+ case 0x0022: // "
+ res = """;
+ break;
+ case 0x300c: // LEFT CORNER BRACKET
+ res = "「";
+ break;
+ case 0x300d: // RIGHT CORNER BRACKET
+ res = "」";
+ break;
+ case 0x300e: // LEFT WHITE CORNER BRACKET
+ res = "『";
+ break;
+ case 0x300f: // RIGHT WHITE CORNER BRACKET
+ res = "』";
+ break;
+ case 0x300a: // LEFT DOUBLE ANGLE BRACKET
+ res = "《";
+ break;
+ case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
+ res = "》";
+ break;
+ case 0x3008: // LEFT ANGLE BRACKET
+ res = "〈";
+ break;
+ case 0x3009: // RIGHT ANGLE BRACKET
+ res = "〉";
+ break;
+ default:
+ break;
+ }
+
+ return from_ascii(res);
+}
+
+
map<string, docstring> InsetQuotesParams::getTypes() const
{
map<string, docstring> res;
}
-docstring InsetQuotes::getQuoteEntity() const {
+docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
InsetQuotesParams::QuoteStyle style =
(style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
- docstring res = quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_));
+ docstring res = isHTML ? quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_)) :
+ quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
// in French, thin spaces are added inside double guillemets
if (prefixIs(context_lang_, "fr")
&& level_ == InsetQuotesParams::PrimaryQuotes
int InsetQuotes::docbook(odocstream & os, OutputParams const &) const
{
- os << getQuoteEntity();
+ os << getQuoteEntity(false);
return 0;
}
-docstring InsetQuotes::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetQuotes::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << XHTMLStream::ESCAPE_NONE << getQuoteEntity();
+ xs << XMLStream::ESCAPE_NONE << getQuoteEntity(true);
return docstring();
}
bool const rtl = false) const;
///
docstring getHTMLQuote(char_type c) const;
+ ///
+ docstring getXMLQuote(char_type c) const;
/// Returns a descriptive label of a style suitable for dialog and menu
docstring const getGuiLabel(QuoteStyle const & qs,
bool langdef = false);
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
docstring displayString() const;
///
- docstring getQuoteEntity() const;
+ docstring getQuoteEntity(bool isHTML) const;
///
InsetQuotesParams::QuoteStyle getStyle(std::string const &);
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParIterator.h"
-#include "sgml.h"
+#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
if (name.empty()) {
if (runparams.flavor == OutputParams::XML) {
os << "<xref linkend=\""
- << sgml::cleanID(buffer(), runparams, getParam("reference"))
+ << xml::cleanID(getParam("reference"))
<< "\" />";
} else {
os << "<xref linkend=\""
- << sgml::cleanID(buffer(), runparams, getParam("reference"))
+ << xml::cleanID(getParam("reference"))
<< "\">";
}
} else {
os << "<link linkend=\""
- << sgml::cleanID(buffer(), runparams, getParam("reference"))
+ << xml::cleanID(getParam("reference"))
<< "\">"
<< getParam("name")
<< "</link>";
}
-docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const & op) const
+docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
{
docstring const & ref = getParam("reference");
InsetLabel const * il = buffer().insetLabel(ref, true);
// FIXME What we'd really like to do is to be able to output some
// appropriate sort of text here. But to do that, we need to associate
// some sort of counter with the label, and we don't have that yet.
- docstring const attr = "href=\"#" + html::cleanAttr(ref) + '"';
- xs << html::StartTag("a", to_utf8(attr));
+ docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"';
+ xs << xml::StartTag("a", to_utf8(attr));
xs << display_string;
- xs << html::EndTag("a");
+ xs << xml::EndTag("a");
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
}
-docstring InsetSeparator::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetSeparator::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << html::CR() << html::CompTag("br") << html::CR();
+ xs << xml::CR() << xml::CompTag("br") << xml::CR();
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///
}
-docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetSpace::xhtml(XMLStream & xs, OutputParams const &) const
{
string output;
switch (params_.kind) {
break;
}
// don't escape the entities!
- xs << XHTMLStream::ESCAPE_NONE << from_ascii(output);
+ xs << XMLStream::ESCAPE_NONE << from_ascii(output);
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures & features) const;
///
}
-docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetSpecialChar::xhtml(XMLStream & xs, OutputParams const &) const
{
switch (kind_) {
case HYPHENATION:
break;
case ALLOWBREAK:
- xs << XHTMLStream::ESCAPE_NONE << "​";
+ xs << XMLStream::ESCAPE_NONE << "​";
break;
case LIGATURE_BREAK:
- xs << XHTMLStream::ESCAPE_NONE << "‌";
+ xs << XMLStream::ESCAPE_NONE << "‌";
break;
case END_OF_SENTENCE:
xs << '.';
break;
case LDOTS:
- xs << XHTMLStream::ESCAPE_NONE << "…";
+ xs << XMLStream::ESCAPE_NONE << "…";
break;
case MENU_SEPARATOR:
- xs << XHTMLStream::ESCAPE_NONE << "⇒";
+ xs << XMLStream::ESCAPE_NONE << "⇒";
break;
case SLASH:
- xs << XHTMLStream::ESCAPE_NONE << "⁄";
+ xs << XMLStream::ESCAPE_NONE << "⁄";
break;
case NOBREAKDASH:
- xs << XHTMLStream::ESCAPE_NONE << "‑";
+ xs << XMLStream::ESCAPE_NONE << "‑";
break;
case PHRASE_LYX:
xs << "LyX";
xs << "TeX";
break;
case PHRASE_LATEX2E:
- xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "ε";
+ xs << "LaTeX2" << XMLStream::ESCAPE_NONE << "ε";
break;
case PHRASE_LATEX:
xs << "LaTeX";
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///
}
-void InsetTOC::makeTOCEntry(XHTMLStream & xs,
+void InsetTOC::makeTOCEntry(XMLStream & xs,
Paragraph const & par, OutputParams const & op) const
{
string const attr = "href='#" + par.magicLabel() + "' class='tocentry'";
- xs << html::StartTag("a", attr);
+ xs << xml::StartTag("a", attr);
// First the label, if there is one
docstring const & label = par.params().labelString();
Font const dummy;
par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy);
- xs << html::EndTag("a") << html::CR();
+ xs << xml::EndTag("a") << xml::CR();
}
-void InsetTOC::makeTOCWithDepth(XHTMLStream & xs,
+void InsetTOC::makeTOCWithDepth(XMLStream & xs,
Toc const & toc, OutputParams const & op) const
{
Toc::const_iterator it = toc.begin();
continue;
if (depth > lastdepth) {
- xs << html::CR();
+ xs << xml::CR();
// open as many tags as we need to open to get to this level
// this includes the tag for the current level
for (int i = lastdepth + 1; i <= depth; ++i) {
stringstream attr;
attr << "class='lyxtoc-" << i << "'";
- xs << html::StartTag("div", attr.str()) << html::CR();
+ xs << xml::StartTag("div", attr.str()) << xml::CR();
}
lastdepth = depth;
}
// close as many as we have to close to get back to this level
// this includes closing the last tag at this level
for (int i = lastdepth; i >= depth; --i)
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
// now open our tag
stringstream attr;
attr << "class='lyxtoc-" << depth << "'";
- xs << html::StartTag("div", attr.str()) << html::CR();
+ xs << xml::StartTag("div", attr.str()) << xml::CR();
lastdepth = depth;
} else {
// no change of level, so close and open
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
stringstream attr;
attr << "class='lyxtoc-" << depth << "'";
- xs << html::StartTag("div", attr.str()) << html::CR();
+ xs << xml::StartTag("div", attr.str()) << xml::CR();
}
// Now output TOC info for this entry
makeTOCEntry(xs, par, op);
}
for (int i = lastdepth; i > 0; --i)
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
}
-void InsetTOC::makeTOCNoDepth(XHTMLStream & xs,
+void InsetTOC::makeTOCNoDepth(XMLStream & xs,
Toc const & toc, const OutputParams & op) const
{
Toc::const_iterator it = toc.begin();
if (!it->isOutput())
continue;
- xs << html::StartTag("div", "class='lyxtoc-flat'") << html::CR();
+ xs << xml::StartTag("div", "class='lyxtoc-flat'") << xml::CR();
Paragraph const & par = it->dit().innerParagraph();
makeTOCEntry(xs, par, op);
- xs << html::EndTag("div");
+ xs << xml::EndTag("div");
}
}
-docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
+docstring InsetTOC::xhtml(XMLStream &, OutputParams const & op) const
{
string const & command = getCmdName();
if (command != "tableofcontents" && command != "lstlistoflistings") {
// that's how we deal with the fact that we're probably inside a standard
// paragraph, and we don't want to be.
odocstringstream ods;
- XHTMLStream xs(ods);
+ XMLStream xs(ods);
- xs << html::StartTag("div", "class='toc'");
+ xs << xml::StartTag("div", "class='toc'");
// Title of TOC
InsetLayout const & il = getLayout();
Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
string const & tocclass = lay.defaultCSSClass();
string const tocattr = "class='tochead " + tocclass + "'";
- xs << html::StartTag(tag, tocattr)
+ xs << xml::StartTag(tag, tocattr)
<< title
- << html::EndTag(tag);
+ << xml::EndTag(tag);
// with lists of listings, at least, there is no depth
// to worry about. so the code can be simpler.
else
makeTOCNoDepth(xs, *toc, op);
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
return ods.str();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream & xs, OutputParams const &) const;
+ docstring xhtml(XMLStream & xs, OutputParams const &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
private:
///
- void makeTOCWithDepth(XHTMLStream & xs, Toc const & toc, const OutputParams & op) const;
+ void makeTOCWithDepth(XMLStream & xs, Toc const & toc, const OutputParams & op) const;
///
- void makeTOCNoDepth(XHTMLStream & xs, Toc const & toc, const OutputParams & op) const;
+ void makeTOCNoDepth(XMLStream & xs, Toc const & toc, const OutputParams & op) const;
///
- void makeTOCEntry(XHTMLStream & xs, Paragraph const & par, OutputParams const & op) const;
+ void makeTOCEntry(XMLStream & xs, Paragraph const & par, OutputParams const & op) const;
/// \name Private functions inherited from Inset class
//@{
}
-docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
+docstring Tabular::xhtmlRow(XMLStream & xs, row_type row,
OutputParams const & runparams, bool header) const
{
docstring ret;
string const celltag = header ? "th" : "td";
idx_type cell = getFirstCellInRow(row);
- xs << html::StartTag("tr");
+ xs << xml::StartTag("tr");
for (col_type c = 0; c < ncols(); ++c) {
if (isPartOfMultiColumn(row, c) || isPartOfMultiRow(row, c))
continue;
else if (isMultiRow(cell))
attr << " rowspan='" << rowSpan(cell) << "'";
- xs << html::StartTag(celltag, attr.str(), true) << html::CR();
+ xs << xml::StartTag(celltag, attr.str(), true) << xml::CR();
ret += cellInset(cell)->xhtml(xs, runparams);
- xs << html::EndTag(celltag) << html::CR();
+ xs << xml::EndTag(celltag) << xml::CR();
++cell;
}
- xs << html::EndTag("tr");
+ xs << xml::EndTag("tr");
return ret;
}
-docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
+docstring Tabular::xhtml(XMLStream & xs, OutputParams const & runparams) const
{
docstring ret;
align = "right";
break;
}
- xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'")
- << html::CR();
+ xs << xml::StartTag("div", "class='longtable' style='text-align: " + align + ";'")
+ << xml::CR();
// The caption flag wins over head/foot
if (haveLTCaption()) {
- xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'")
- << html::CR();
+ xs << xml::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'")
+ << xml::CR();
for (row_type r = 0; r < nrows(); ++r)
if (row_info[r].caption)
ret += xhtmlRow(xs, r, runparams);
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
}
}
- xs << html::StartTag("table") << html::CR();
+ xs << xml::StartTag("table") << xml::CR();
// output header info
bool const havefirsthead = haveLTFirstHead(false);
// in XHTML. this test accomplishes that.
bool const havehead = !havefirsthead && haveLTHead(false);
if (havehead || havefirsthead) {
- xs << html::StartTag("thead") << html::CR();
+ xs << xml::StartTag("thead") << xml::CR();
for (row_type r = 0; r < nrows(); ++r) {
if (((havefirsthead && row_info[r].endfirsthead) ||
(havehead && row_info[r].endhead)) &&
ret += xhtmlRow(xs, r, runparams, true);
}
}
- xs << html::EndTag("thead") << html::CR();
+ xs << xml::EndTag("thead") << xml::CR();
}
// output footer info
bool const havelastfoot = haveLTLastFoot(false);
// as before.
bool const havefoot = !havelastfoot && haveLTFoot(false);
if (havefoot || havelastfoot) {
- xs << html::StartTag("tfoot") << html::CR();
+ xs << xml::StartTag("tfoot") << xml::CR();
for (row_type r = 0; r < nrows(); ++r) {
if (((havelastfoot && row_info[r].endlastfoot) ||
(havefoot && row_info[r].endfoot)) &&
ret += xhtmlRow(xs, r, runparams);
}
}
- xs << html::EndTag("tfoot") << html::CR();
+ xs << xml::EndTag("tfoot") << xml::CR();
}
- xs << html::StartTag("tbody") << html::CR();
+ xs << xml::StartTag("tbody") << xml::CR();
for (row_type r = 0; r < nrows(); ++r) {
if (isValidRow(r)) {
ret += xhtmlRow(xs, r, runparams);
}
}
- xs << html::EndTag("tbody")
- << html::CR()
- << html::EndTag("table")
- << html::CR();
+ xs << xml::EndTag("tbody")
+ << xml::CR()
+ << xml::EndTag("table")
+ << xml::CR();
if (is_long_tabular)
- xs << html::EndTag("div") << html::CR();
+ xs << xml::EndTag("div") << xml::CR();
return ret;
}
}
-docstring InsetTableCell::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetTableCell::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (!isFixedWidth)
return InsetText::insetAsXHTML(xs, rp, InsetText::JustText);
}
-
/////////////////////////////////////////////////////////////////////
//
// InsetTabular
}
-docstring InsetTabular::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetTabular::xhtml(XMLStream & xs, OutputParams const & rp) const
{
return tabular.xhtml(xs, rp);
}
class Lexer;
class OutputParams;
class Paragraph;
-class XHTMLStream;
+class XMLStream;
///
/// descending into insets
docstring asString(bool intoInsets = true);
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void addToToc(DocIterator const & di, bool output_active,
UpdateType utype, TocBackend & backend) const;
///
int docbook(odocstream & os, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream & os, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void plaintext(odocstringstream &,
OutputParams const & runparams, int const depth,
/// auxiliary function for docbook
int docbookRow(odocstream & os, row_type, OutputParams const &) const;
///
- docstring xhtmlRow(XHTMLStream & xs, row_type, OutputParams const &,
+ docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &,
bool header = false) const;
/// change associated Buffer
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures & features) const;
///
#include "ParagraphParameters.h"
#include "ParIterator.h"
#include "Row.h"
-#include "sgml.h"
+#include "xml.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
ParagraphList::const_iterator const beg = paragraphs().begin();
if (!undefined())
- sgml::openTag(os, getLayout().latexname(),
+ xml::openTag(os, getLayout().latexname(),
beg->getID(buffer(), runparams) + getLayout().latexparam());
docbookParagraphs(text_, buffer(), os, runparams);
if (!undefined())
- sgml::closeTag(os, getLayout().latexname());
+ xml::closeTag(os, getLayout().latexname());
return 0;
}
-docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
+docstring InsetText::xhtml(XMLStream & xs, OutputParams const & runparams) const
{
return insetAsXHTML(xs, runparams, WriteEverything);
}
// if so, try to close fonts, etc.
// There are probably limits to how well we can do here, though, and we will
// have to rely upon users not putting footnotes inside noun-type insets.
-docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
+docstring InsetText::insetAsXHTML(XMLStream & xs, OutputParams const & rp,
XHTMLOptions opts) const
{
// we will always want to output all our paragraphs when we are
InsetLayout const & il = getLayout();
if (opts & WriteOuterTag)
- xs << html::StartTag(il.htmltag(), il.htmlattr());
+ xs << xml::StartTag(il.htmltag(), il.htmlattr());
if ((opts & WriteLabel) && !il.counter().empty()) {
BufferParams const & bp = buffer().masterBuffer()->params();
cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
// FIXME is this check necessary?
if (!lbl.empty()) {
- xs << html::StartTag(il.htmllabeltag(), il.htmllabelattr());
+ xs << xml::StartTag(il.htmllabeltag(), il.htmllabelattr());
xs << lbl;
- xs << html::EndTag(il.htmllabeltag());
+ xs << xml::EndTag(il.htmllabeltag());
}
}
}
if (opts & WriteInnerTag)
- xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
+ xs << xml::StartTag(il.htmlinnertag(), il.htmlinnerattr());
// we will eventually lose information about the containing inset
if (!allowMultiPar() || opts == JustText)
xs.endDivision();
if (opts & WriteInnerTag)
- xs << html::EndTag(il.htmlinnertag());
+ xs << xml::EndTag(il.htmlinnertag());
if (opts & WriteOuterTag)
- xs << html::EndTag(il.htmltag());
+ xs << xml::EndTag(il.htmltag());
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
enum XHTMLOptions {
JustText = 0,
WriteEverything = 7
};
///
- docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
+ docstring insetAsXHTML(XMLStream &, OutputParams const &,
XHTMLOptions) const;
///
void validate(LaTeXFeatures & features) const;
}
-docstring InsetVSpace::xhtml(XHTMLStream & os, OutputParams const &) const
+docstring InsetVSpace::xhtml(XMLStream & os, OutputParams const &) const
{
string const len = space_.asHTMLLength();
string const attr = "style='height:" + (len.empty() ? "1em" : len) + "'";
- os << html::StartTag("div", attr, true) << html::EndTag("div");
+ os << xml::StartTag("div", attr, true) << xml::EndTag("div");
return docstring();
}
/// The normal case is that this inset will be on a line by
/// itself, and in that case the present paragraph will not,
/// in fact, appear at all.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///
}
-docstring InsetWrap::xhtml(XHTMLStream & xs, OutputParams const & rp) const
+docstring InsetWrap::xhtml(XMLStream & xs, OutputParams const & rp) const
{
string const len = params_.width.asHTMLString();
string const width = len.empty() ? "50%" : len;
InsetLayout const & il = getLayout();
string const & tag = il.htmltag();
string const attr = il.htmlattr() + " style='width:" + width + ";'";
- xs << html::StartTag(tag, attr);
+ xs << xml::StartTag(tag, attr);
docstring const deferred =
InsetText::insetAsXHTML(xs, rp, InsetText::WriteInnerTag);
- xs << html::EndTag(tag);
+ xs << xml::EndTag(tag);
return deferred;
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
bool insetAllowed(InsetCode) const;
///
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParIterator.h"
-#include "sgml.h"
+#include "xml.h"
#include "TexRow.h"
#include "TextClass.h"
#include "TextPainter.h"
docstring bname = name;
if (!label(0).empty())
- bname += " id='" + sgml::cleanID(buffer(), runparams, label(0)) + "'";
+ bname += " id='" + xml::cleanID(label(0)) + "'";
++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
ms << from_ascii("<graphic fileref=\"eqn/");
if (!label(0).empty())
- ms << sgml::cleanID(buffer(), runparams, label(0));
+ ms << xml::cleanID(label(0));
else
- ms << sgml::uniqueID(from_ascii("anon"));
+ ms << xml::uniqueID(from_ascii("anon"));
if (runparams.flavor == OutputParams::XML)
ms << from_ascii("\"/>");
}
-docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
+docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const
{
BufferParams::MathOutput const mathtype =
buffer().masterBuffer()->params().html_math_output;
} catch (MathExportException const &) {}
if (success) {
if (getType() == hullSimple)
- xs << html::StartTag("math",
+ xs << xml::StartTag("math",
"xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
else
- xs << html::StartTag("math",
+ xs << xml::StartTag("math",
"display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
- xs << XHTMLStream::ESCAPE_NONE
+ xs << XMLStream::ESCAPE_NONE
<< os.str()
- << html::EndTag("math");
+ << xml::EndTag("math");
}
} else if (mathtype == BufferParams::HTML) {
odocstringstream os;
} catch (MathExportException const &) {}
if (success) {
string const tag = (getType() == hullSimple) ? "span" : "div";
- xs << html::StartTag(tag, "class='formula'", true)
- << XHTMLStream::ESCAPE_NONE
+ xs << xml::StartTag(tag, "class='formula'", true)
+ << XMLStream::ESCAPE_NONE
<< os.str()
- << html::EndTag(tag);
+ << xml::EndTag(tag);
}
}
}
string const tag = (getType() == hullSimple) ? "span" : "div";
- xs << html::CR()
- << html::StartTag(tag, "style = \"text-align: center;\"")
- << html::CompTag("img", "src=\"" + filename + "\" alt=\"Mathematical Equation\"")
- << html::EndTag(tag)
- << html::CR();
+ xs << xml::CR()
+ << xml::StartTag(tag, "style = \"text-align: center;\"")
+ << xml::CompTag("img", "src=\"" + filename + "\" alt=\"Mathematical Equation\"")
+ << xml::EndTag(tag)
+ << xml::CR();
success = true;
}
}
// FIXME XHTML
// probably should allow for some kind of customization here
string const tag = (getType() == hullSimple) ? "span" : "div";
- xs << html::StartTag(tag, "class='math'")
+ xs << xml::StartTag(tag, "class='math'")
<< latex
- << html::EndTag(tag)
- << html::CR();
+ << xml::EndTag(tag)
+ << xml::CR();
}
return docstring();
}
///
int docbook(odocstream &, OutputParams const &) const;
///
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
void mathmlize(MathStream &) const;
///
}
-docstring InsetMathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetMathMacroTemplate::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}
namespace lyx {
class OutputParams;
-class XHTMLStream;
+class XMLStream;
/// This class contains the macro definition.
class InsetMathMacroTemplate : public InsetMathNest {
/// if overwriteRedefinition is true
int write(WriteStream & os, bool overwriteRedefinition) const;
/// Nothing happens. This is simply to suppress the default output.
- docstring xhtml(XHTMLStream &, OutputParams const &) const;
+ docstring xhtml(XMLStream &, OutputParams const &) const;
///
int plaintext(odocstringstream &, OutputParams const &, size_t) const;
///
#include "MathSupport.h"
#include "OutputParams.h"
#include "ParIterator.h"
-#include "sgml.h"
+#include "xml.h"
#include "insets/InsetCommand.h"
{
if (cell(1).empty()) {
os << "<xref linkend=\""
- << sgml::cleanID(buffer(), runparams, asString(cell(0)));
+ << xml::cleanID(asString(cell(0)));
if (runparams.flavor == OutputParams::XML)
os << "\"/>";
else
os << "\">";
} else {
os << "<link linkend=\""
- << sgml::cleanID(buffer(), runparams, asString(cell(0)))
+ << xml::cleanID(asString(cell(0)))
<< "\">"
<< asString(cell(1))
<< "</link>";
#include "Paragraph.h"
#include "ParagraphList.h"
#include "ParagraphParameters.h"
-#include "sgml.h"
+#include "xml.h"
#include "Text.h"
#include "TextClass.h"
namespace {
+std::string const fontToDocBookTag(xml::FontTypes type) {
+ switch (type) {
+ case xml::FontTypes::FT_EMPH:
+ case xml::FontTypes::FT_BOLD:
+ return "emphasis";
+ case xml::FontTypes::FT_NOUN:
+ return "person";
+ case xml::FontTypes::FT_UBAR:
+ case xml::FontTypes::FT_WAVE:
+ case xml::FontTypes::FT_DBAR:
+ case xml::FontTypes::FT_SOUT:
+ case xml::FontTypes::FT_XOUT:
+ case xml::FontTypes::FT_ITALIC:
+ case xml::FontTypes::FT_UPRIGHT:
+ case xml::FontTypes::FT_SLANTED:
+ case xml::FontTypes::FT_SMALLCAPS:
+ case xml::FontTypes::FT_ROMAN:
+ case xml::FontTypes::FT_SANS:
+ return "emphasis";
+ case xml::FontTypes::FT_TYPE:
+ return "code";
+ case xml::FontTypes::FT_SIZE_TINY:
+ case xml::FontTypes::FT_SIZE_SCRIPT:
+ case xml::FontTypes::FT_SIZE_FOOTNOTE:
+ case xml::FontTypes::FT_SIZE_SMALL:
+ case xml::FontTypes::FT_SIZE_NORMAL:
+ case xml::FontTypes::FT_SIZE_LARGE:
+ case xml::FontTypes::FT_SIZE_LARGER:
+ case xml::FontTypes::FT_SIZE_LARGEST:
+ case xml::FontTypes::FT_SIZE_HUGE:
+ case xml::FontTypes::FT_SIZE_HUGER:
+ case xml::FontTypes::FT_SIZE_INCREASE:
+ case xml::FontTypes::FT_SIZE_DECREASE:
+ return "emphasis";
+ default:
+ return "";
+ }
+}
+
ParagraphList::const_iterator searchParagraph(
ParagraphList::const_iterator p,
ParagraphList::const_iterator const & pend)
par->simpleDocBookOnePar(buf, os, runparams,
text.outerFont(distance(paragraphs.begin(), par)));
} else {
- sgml::openTag(buf, os, runparams, *par);
+ xml::openTag(buf, os, runparams, *par);
par->simpleDocBookOnePar(buf, os, runparams,
text.outerFont(distance(paragraphs.begin(), par)));
- sgml::closeTag(os, *par);
+ xml::closeTag(os, *par);
}
}
return pend;
Layout const & bstyle = par->layout();
// Opening outter tag
- sgml::openTag(buf, os, runparams, *pbegin);
+ xml::openTag(buf, os, runparams, *pbegin);
os << '\n';
if (bstyle.latextype == LATEX_ENVIRONMENT && bstyle.pass_thru)
os << "<![CDATA[";
switch (bstyle.latextype) {
case LATEX_ENVIRONMENT:
if (!bstyle.innertag().empty()) {
- sgml::openTag(os, bstyle.innertag(), id);
+ xml::openTag(os, bstyle.innertag(), id);
}
break;
case LATEX_ITEM_ENVIRONMENT:
if (!bstyle.labeltag().empty()) {
- sgml::openTag(os, bstyle.innertag(), id);
- sgml::openTag(os, bstyle.labeltag());
+ xml::openTag(os, bstyle.innertag(), id);
+ xml::openTag(os, bstyle.labeltag());
sep = par->firstWordDocBook(os, runparams) + 1;
- sgml::closeTag(os, bstyle.labeltag());
+ xml::closeTag(os, bstyle.labeltag());
}
wrapper = defaultstyle.latexname();
// If a sub list (embedded list) appears next with a
// different depth, then there is no need to open
// another tag at the current depth.
if(par->params().depth() == pbegin->params().depth()) {
- sgml::openTag(os, bstyle.itemtag());
+ xml::openTag(os, bstyle.itemtag());
}
break;
default:
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT: {
if (par->params().depth() == pbegin->params().depth()) {
- sgml::openTag(os, wrapper);
+ xml::openTag(os, wrapper);
par->simpleDocBookOnePar(buf, os, runparams,
text.outerFont(distance(paragraphs.begin(), par)), sep);
- sgml::closeTag(os, wrapper);
+ xml::closeTag(os, wrapper);
++par;
}
else {
switch (bstyle.latextype) {
case LATEX_ENVIRONMENT:
if (!bstyle.innertag().empty()) {
- sgml::closeTag(os, bstyle.innertag());
+ xml::closeTag(os, bstyle.innertag());
os << '\n';
}
break;
// when par == pend but at the same time that the
// current tag is closed.
if((par != pend && par->params().depth() == pbegin->params().depth()) || par == pend) {
- sgml::closeTag(os, bstyle.itemtag());
+ xml::closeTag(os, bstyle.itemtag());
}
if (!bstyle.labeltag().empty())
- sgml::closeTag(os, bstyle.innertag());
+ xml::closeTag(os, bstyle.innertag());
break;
default:
break;
os << "]]>";
// Closing outer tag
- sgml::closeTag(os, *pbegin);
+ xml::closeTag(os, *pbegin);
return pend;
}
Layout const & bstyle = par->layout();
//Open outter tag
- sgml::openTag(buf, os, runparams, *pbegin);
+ xml::openTag(buf, os, runparams, *pbegin);
os << '\n';
// Label around sectioning number:
if (!bstyle.labeltag().empty()) {
- sgml::openTag(os, bstyle.labeltag());
+ xml::openTag(os, bstyle.labeltag());
// We don't care about appendix in DOCBOOK.
os << par->expandDocBookLabel(bstyle, buf.params());
- sgml::closeTag(os, bstyle.labeltag());
+ xml::closeTag(os, bstyle.labeltag());
}
// Opend inner tag and close inner tags
- sgml::openTag(os, bstyle.innertag());
+ xml::openTag(os, bstyle.innertag());
par->simpleDocBookOnePar(buf, os, runparams,
text.outerFont(distance(paragraphs.begin(), par)));
- sgml::closeTag(os, bstyle.innertag());
+ xml::closeTag(os, bstyle.innertag());
os << '\n';
++par;
}
}
// Close outter tag
- sgml::closeTag(os, *pbegin);
+ xml::closeTag(os, *pbegin);
return pend;
}
#define OUTPUT_DOCBOOK_H
#include "support/strfwd.h"
+#include "xml.h"
namespace lyx {
+std::string const fontToDocBookTag(xml::FontTypes type);
+
class Buffer;
class OutputParams;
class Text;
#include "Paragraph.h"
#include "ParagraphList.h"
#include "ParagraphParameters.h"
-#include "sgml.h"
+#include "xml.h"
#include "Text.h"
#include "TextClass.h"
namespace lyx {
-namespace html {
-docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e)
-{
- docstring str;
- switch (e) {
- case XHTMLStream::ESCAPE_NONE:
- str += c;
- break;
- case XHTMLStream::ESCAPE_ALL:
- if (c == '<') {
- str += "<";
- break;
- } else if (c == '>') {
- str += ">";
- break;
- }
- // fall through
- case XHTMLStream::ESCAPE_AND:
- if (c == '&')
- str += "&";
- else
- str +=c ;
- break;
- }
- return str;
-}
-
-
-// escape what needs escaping
-docstring htmlize(docstring const & str, XHTMLStream::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, XHTMLStream::EscapeSettings e)
-{
- LATTEST(static_cast<unsigned char>(c) < 0x80);
- return escapeChar(static_cast<char_type>(c), e);
-}
-
-
-docstring cleanAttr(docstring const & str)
-{
- docstring newname;
- docstring::const_iterator it = str.begin();
- docstring::const_iterator en = str.end();
- for (; it != en; ++it) {
- char_type const c = *it;
- newname += isAlnumASCII(c) ? c : char_type('_');
- }
- return newname;
-}
-
-
-docstring StartTag::writeTag() const
-{
- docstring output = '<' + from_utf8(tag_);
- if (!attr_.empty())
- output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE);
- output += ">";
- return output;
+docstring const & fontToHtmlTag(xml::FontTypes type)
+{
+ switch(type) {
+ case xml::FontTypes::FT_EMPH:
+ return from_utf8("em");
+ case xml::FontTypes::FT_BOLD:
+ return from_utf8("b");
+ case xml::FontTypes::FT_NOUN:
+ return from_utf8("dfn");
+ case xml::FontTypes::FT_UBAR:
+ case xml::FontTypes::FT_WAVE:
+ case xml::FontTypes::FT_DBAR:
+ return from_utf8("u");
+ case xml::FontTypes::FT_SOUT:
+ case xml::FontTypes::FT_XOUT:
+ return from_utf8("del");
+ case xml::FontTypes::FT_ITALIC:
+ return from_utf8("i");
+ case xml::FontTypes::FT_UPRIGHT:
+ case xml::FontTypes::FT_SLANTED:
+ case xml::FontTypes::FT_SMALLCAPS:
+ case xml::FontTypes::FT_ROMAN:
+ case xml::FontTypes::FT_SANS:
+ case xml::FontTypes::FT_TYPE:
+ case xml::FontTypes::FT_SIZE_TINY:
+ case xml::FontTypes::FT_SIZE_SCRIPT:
+ case xml::FontTypes::FT_SIZE_FOOTNOTE:
+ case xml::FontTypes::FT_SIZE_SMALL:
+ case xml::FontTypes::FT_SIZE_NORMAL:
+ case xml::FontTypes::FT_SIZE_LARGE:
+ case xml::FontTypes::FT_SIZE_LARGER:
+ case xml::FontTypes::FT_SIZE_LARGEST:
+ case xml::FontTypes::FT_SIZE_HUGE:
+ case xml::FontTypes::FT_SIZE_HUGER:
+ case xml::FontTypes::FT_SIZE_INCREASE:
+ case xml::FontTypes::FT_SIZE_DECREASE:
+ return from_utf8("span");
+ }
+ // kill warning
+ return docstring();
}
-docstring StartTag::writeEndTag() const
-{
- string output = "</" + tag_ + ">";
- return from_utf8(output);
-}
-
-
-bool StartTag::operator==(FontTag const & rhs) const
-{
- return rhs == *this;
-}
-
-
-docstring EndTag::writeEndTag() const
-{
- string output = "</" + tag_ + ">";
- return from_utf8(output);
-}
-
-
-ParTag::ParTag(std::string const & tag, std::string attr,
- std::string const & parid)
- : StartTag(tag)
-{
- if (!parid.empty())
- attr += " id='" + parid + "'";
- attr_ = attr;
-}
-
-
-docstring CompTag::writeTag() const
-{
- docstring output = '<' + from_utf8(tag_);
- if (!attr_.empty())
- output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE);
- output += " />";
- return output;
-}
-
-
-
namespace {
-string fontToTag(html::FontTypes type)
+string fontToAttribute(xml::FontTypes type)
{
switch(type) {
- case FT_EMPH:
- return "em";
- case FT_BOLD:
- return "b";
- case FT_NOUN:
- return "dfn";
- case FT_UBAR:
- case FT_WAVE:
- case FT_DBAR:
- return "u";
- case FT_SOUT:
- case FT_XOUT:
- return "del";
- case FT_ITALIC:
- return "i";
- case FT_UPRIGHT:
- case FT_SLANTED:
- case FT_SMALLCAPS:
- case FT_ROMAN:
- case FT_SANS:
- case FT_TYPE:
- case FT_SIZE_TINY:
- case FT_SIZE_SCRIPT:
- case FT_SIZE_FOOTNOTE:
- case FT_SIZE_SMALL:
- case FT_SIZE_NORMAL:
- case FT_SIZE_LARGE:
- case FT_SIZE_LARGER:
- case FT_SIZE_LARGEST:
- case FT_SIZE_HUGE:
- case FT_SIZE_HUGER:
- case FT_SIZE_INCREASE:
- case FT_SIZE_DECREASE:
- return "span";
- }
- // kill warning
- return "";
-}
-
-string fontToAttribute(html::FontTypes type)
-{
- switch(type) {
- case FT_EMPH:
- case FT_BOLD:
+ case xml::FontTypes::FT_EMPH:
+ case xml::FontTypes::FT_BOLD:
return "";
- case FT_NOUN:
+ case xml::FontTypes::FT_NOUN:
return "class='lyxnoun'";
- case FT_UBAR:
+ case xml::FontTypes::FT_UBAR:
return "";
- case FT_DBAR:
+ case xml::FontTypes::FT_DBAR:
return "class='dline'";
- case FT_XOUT:
- case FT_SOUT:
+ case xml::FontTypes::FT_XOUT:
+ case xml::FontTypes::FT_SOUT:
return "class='strikeout'";
- case FT_WAVE:
+ case xml::FontTypes::FT_WAVE:
return "class='wline'";
- case FT_ITALIC:
+ case xml::FontTypes::FT_ITALIC:
return "";
- case FT_UPRIGHT:
+ case xml::FontTypes::FT_UPRIGHT:
return "style='font-style:normal;'";
- case FT_SLANTED:
+ case xml::FontTypes::FT_SLANTED:
return "style='font-style:oblique;'";
- case FT_SMALLCAPS:
+ case xml::FontTypes::FT_SMALLCAPS:
return "style='font-variant:small-caps;'";
- case FT_ROMAN:
+ case xml::FontTypes::FT_ROMAN:
return "style='font-family:serif;'";
- case FT_SANS:
+ case xml::FontTypes::FT_SANS:
return "style='font-family:sans-serif;'";
- case FT_TYPE:
+ case xml::FontTypes::FT_TYPE:
return "style='font-family:monospace;'";
- case FT_SIZE_TINY:
- case FT_SIZE_SCRIPT:
- case FT_SIZE_FOOTNOTE:
+ case xml::FontTypes::FT_SIZE_TINY:
+ case xml::FontTypes::FT_SIZE_SCRIPT:
+ case xml::FontTypes::FT_SIZE_FOOTNOTE:
return "style='font-size:x-small;'";
- case FT_SIZE_SMALL:
+ case xml::FontTypes::FT_SIZE_SMALL:
return "style='font-size:small;'";
- case FT_SIZE_NORMAL:
+ case xml::FontTypes::FT_SIZE_NORMAL:
return "style='font-size:normal;'";
- case FT_SIZE_LARGE:
+ case xml::FontTypes::FT_SIZE_LARGE:
return "style='font-size:large;'";
- case FT_SIZE_LARGER:
- case FT_SIZE_LARGEST:
+ case xml::FontTypes::FT_SIZE_LARGER:
+ case xml::FontTypes::FT_SIZE_LARGEST:
return "style='font-size:x-large;'";
- case FT_SIZE_HUGE:
- case FT_SIZE_HUGER:
+ case xml::FontTypes::FT_SIZE_HUGE:
+ case xml::FontTypes::FT_SIZE_HUGER:
return "style='font-size:xx-large;'";
- case FT_SIZE_INCREASE:
+ case xml::FontTypes::FT_SIZE_INCREASE:
return "style='font-size:larger;'";
- case FT_SIZE_DECREASE:
+ case xml::FontTypes::FT_SIZE_DECREASE:
return "style='font-size:smaller;'";
}
// kill warning
} // end anonymous namespace
-FontTag::FontTag(FontTypes type)
- : StartTag(fontToTag(type), fontToAttribute(type)), font_type_(type)
-{}
-
-
-bool FontTag::operator==(StartTag const & tag) const
-{
- FontTag const * const ftag = tag.asFontTag();
- if (!ftag)
- return false;
- return (font_type_ == ftag->font_type_);
-}
-
-
-EndFontTag::EndFontTag(FontTypes type)
- : EndTag(fontToTag(type)), font_type_(type)
-{}
-
-} // namespace html
-
-
-
-////////////////////////////////////////////////////////////////
-///
-/// XHTMLStream
-///
-////////////////////////////////////////////////////////////////
-
-XHTMLStream::XHTMLStream(odocstream & os)
- : os_(os), escape_(ESCAPE_ALL)
-{}
-
-
-#ifdef XHTML_DEBUG
-void XHTMLStream::dumpTagStack(string const & msg)
+xml::FontTag xhtmlStartFontTag(xml::FontTypes type)
{
- *this << html::CR();
- writeError(msg);
- *this << html::CR();
- writeError("Tag Stack");
- TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
- TagDeque::const_reverse_iterator en = tag_stack_.rend();
- for (; it != en; ++it) {
- writeError(it->get()->tag_);
- }
- writeError("End Tag Stack");
- *this << html::CR();
- writeError("Pending Tags");
- it = pending_tags_.rbegin();
- en = pending_tags_.rend();
- for (; it != en; ++it) {
- writeError(it->get()->tag_);
- }
- writeError("End Pending Tags");
- *this << html::CR();
+ return xml::FontTag(fontToHtmlTag(type), from_utf8(fontToAttribute(type)), type);
}
-#endif
-void XHTMLStream::writeError(std::string const & s) const
+xml::EndFontTag xhtmlEndFontTag(xml::FontTypes type)
{
- LYXERR0(s);
- os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
+ return xml::EndFontTag(fontToHtmlTag(type), type);
}
-
-namespace {
- // an illegal tag for internal use
- static html::StartTag const parsep_tag("&LyX_parsep_tag&");
-} // namespace
-
-
-bool XHTMLStream::closeFontTags()
-{
- if (isTagPending(parsep_tag))
- // we haven't had any content
- return true;
-
-#ifdef XHTML_DEBUG
- dumpTagStack("Beging Close Font Tags");
-#endif
-
- // this may be a useless check, since we ought at least to have
- // the parsep_tag. but it can't hurt too much to be careful.
- if (tag_stack_.empty())
- return true;
-
- // first, we close any open font tags we can close
- TagPtr curtag = tag_stack_.back();
- while (curtag->asFontTag()) {
- os_ << curtag->writeEndTag();
- tag_stack_.pop_back();
- // this shouldn't happen, since then the font tags
- // weren't in any other tag.
- LASSERT(!tag_stack_.empty(), return true);
- curtag = tag_stack_.back();
- }
-
-#ifdef XHTML_DEBUG
- dumpTagStack("End Close Font Tags");
-#endif
-
- if (*curtag == parsep_tag)
- return true;
-
- // so we've hit a non-font tag.
- writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
- "but you might want to check these tags:");
- TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
- TagDeque::const_reverse_iterator const en = tag_stack_.rend();
- for (; it != en; ++it) {
- if (**it == parsep_tag)
- break;
- writeError((*it)->tag_);
- }
- return false;
-}
-
-
-void XHTMLStream::startDivision(bool keep_empty)
-{
- pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag)));
- if (keep_empty)
- clearTagDeque();
-#ifdef XHTML_DEBUG
- dumpTagStack("StartDivision");
-#endif
-}
-
-
-void XHTMLStream::endDivision()
-{
- if (isTagPending(parsep_tag)) {
- // this case is normal. it just means we didn't have content,
- // so the parsep_tag never got moved onto the tag stack.
- while (!pending_tags_.empty()) {
- // clear all pending tags up to and including the parsep tag.
- // note that we work from the back, because we want to get rid
- // of everything that hasn't been used.
- TagPtr const cur_tag = pending_tags_.back();
- pending_tags_.pop_back();
- if (*cur_tag == parsep_tag)
- break;
- }
-
-#ifdef XHTML_DEBUG
- dumpTagStack("EndDivision");
-#endif
-
- return;
- }
-
- if (!isTagOpen(parsep_tag)) {
- writeError("No division separation tag found in endDivision().");
- return;
- }
-
- // this case is also normal, if the parsep tag is the last one
- // on the stack. otherwise, it's an error.
- while (!tag_stack_.empty()) {
- TagPtr const cur_tag = tag_stack_.back();
- tag_stack_.pop_back();
- if (*cur_tag == parsep_tag)
- break;
- writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
- os_ << cur_tag->writeEndTag();
- }
-
-#ifdef XHTML_DEBUG
- dumpTagStack("EndDivision");
-#endif
-}
-
-
-void XHTMLStream::clearTagDeque()
-{
- while (!pending_tags_.empty()) {
- TagPtr const tag = pending_tags_.front();
- if (*tag != parsep_tag)
- // tabs?
- os_ << tag->writeTag();
- tag_stack_.push_back(tag);
- pending_tags_.pop_front();
- }
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(docstring const & d)
-{
- clearTagDeque();
- os_ << html::htmlize(d, escape_);
- escape_ = ESCAPE_ALL;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(const char * s)
-{
- clearTagDeque();
- docstring const d = from_ascii(s);
- os_ << html::htmlize(d, escape_);
- escape_ = ESCAPE_ALL;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(char_type c)
-{
- clearTagDeque();
- os_ << html::escapeChar(c, escape_);
- escape_ = ESCAPE_ALL;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(char c)
-{
- clearTagDeque();
- os_ << html::escapeChar(c, escape_);
- escape_ = ESCAPE_ALL;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(int i)
-{
- clearTagDeque();
- os_ << i;
- escape_ = ESCAPE_ALL;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(EscapeSettings e)
-{
- escape_ = e;
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
-{
- if (tag.tag_.empty())
- return *this;
- pending_tags_.push_back(makeTagPtr(tag));
- if (tag.keepempty_)
- clearTagDeque();
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
-{
- if (tag.tag_.empty())
- return *this;
- pending_tags_.push_back(makeTagPtr(tag));
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
-{
- if (tag.tag_.empty())
- return *this;
- clearTagDeque();
- os_ << tag.writeTag();
- *this << html::CR();
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag)
-{
- if (tag.tag_.empty())
- return *this;
- pending_tags_.push_back(makeTagPtr(tag));
- return *this;
-}
-
-
-XHTMLStream & XHTMLStream::operator<<(html::CR const &)
-{
- // tabs?
- os_ << from_ascii("\n");
- return *this;
-}
-
-
-bool XHTMLStream::isTagOpen(html::StartTag const & stag) const
-{
- TagDeque::const_iterator sit = tag_stack_.begin();
- TagDeque::const_iterator const sen = tag_stack_.end();
- for (; sit != sen; ++sit)
- if (**sit == stag)
- return true;
- return false;
-}
-
-
-bool XHTMLStream::isTagOpen(html::EndTag const & etag) const
-{
- TagDeque::const_iterator sit = tag_stack_.begin();
- TagDeque::const_iterator const sen = tag_stack_.end();
- for (; sit != sen; ++sit)
- if (etag == **sit)
- return true;
- return false;
-}
-
-
-bool XHTMLStream::isTagPending(html::StartTag const & stag) const
-{
- TagDeque::const_iterator sit = pending_tags_.begin();
- TagDeque::const_iterator const sen = pending_tags_.end();
- for (; sit != sen; ++sit)
- if (**sit == stag)
- return true;
- return false;
-}
-
-
-// this is complicated, because we want to make sure that
-// everything is properly nested. the code ought to make
-// sure of that, but we won't assert (yet) if we run into
-// a problem. we'll just output error messages and try our
-// best to make things work.
-XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag)
-{
- if (etag.tag_.empty())
- return *this;
-
- // if this tag is pending, we can simply discard it.
- if (!pending_tags_.empty()) {
-
- if (etag == *pending_tags_.back()) {
- // we have <tag></tag>, so we discard it and remove it
- // from the pending_tags_.
- pending_tags_.pop_back();
- return *this;
- }
-
- // there is a pending tag that isn't the one we are trying
- // to close.
-
- // is this tag itself pending?
- // non-const iterators because we may call erase().
- TagDeque::iterator dit = pending_tags_.begin();
- TagDeque::iterator const den = pending_tags_.end();
- for (; dit != den; ++dit) {
- if (etag == **dit) {
- // it was pending, so we just erase it
- writeError("Tried to close pending tag `" + etag.tag_
- + "' when other tags were pending. Last pending tag is `"
- + to_utf8(pending_tags_.back()->writeTag())
- + "'. Tag discarded.");
- pending_tags_.erase(dit);
- return *this;
- }
- }
- // so etag isn't itself pending. is it even open?
- if (!isTagOpen(etag)) {
- writeError("Tried to close `" + etag.tag_
- + "' when tag was not open. Tag discarded.");
- return *this;
- }
- // ok, so etag is open.
- // our strategy will be as below: we will do what we need to
- // do to close this tag.
- string estr = "Closing tag `" + etag.tag_
- + "' when other tags are pending. Discarded pending tags:\n";
- for (dit = pending_tags_.begin(); dit != den; ++dit)
- estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n";
- writeError(estr);
- // clear the pending tags...
- pending_tags_.clear();
- // ...and then just fall through.
- }
-
- // make sure there are tags to be closed
- if (tag_stack_.empty()) {
- writeError("Tried to close `" + etag.tag_
- + "' when no tags were open!");
- return *this;
- }
-
- // is the tag we are closing the last one we opened?
- if (etag == *tag_stack_.back()) {
- // output it...
- os_ << etag.writeEndTag();
- // ...and forget about it
- tag_stack_.pop_back();
- return *this;
- }
-
- // we are trying to close a tag other than the one last opened.
- // let's first see if this particular tag is still open somehow.
- if (!isTagOpen(etag)) {
- writeError("Tried to close `" + etag.tag_
- + "' when tag was not open. Tag discarded.");
- return *this;
- }
-
- // so the tag was opened, but other tags have been opened since
- // and not yet closed.
- // if it's a font tag, though...
- if (etag.asFontTag()) {
- // it won't be a problem if the other tags open since this one
- // are also font tags.
- TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
- TagDeque::const_reverse_iterator ren = tag_stack_.rend();
- for (; rit != ren; ++rit) {
- if (etag == **rit)
- break;
- if (!(*rit)->asFontTag()) {
- // we'll just leave it and, presumably, have to close it later.
- writeError("Unable to close font tag `" + etag.tag_
- + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
- return *this;
- }
- }
-
- // so we have e.g.:
- // <em>this is <strong>bold
- // and are being asked to closed em. we want:
- // <em>this is <strong>bold</strong></em><strong>
- // first, we close the intervening tags...
- TagPtr curtag = tag_stack_.back();
- // ...remembering them in a stack.
- TagDeque fontstack;
- while (etag != *curtag) {
- os_ << curtag->writeEndTag();
- fontstack.push_back(curtag);
- tag_stack_.pop_back();
- curtag = tag_stack_.back();
- }
- os_ << etag.writeEndTag();
- tag_stack_.pop_back();
-
- // ...and restore the other tags.
- rit = fontstack.rbegin();
- ren = fontstack.rend();
- for (; rit != ren; ++rit)
- pending_tags_.push_back(*rit);
- return *this;
- }
-
- // it wasn't a font tag.
- // so other tags were opened before this one and not properly closed.
- // so we'll close them, too. that may cause other issues later, but it
- // at least guarantees proper nesting.
- writeError("Closing tag `" + etag.tag_
- + "' when other tags are open, namely:");
- TagPtr curtag = tag_stack_.back();
- while (etag != *curtag) {
- writeError(curtag->tag_);
- if (*curtag != parsep_tag)
- os_ << curtag->writeEndTag();
- tag_stack_.pop_back();
- curtag = tag_stack_.back();
- }
- // curtag is now the one we actually want.
- os_ << curtag->writeEndTag();
- tag_stack_.pop_back();
-
- return *this;
-}
-
-// End code for XHTMLStream
-
namespace {
// convenience functions
-inline void openParTag(XHTMLStream & xs, Layout const & lay,
+inline void openParTag(XMLStream & xs, Layout const & lay,
std::string parlabel)
{
- xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
+ xs << xml::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
}
-void openParTag(XHTMLStream & xs, Layout const & lay,
+void openParTag(XMLStream & xs, Layout const & lay,
ParagraphParameters const & params,
std::string parlabel)
{
return;
}
string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
- xs << html::ParTag(lay.htmltag(), attrs, parlabel);
+ xs << xml::ParTag(lay.htmltag(), attrs, parlabel);
}
-inline void closeTag(XHTMLStream & xs, Layout const & lay)
+inline void closeTag(XMLStream & xs, Layout const & lay)
{
- xs << html::EndTag(lay.htmltag());
+ xs << xml::EndTag(lay.htmltag());
}
-inline void openLabelTag(XHTMLStream & xs, Layout const & lay)
+inline void openLabelTag(XMLStream & xs, Layout const & lay)
{
- xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
+ xs << xml::StartTag(lay.htmllabeltag(), lay.htmllabelattr());
}
-inline void closeLabelTag(XHTMLStream & xs, Layout const & lay)
+inline void closeLabelTag(XMLStream & xs, Layout const & lay)
{
- xs << html::EndTag(lay.htmllabeltag());
+ xs << xml::EndTag(lay.htmllabeltag());
}
-inline void openItemTag(XHTMLStream & xs, Layout const & lay)
+inline void openItemTag(XMLStream & xs, Layout const & lay)
{
- xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
+ xs << xml::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true);
}
-void openItemTag(XHTMLStream & xs, Layout const & lay,
+void openItemTag(XMLStream & xs, Layout const & lay,
ParagraphParameters const & params)
{
// FIXME Are there other things we should handle here?
return;
}
string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
- xs << html::StartTag(lay.htmlitemtag(), attrs);
+ xs << xml::StartTag(lay.htmlitemtag(), attrs);
}
-inline void closeItemTag(XHTMLStream & xs, Layout const & lay)
+inline void closeItemTag(XMLStream & xs, Layout const & lay)
{
- xs << html::EndTag(lay.htmlitemtag());
+ xs << xml::EndTag(lay.htmlitemtag());
}
// end of convenience functions
ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams,
Text const & text,
ParagraphList::const_iterator const & pbegin,
// FIXME We should see if there's a label to be output and
// do something with it.
if (par != pbegin)
- xs << html::CR();
+ xs << xml::CR();
// We want to open the paragraph tag if:
// (i) the current layout permits multiple paragraphs
if (close_par) {
closeTag(xs, lay);
- xs << html::CR();
+ xs << xml::CR();
}
if (!deferred.empty()) {
- xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR();
+ xs << XMLStream::ESCAPE_NONE << deferred << xml::CR();
}
}
return pend;
ParagraphList::const_iterator makeBibliography(Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams,
Text const & text,
ParagraphList::const_iterator const & pbegin,
{
// FIXME XHTML
// Use TextClass::htmlTOCLayout() to figure out how we should look.
- xs << html::StartTag("h2", "class='bibliography'")
+ xs << xml::StartTag("h2", "class='bibliography'")
<< pbegin->layout().labelstring(false)
- << html::EndTag("h2")
- << html::CR()
- << html::StartTag("div", "class='bibliography'")
- << html::CR();
+ << xml::EndTag("h2")
+ << xml::CR()
+ << xml::StartTag("div", "class='bibliography'")
+ << xml::CR();
makeParagraphs(buf, xs, runparams, text, pbegin, pend);
- xs << html::EndTag("div");
+ xs << xml::EndTag("div");
return pend;
}
ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams,
Text const & text,
ParagraphList::const_iterator const & pbegin,
// open tag for this environment
openParTag(xs, bstyle, pbegin->magicLabel());
- xs << html::CR();
+ xs << xml::CR();
// we will on occasion need to remember a layout from before.
Layout const * lastlay = nullptr;
case LATEX_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT: {
- // There are two possiblities in this case.
+ // There are two possibilities in this case.
// One is that we are still in the environment in which we
// started---which we will be if the depth is the same.
if (par->params().depth() == origdepth) {
xs << lbl;
closeLabelTag(xs, style);
}
- xs << html::CR();
+ xs << xml::CR();
}
} else { // some kind of list
if (style.labeltype == LABEL_MANUAL) {
openLabelTag(xs, style);
sep = par->firstWordLyXHTML(xs, runparams);
closeLabelTag(xs, style);
- xs << html::CR();
+ xs << xml::CR();
}
else {
openLabelTag(xs, style);
xs << par->params().labelString();
closeLabelTag(xs, style);
- xs << html::CR();
+ xs << xml::CR();
}
}
} // end label output
docstring deferred = par->simpleLyXHTMLOnePar(buf, xs, runparams,
text.outerFont(distance(begin, par)), true, true, sep);
- xs << XHTMLStream::ESCAPE_NONE << deferred;
+ xs << XMLStream::ESCAPE_NONE << deferred;
++par;
// We may not want to close the tag yet, in particular:
lastlay = &style;
} else
closeItemTag(xs, style);
- xs << html::CR();
+ xs << xml::CR();
}
// The other possibility is that the depth has increased, in which
// case we need to recurse.
if (lastlay != nullptr)
closeItemTag(xs, *lastlay);
closeTag(xs, bstyle);
- xs << html::CR();
+ xs << xml::CR();
return pend;
}
void makeCommand(Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams,
Text const & text,
ParagraphList::const_iterator const & pbegin)
pbegin->simpleLyXHTMLOnePar(buf, xs, runparams,
text.outerFont(distance(begin, pbegin)));
closeTag(xs, style);
- xs << html::CR();
+ xs << xml::CR();
}
} // end anonymous namespace
void xhtmlParagraphs(Text const & text,
Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams)
{
ParagraphList const & paragraphs = text.paragraphs();
pit_type bpit = runparams.par_begin;
pit_type const epit = runparams.par_end;
LASSERT(bpit < epit,
- { xs << XHTMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
+ { xs << XMLStream::ESCAPE_NONE << "<!-- XHTML output error! -->\n"; return; });
OutputParams ourparams = runparams;
ParagraphList::const_iterator const pend =
#include "support/docstream.h"
#include "support/strfwd.h"
+#include "xml.h"
#include <deque>
#include <memory>
namespace lyx {
+docstring const & fontToHtmlTag(xml::FontTypes type);
+
class Buffer;
class OutputParams;
class Text;
-// Inspiration for the *Tag structs and for XHTMLStream
-// came from MathStream and its cousins.
-
-namespace html {
-
-struct FontTag;
-struct EndFontTag;
-
-/// Attributes will be escaped automatically and so should NOT
-/// be escaped before being passed to the constructor.
-struct StartTag
-{
- ///
- explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
- ///
- explicit StartTag(std::string const & tag, std::string const & attr,
- bool keepempty = false)
- : tag_(tag), attr_(attr), keepempty_(keepempty) {}
- ///
- virtual ~StartTag() {}
- /// <tag_ attr_>
- virtual docstring writeTag() const;
- /// </tag_>
- virtual docstring writeEndTag() const;
- ///
- virtual FontTag const * asFontTag() const { return 0; }
- ///
- virtual bool operator==(StartTag const & rhs) const
- { return tag_ == rhs.tag_; }
- ///
- virtual bool operator!=(StartTag const & rhs) const
- { return !(*this == rhs); }
- ///
- virtual bool operator==(FontTag const & rhs) const;
- ///
- std::string tag_;
- ///
- std::string attr_;
- /// whether to keep things like "<tag></tag>" or discard them
- /// you would want this for td, e.g, but maybe not for a div
- bool keepempty_;
-};
-
-
-///
-struct EndTag
-{
- ///
- explicit EndTag(std::string const & tag) : tag_(tag) {}
- ///
- virtual ~EndTag() {}
- /// </tag_>
- virtual docstring writeEndTag() const;
- ///
- bool operator==(StartTag const & rhs) const
- { return tag_ == rhs.tag_; }
- ///
- bool operator!=(StartTag const & rhs) const
- { return !(*this == rhs); }
- ///
- virtual EndFontTag const * asFontTag() const { return 0; }
- ///
- std::string tag_;
-};
-
-
-/// Tags like <img />
-/// Attributes will be escaped automatically and so should NOT
-/// be escaped before being passed to the constructor.
-struct CompTag
-{
- ///
- explicit CompTag(std::string const & tag)
- : tag_(tag) {}
- ///
- explicit CompTag(std::string const & tag, std::string const & attr)
- : tag_(tag), attr_(attr) {}
- /// <tag_ attr_ />
- docstring writeTag() const;
- ///
- std::string tag_;
- ///
- std::string attr_;
-};
-
-
-/// A special case of StartTag, used exclusively for tags that wrap paragraphs.
-struct ParTag : public StartTag
-{
- ///
- explicit ParTag(std::string const & tag, std::string attr,
- std::string const & parid);
- ///
- ~ParTag() {}
-};
-
-
-///
-enum FontTypes {
- // ranges
- FT_EMPH,
- FT_NOUN,
- FT_UBAR,
- FT_DBAR,
- FT_WAVE,
- FT_SOUT,
- FT_XOUT,
- // bold
- FT_BOLD,
- // shapes
- FT_UPRIGHT,
- FT_ITALIC,
- FT_SLANTED,
- FT_SMALLCAPS,
- // families
- FT_ROMAN,
- FT_SANS,
- FT_TYPE,
- // sizes
- FT_SIZE_TINY,
- FT_SIZE_SCRIPT,
- FT_SIZE_FOOTNOTE,
- FT_SIZE_SMALL,
- FT_SIZE_NORMAL,
- FT_SIZE_LARGE,
- FT_SIZE_LARGER,
- FT_SIZE_LARGEST,
- FT_SIZE_HUGE,
- FT_SIZE_HUGER,
- FT_SIZE_INCREASE,
- FT_SIZE_DECREASE
-};
-
-
///
-struct FontTag : public StartTag
-{
- ///
- explicit FontTag(FontTypes type);
- ///
- FontTag const * asFontTag() const { return this; }
- ///
- bool operator==(StartTag const &) const;
- ///
- FontTypes font_type_;
-};
-
-
+xml::FontTag xhtmlStartFontTag(xml::FontTypes type);
///
-struct EndFontTag : public EndTag
-{
- ///
- explicit EndFontTag(FontTypes type);
- ///
- EndFontTag const * asFontTag() const { return this; }
- ///
- FontTypes font_type_;
-};
-
-
-// trivial struct for output of newlines
-struct CR{};
-
-} // namespace html
-
-class XHTMLStream {
-public:
- ///
- explicit XHTMLStream(odocstream & os);
- ///
- odocstream & os() { return os_; }
- ///
- // int & tab() { return tab_; }
- /// closes any font tags that are eligible to be closed,
- /// i.e., last on the tag_stack_.
- /// \return false if there are open font tags we could not close.
- /// because they are "blocked" by open non-font tags on the stack.
- bool closeFontTags();
- /// sets a mark so we know what tags to close at the end.
- /// normally called at the start of a paragraph.
- void startDivision(bool keep_empty);
- /// clears the mark set by previous method.
- /// there should not be any other tags open before it on the stack,
- /// but if there are, we will close them.
- void endDivision();
- ///
- XHTMLStream & operator<<(docstring const &);
- ///
- XHTMLStream & operator<<(const char *);
- ///
- XHTMLStream & operator<<(char_type);
- ///
- XHTMLStream & operator<<(int);
- ///
- XHTMLStream & operator<<(char);
- ///
- XHTMLStream & operator<<(html::StartTag const &);
- ///
- XHTMLStream & operator<<(html::EndTag const &);
- ///
- XHTMLStream & operator<<(html::CompTag const &);
- ///
- XHTMLStream & operator<<(html::ParTag const &);
- ///
- XHTMLStream & operator<<(html::FontTag const &);
- ///
- XHTMLStream & operator<<(html::CR const &);
- ///
- enum EscapeSettings {
- ESCAPE_NONE,
- ESCAPE_AND, // meaning &
- ESCAPE_ALL // meaning <, >, &, at present
- };
- /// Sets what we are going to escape on the NEXT write.
- /// Everything is reset for the next time.
- XHTMLStream & operator<<(EscapeSettings);
- /// This routine is for debugging the tag stack, etc. Code
- /// for it is disabled by default, however, so you will need
- /// to enable it if you want to use it.
- void dumpTagStack(std::string const & msg);
-private:
- ///
- void clearTagDeque();
- ///
- bool isTagOpen(html::StartTag const &) const;
- ///
- bool isTagOpen(html::EndTag const &) const;
- ///
- bool isTagPending(html::StartTag const &) const;
- ///
- void writeError(std::string const &) const;
- ///
- odocstream & os_;
- ///
- EscapeSettings escape_;
- // What we would really like to do here is simply use a
- // deque<StartTag>. But we want to store both StartTags and
- // sub-classes thereof on this stack, which means we run into the
- // so-called polymorphic class problem with the STL. We therefore have
- // to use a deque<StartTag *>, which leads to the question who will
- // own these pointers and how they will be deleted, so we use shared
- // pointers.
- ///
- typedef std::shared_ptr<html::StartTag> TagPtr;
- typedef std::deque<TagPtr> TagDeque;
- ///
- template <typename T>
- TagPtr makeTagPtr(T const & tag) { return std::make_shared<T>(tag); }
- ///
- TagDeque pending_tags_;
- ///
- TagDeque tag_stack_;
-};
+xml::EndFontTag xhtmlEndFontTag(xml::FontTypes type);
///
void xhtmlParagraphs(Text const & text,
Buffer const & buf,
- XHTMLStream & xs,
+ XMLStream & xs,
OutputParams const & runparams);
/// \return a string appropriate for setting alignment in CSS
/// Does NOT return "justify" for "block"
std::string alignmentToCSS(LyXAlignment align);
-namespace html {
-///
-docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e);
-/// converts a string to a form safe for links, etc
-docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e);
-/// cleans \param str for use as an atttribute by replacing
-/// all non-alnum by "_"
-docstring cleanAttr(docstring const & str);
-/// \p c must be ASCII
-docstring escapeChar(char c, XHTMLStream::EscapeSettings e);
-
-} // namespace html
} // namespace lyx
#endif
+++ /dev/null
-/**
- * \file sgml.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author José Matos
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "sgml.h"
-
-#include "Buffer.h"
-#include "BufferParams.h"
-#include "Counters.h"
-#include "Layout.h"
-#include "OutputParams.h"
-#include "Paragraph.h"
-#include "Text.h"
-#include "TextClass.h"
-
-#include "support/convert.h"
-#include "support/docstream.h"
-#include "support/lstrings.h"
-#include "support/textutils.h"
-
-#include <atomic>
-#include <map>
-#include <QThreadStorage>
-
-using namespace std;
-using namespace lyx::support;
-
-namespace lyx {
-
-
-docstring sgml::escapeChar(char_type c)
-{
- docstring str;
- switch (c) {
- case ' ':
- str += " ";
- break;
- case '&':
- str += "&";
- break;
- case '<':
- str += "<";
- break;
- case '>':
- str += ">";
- break;
-#if 0
- case '$':
- str += "$";
- break;
- case '#':
- str += "#";
- break;
- case '%':
- str += "%";
- break;
- case '[':
- str += "[";
- break;
- case ']':
- str += "]";
- break;
- case '{':
- str += "{";
- break;
- case '}':
- str += "}";
- break;
- case '~':
- str += "˜";
- break;
- case '"':
- str += """;
- break;
- case '\\':
- str += "\";
- break;
-#endif
- default:
- str += c;
- break;
- }
- return str;
-}
-
-
-docstring sgml::escapeString(docstring const & raw)
-{
- docstring bin;
- bin.reserve(raw.size() * 2); // crude approximation is sufficient
- for (size_t i = 0; i != raw.size(); ++i)
- bin += sgml::escapeChar(raw[i]);
-
- return bin;
-}
-
-
-docstring const sgml::uniqueID(docstring const & label)
-{
- // thread-safe
- static atomic_uint seed(1000);
- return label + convert<docstring>(++seed);
-}
-
-
-docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams,
- docstring const & orig)
-{
- // The standard DocBook SGML declaration only allows letters,
- // digits, '-' and '.' in a name.
- // Since users might change that declaration one has to cater
- // for additional allowed characters.
- // This routine replaces illegal characters by '-' or '.'
- // and adds a number for uniqueness.
- // If you know what you are doing, you can set allowed==""
- // to disable this mangling.
- DocumentClass const & tclass = buf.params().documentClass();
- docstring const allowed = from_ascii(
- runparams.flavor == OutputParams::XML ? ".-_:" : tclass.options());
-
- if (allowed.empty())
- return orig;
-
- docstring::const_iterator it = orig.begin();
- docstring::const_iterator end = orig.end();
-
- docstring content;
-
- typedef map<docstring, docstring> MangledMap;
- static QThreadStorage<MangledMap> tMangledNames;
- static QThreadStorage<int> tMangleID;
-
- MangledMap & mangledNames = tMangledNames.localData();
-
- MangledMap::const_iterator const known = mangledNames.find(orig);
- if (known != mangledNames.end())
- return known->second;
-
- // make sure it starts with a letter
- if (!isAlphaASCII(*it) && allowed.find(*it) >= allowed.size())
- content += "x";
-
- bool mangle = false;
- for (; it != end; ++it) {
- char_type c = *it;
- if (isAlphaASCII(c) || isDigitASCII(c) || c == '-' || c == '.'
- || allowed.find(c) < allowed.size())
- content += c;
- else if (c == '_' || c == ' ') {
- mangle = true;
- content += "-";
- }
- else if (c == ':' || c == ',' || c == ';' || c == '!') {
- mangle = true;
- content += ".";
- }
- else {
- mangle = true;
- }
- }
-
- if (mangle) {
- int & mangleID = tMangleID.localData();
- content += "-" + convert<docstring>(mangleID++);
- } else if (isDigitASCII(content[content.size() - 1]))
- content += ".";
-
- mangledNames[orig] = content;
-
- return content;
-}
-
-
-void sgml::openTag(odocstream & os, string const & name, string const & attribute)
-{
- // FIXME UNICODE
- // This should be fixed in layout files later.
- string param = subst(attribute, "<", "\"");
- param = subst(param, ">", "\"");
-
- // Note: we ignore the name if it empty or if it is a comment "<!-- -->" or
- // if the name is *dummy*.
- // We ignore dummy because dummy is not a valid docbook element and it is
- // the internal name given to single paragraphs in the latex output.
- // This allow us to simplify the code a lot and is a reasonable compromise.
- if (!name.empty() && name != "!-- --" && name != "dummy") {
- os << '<' << from_ascii(name);
- if (!param.empty())
- os << ' ' << from_ascii(param);
- os << '>';
- }
-}
-
-
-void sgml::closeTag(odocstream & os, string const & name)
-{
- if (!name.empty() && name != "!-- --" && name != "dummy")
- os << "</" << from_ascii(name) << '>';
-}
-
-
-void sgml::openTag(Buffer const & buf, odocstream & os,
- OutputParams const & runparams, Paragraph const & par)
-{
- Layout const & style = par.layout();
- string const & name = style.latexname();
- string param = style.latexparam();
- Counters & counters = buf.params().documentClass().counters();
-
- string id = par.getID(buf, runparams);
-
- string attribute;
- if (!id.empty()) {
- if (param.find('#') != string::npos) {
- string::size_type pos = param.find("id=<");
- string::size_type end = param.find(">");
- if( pos != string::npos && end != string::npos)
- param.erase(pos, end-pos + 1);
- }
- attribute = id + ' ' + param;
- } else {
- if (param.find('#') != string::npos) {
- // FIXME UNICODE
- if (!style.counter.empty())
- // This uses InternalUpdate at the moment becuase sgml output
- // does not do anything with tracked counters, and it would need
- // to track layouts if it did want to use them.
- counters.step(style.counter, InternalUpdate);
- else
- counters.step(from_ascii(name), InternalUpdate);
- int i = counters.value(from_ascii(name));
- attribute = subst(param, "#", convert<string>(i));
- } else {
- attribute = param;
- }
- }
- openTag(os, name, attribute);
-}
-
-
-void sgml::closeTag(odocstream & os, Paragraph const & par)
-{
- Layout const & style = par.layout();
- closeTag(os, style.latexname());
-}
-
-
-} // namespace lyx
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file sgml.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author José Matos
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef SGML_H
-#define SGML_H
-
-#include "support/docstring.h"
-
-namespace lyx {
-
-class Buffer;
-class Paragraph;
-class OutputParams;
-
-namespace sgml {
-
-/**
- * Escape the given character, if necessary,
- * to an SGML entity.
- */
-docstring escapeChar(char_type c);
-
-/// Escape a word instead of a single character
-docstring escapeString(docstring const & raw);
-
-/// replaces illegal characters from SGML/XML ID attributes
-docstring cleanID(Buffer const & buf, OutputParams const & runparams,
- docstring const & orig);
-
-/// returns a unique numeric id
-docstring const uniqueID(docstring const & label);
-
-/// Opens tag
-void openTag(odocstream & os, std::string const & name,
- std::string const & attribute = std::string());
-
-/// Open tag
-void openTag(Buffer const & buf, odocstream & os,
- OutputParams const & runparams, Paragraph const & par);
-
-/// Close tag
-void closeTag(odocstream & os, std::string const & name);
-
-/// Close tag
-void closeTag(odocstream & os, Paragraph const & par);
-
-} // namespace sgml
-} // namespace lyx
-
-#endif // SGML_H
#include "LyXRC.h"
#include "support/Messages.h"
+#include "xml.h"
using namespace std;
return string();
}
+namespace xml {
+docstring StartTag::writeTag() const { return docstring(); }
+docstring StartTag::writeEndTag() const { return docstring(); }
+bool StartTag::operator==(FontTag const & rhs) const { return rhs == *this; }
+}
+
} // namespace lyx
void lyx_exit(int)
{}
+namespace xml {
+docstring StartTag::writeTag() const { return docstring(); }
+docstring StartTag::writeEndTag() const { return docstring(); }
+bool StartTag::operator==(FontTag const & rhs) const { return rhs == *this; }
+}
+
} // namespace lyx
--- /dev/null
+/**
+ * \file xml.cpp
+ * This file is part of LyX, the document processor.
+ * License details can be found in the file COPYING.
+ *
+ * \author José Matos
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "xml.h"
+
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "Counters.h"
+#include "Layout.h"
+#include "OutputParams.h"
+#include "Paragraph.h"
+#include "Text.h"
+#include "TextClass.h"
+
+#include "support/convert.h"
+#include "support/docstream.h"
+#include "support/lstrings.h"
+#include "support/textutils.h"
+
+#include <atomic>
+#include <map>
+#include <functional>
+#include <QThreadStorage>
+#include <support/lassert.h>
+
+using namespace std;
+using namespace lyx::support;
+
+namespace lyx {
+namespace xml {
+
+
+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;
+ 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 ;
+ 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);
+ return escapeChar(static_cast<char_type>(c), e);
+}
+
+
+docstring cleanAttr(docstring const & str)
+{
+ docstring newname;
+ docstring::const_iterator it = str.begin();
+ docstring::const_iterator en = str.end();
+ for (; it != en; ++it) {
+ char_type const c = *it;
+ newname += isAlnumASCII(c) ? c : char_type('_');
+ }
+ return newname;
+}
+
+
+docstring StartTag::writeTag() const {
+ docstring output = '<' + tag_;
+ if (!attr_.empty()) {
+ docstring attributes = xml::xmlize(attr_, XMLStream::ESCAPE_NONE);
+ attributes.erase(attributes.begin(), std::find_if(attributes.begin(), attributes.end(),
+ [](int c) {return !std::isspace(c);}));
+ if (!attributes.empty()) {
+ output += ' ' + attributes;
+ }
+ }
+ output += ">";
+ return output;
+}
+
+
+docstring StartTag::writeEndTag() const {
+ return from_utf8("</") + tag_ + from_utf8(">");
+}
+
+
+bool StartTag::operator==(FontTag const &rhs) const {
+ return rhs == *this;
+}
+
+
+docstring EndTag::writeEndTag() const {
+ return from_utf8("</") + tag_ + from_utf8(">");
+}
+
+
+docstring CompTag::writeTag() const {
+ docstring output = '<' + from_utf8(tag_);
+ if (!attr_.empty()) {
+ // Erase the beginning of the attributes if it contains space characters: this function deals with that
+ // automatically.
+ docstring attributes = xmlize(from_utf8(attr_), XMLStream::ESCAPE_NONE);
+ attributes.erase(attributes.begin(), std::find_if(attributes.begin(), attributes.end(),
+ [](int c) {return !std::isspace(c);}));
+ if (!attributes.empty()) {
+ output += ' ' + attributes;
+ }
+ }
+ output += " />";
+ return output;
+}
+
+
+bool FontTag::operator==(StartTag const & tag) const
+{
+ FontTag const * const ftag = tag.asFontTag();
+ if (!ftag)
+ return false;
+ return (font_type_ == ftag->font_type_);
+}
+
+} // namespace xml
+
+
+void XMLStream::writeError(std::string const &s) const {
+ LYXERR0(s);
+ os_ << from_utf8("<!-- Output Error: " + s + " -->\n");
+}
+
+
+void XMLStream::writeError(docstring const &s) const {
+ LYXERR0(s);
+ os_ << from_utf8("<!-- Output Error: ") << s << from_utf8(" -->\n");
+}
+
+
+bool XMLStream::closeFontTags() {
+ if (isTagPending(xml::parsep_tag))
+ // we haven't had any content
+ return true;
+
+ // this may be a useless check, since we ought at least to have
+ // the parsep_tag. but it can't hurt too much to be careful.
+ if (tag_stack_.empty())
+ return true;
+
+ // first, we close any open font tags we can close
+ TagPtr *curtag = &tag_stack_.back();
+ while ((*curtag)->asFontTag()) {
+ if (**curtag != xml::parsep_tag)
+ os_ << (*curtag)->writeEndTag();
+ tag_stack_.pop_back();
+ // this shouldn't happen, since then the font tags
+ // weren't in any other tag.
+ LASSERT(!tag_stack_.empty(), return true);
+ curtag = &tag_stack_.back();
+ }
+
+ if (**curtag == xml::parsep_tag)
+ return true;
+
+ // so we've hit a non-font tag.
+ writeError("Tags still open in closeFontTags(). Probably not a problem,\n"
+ "but you might want to check these tags:");
+ TagDeque::const_reverse_iterator it = tag_stack_.rbegin();
+ TagDeque::const_reverse_iterator const en = tag_stack_.rend();
+ for (; it != en; ++it) {
+ if (**it == xml::parsep_tag)
+ break;
+ writeError((*it)->tag_);
+ }
+ return false;
+}
+
+
+void XMLStream::startDivision(bool keep_empty) {
+ pending_tags_.push_back(makeTagPtr(xml::StartTag(xml::parsep_tag)));
+ if (keep_empty)
+ clearTagDeque();
+}
+
+
+void XMLStream::endDivision() {
+ if (isTagPending(xml::parsep_tag)) {
+ // this case is normal. it just means we didn't have content,
+ // so the parsep_tag never got moved onto the tag stack.
+ while (!pending_tags_.empty()) {
+ // clear all pending tags up to and including the parsep tag.
+ // note that we work from the back, because we want to get rid
+ // of everything that hasn't been used.
+ TagPtr const cur_tag = pending_tags_.back();
+ pending_tags_.pop_back();
+ if (*cur_tag == xml::parsep_tag)
+ break;
+ }
+
+#ifdef XHTML_DEBUG
+ dumpTagStack("EndDivision");
+#endif
+
+ return;
+ }
+
+ if (!isTagOpen(xml::parsep_tag)) {
+ writeError("No division separation tag found in endDivision().");
+ return;
+ }
+
+ // this case is also normal, if the parsep tag is the last one
+ // on the stack. otherwise, it's an error.
+ while (!tag_stack_.empty()) {
+ TagPtr const cur_tag = tag_stack_.back();
+ tag_stack_.pop_back();
+ if (*cur_tag == xml::parsep_tag)
+ break;
+ writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing.");
+ os_ << cur_tag->writeEndTag();
+ }
+
+#ifdef XHTML_DEBUG
+ dumpTagStack("EndDivision");
+#endif
+}
+
+
+void XMLStream::clearTagDeque() {
+ while (!pending_tags_.empty()) {
+ TagPtr const & tag = pending_tags_.front();
+ if (*tag != xml::parsep_tag)
+ // tabs?
+ os_ << tag->writeTag();
+ tag_stack_.push_back(tag);
+ pending_tags_.pop_front();
+ }
+}
+
+
+XMLStream &XMLStream::operator<<(docstring const &d) {
+ clearTagDeque();
+ os_ << xml::xmlize(d, escape_);
+ escape_ = ESCAPE_ALL;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(const char *s) {
+ clearTagDeque();
+ docstring const d = from_ascii(s);
+ os_ << xml::xmlize(d, escape_);
+ escape_ = ESCAPE_ALL;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(char_type c) {
+ clearTagDeque();
+ os_ << xml::escapeChar(c, escape_);
+ escape_ = ESCAPE_ALL;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(char c) {
+ clearTagDeque();
+ os_ << xml::escapeChar(c, escape_);
+ escape_ = ESCAPE_ALL;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(int i) {
+ clearTagDeque();
+ os_ << i;
+ escape_ = ESCAPE_ALL;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(EscapeSettings e) {
+ escape_ = e;
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(xml::StartTag const &tag) {
+ if (tag.tag_.empty())
+ return *this;
+ pending_tags_.push_back(makeTagPtr(tag));
+ if (tag.keepempty_)
+ clearTagDeque();
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(xml::ParTag const &tag) {
+ if (tag.tag_.empty())
+ return *this;
+ pending_tags_.push_back(makeTagPtr(tag));
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(xml::CompTag const &tag) {
+ if (tag.tag_.empty())
+ return *this;
+ clearTagDeque();
+ os_ << tag.writeTag();
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(xml::FontTag const &tag) {
+ if (tag.tag_.empty())
+ return *this;
+ pending_tags_.push_back(makeTagPtr(tag));
+ return *this;
+}
+
+
+XMLStream &XMLStream::operator<<(xml::CR const &) {
+ os_ << from_ascii("\n");
+ return *this;
+}
+
+
+bool XMLStream::isTagOpen(xml::StartTag const &stag) const {
+ auto sit = tag_stack_.begin();
+ auto sen = tag_stack_.cend();
+ for (; sit != sen; ++sit)
+ if (**sit == stag)
+ return true;
+ return false;
+}
+
+
+bool XMLStream::isTagOpen(xml::EndTag const &etag) const {
+ auto sit = tag_stack_.begin();
+ auto sen = tag_stack_.cend();
+ for (; sit != sen; ++sit)
+ if (etag == **sit)
+ return true;
+ return false;
+}
+
+
+bool XMLStream::isTagPending(xml::StartTag const &stag) const {
+ auto sit = pending_tags_.begin();
+ auto sen = pending_tags_.cend();
+ for (; sit != sen; ++sit)
+ if (**sit == stag)
+ return true;
+ return false;
+}
+
+
+// this is complicated, because we want to make sure that
+// everything is properly nested. the code ought to make
+// sure of that, but we won't assert (yet) if we run into
+// a problem. we'll just output error messages and try our
+// best to make things work.
+XMLStream &XMLStream::operator<<(xml::EndTag const &etag) {
+ if (etag.tag_.empty())
+ return *this;
+
+ // if this tag is pending, we can simply discard it.
+ if (!pending_tags_.empty()) {
+ if (etag == *pending_tags_.back()) {
+ // we have <tag></tag>, so we discard it and remove it
+ // from the pending_tags_.
+ pending_tags_.pop_back();
+ return *this;
+ }
+
+ // there is a pending tag that isn't the one we are trying
+ // to close.
+
+ // is this tag itself pending?
+ // non-const iterators because we may call erase().
+ TagDeque::iterator dit = pending_tags_.begin();
+ TagDeque::iterator const den = pending_tags_.end();
+ for (; dit != den; ++dit) {
+ if (etag == **dit) {
+ // it was pending, so we just erase it
+ writeError("Tried to close pending tag `" + to_utf8(etag.tag_)
+ + "' when other tags were pending. Last pending tag is `"
+ + to_utf8(pending_tags_.back()->writeTag())
+ + "'. Tag discarded.");
+ pending_tags_.erase(dit);
+ return *this;
+ }
+ }
+ // so etag isn't itself pending. is it even open?
+ if (!isTagOpen(etag)) {
+ writeError("Tried to close `" + to_utf8(etag.tag_)
+ + "' when tag was not open. Tag discarded.");
+ return *this;
+ }
+ // ok, so etag is open.
+ // our strategy will be as below: we will do what we need to
+ // do to close this tag.
+ string estr = "Closing tag `" + to_utf8(etag.tag_)
+ + "' when other tags are pending. Discarded pending tags:\n";
+ for (dit = pending_tags_.begin(); dit != den; ++dit)
+ estr += to_utf8(xml::xmlize((*dit)->writeTag(), XMLStream::ESCAPE_ALL)) + "\n";
+ writeError(estr);
+ // clear the pending tags...
+ pending_tags_.clear();
+ // ...and then just fall through.
+ }
+
+ // make sure there are tags to be closed
+ if (tag_stack_.empty()) {
+ writeError("Tried to close `" + etag.tag_
+ + "' when no tags were open!");
+ return *this;
+ }
+
+ // is the tag we are closing the last one we opened?
+ if (etag == *tag_stack_.back()) {
+ // output it...
+ os_ << etag.writeEndTag();
+ // ...and forget about it
+ tag_stack_.pop_back();
+ return *this;
+ }
+
+ // we are trying to close a tag other than the one last opened.
+ // let's first see if this particular tag is still open somehow.
+ if (!isTagOpen(etag)) {
+ writeError("Tried to close `" + etag.tag_
+ + "' when tag was not open. Tag discarded.");
+ return *this;
+ }
+
+ // so the tag was opened, but other tags have been opened since
+ // and not yet closed.
+ // if it's a font tag, though...
+ if (etag.asFontTag()) {
+ // it won't be a problem if the other tags open since this one
+ // are also font tags.
+ TagDeque::const_reverse_iterator rit = tag_stack_.rbegin();
+ TagDeque::const_reverse_iterator ren = tag_stack_.rend();
+ for (; rit != ren; ++rit) {
+ if (etag == **rit)
+ break;
+ if (!(*rit)->asFontTag()) {
+ // we'll just leave it and, presumably, have to close it later.
+ writeError("Unable to close font tag `" + etag.tag_
+ + "' due to open non-font tag `" + (*rit)->tag_ + "'.");
+ return *this;
+ }
+ }
+
+ // so we have e.g.:
+ // <em>this is <strong>bold
+ // and are being asked to closed em. we want:
+ // <em>this is <strong>bold</strong></em><strong>
+ // first, we close the intervening tags...
+ TagPtr *curtag = &tag_stack_.back();
+ // ...remembering them in a stack.
+ TagDeque fontstack;
+ while (etag != **curtag) {
+ os_ << (*curtag)->writeEndTag();
+ fontstack.push_back(*curtag);
+ tag_stack_.pop_back();
+ curtag = &tag_stack_.back();
+ }
+ os_ << etag.writeEndTag();
+ tag_stack_.pop_back();
+
+ // ...and restore the other tags.
+ rit = fontstack.rbegin();
+ ren = fontstack.rend();
+ for (; rit != ren; ++rit)
+ pending_tags_.push_back(*rit);
+ return *this;
+ }
+
+ // it wasn't a font tag.
+ // so other tags were opened before this one and not properly closed.
+ // so we'll close them, too. that may cause other issues later, but it
+ // at least guarantees proper nesting.
+ writeError("Closing tag `" + etag.tag_
+ + "' when other tags are open, namely:");
+ TagPtr *curtag = &tag_stack_.back();
+ while (etag != **curtag) {
+ writeError((*curtag)->tag_);
+ if (**curtag != xml::parsep_tag)
+ os_ << (*curtag)->writeEndTag();
+ tag_stack_.pop_back();
+ curtag = &tag_stack_.back();
+ }
+ // curtag is now the one we actually want.
+ os_ << (*curtag)->writeEndTag();
+ tag_stack_.pop_back();
+
+ return *this;
+}
+
+
+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)
+{
+ // thread-safe
+ static atomic_uint seed(1000);
+ return label + convert<docstring>(++seed);
+}
+
+
+docstring xml::cleanID(docstring const &orig)
+{
+ // The standard xml:id only allows letters,
+ // digits, '-' and '.' in a name.
+ // This routine replaces illegal characters by '-' or '.'
+ // and adds a number for uniqueness if need be.
+ docstring const allowed = from_ascii(".-_");
+
+ // Use a cache of already mangled names: the alterations may merge several IDs as one. This ensures that the IDs
+ // are not mixed up in the document.
+ typedef map<docstring, docstring> MangledMap;
+ static QThreadStorage<MangledMap> tMangledNames;
+ static QThreadStorage<int> tMangleID;
+
+ MangledMap & mangledNames = tMangledNames.localData();
+
+ // If the name is already known, just return it.
+ MangledMap::const_iterator const known = mangledNames.find(orig);
+ if (known != mangledNames.end())
+ return known->second;
+
+ // Start creating the mangled name by iterating over the characters.
+ docstring content;
+ docstring::const_iterator it = orig.begin();
+ docstring::const_iterator end = orig.end();
+
+ // Make sure it starts with a letter.
+ if (!isAlphaASCII(*it) && allowed.find(*it) >= allowed.size())
+ content += "x";
+
+ // Do the mangling.
+ bool mangle = false; // Indicates whether the ID had to be changed, i.e. if ID no more ensured to be unique.
+ for (; it != end; ++it) {
+ char_type c = *it;
+ if (isAlphaASCII(c) || isDigitASCII(c) || c == '-' || c == '.'
+ || allowed.find(c) < allowed.size())
+ content += c;
+ else if (c == '_' || c == ' ') {
+ mangle = true;
+ content += "-";
+ }
+ else if (c == ':' || c == ',' || c == ';' || c == '!') {
+ mangle = true;
+ content += ".";
+ }
+ else {
+ mangle = true;
+ content += "-";
+ }
+ }
+
+ if (mangle) {
+ int & mangleID = tMangleID.localData();
+ content += "-" + convert<docstring>(mangleID++);
+ } else if (isDigitASCII(content[content.size() - 1]))
+ content += ".";
+
+ mangledNames[orig] = content;
+
+ return content;
+}
+
+
+void xml::openTag(odocstream & os, string const & name, string const & attribute)
+{
+ // FIXME UNICODE
+ // This should be fixed in layout files later.
+ string param = subst(attribute, "<", "\"");
+ param = subst(param, ">", "\"");
+
+ // Note: we ignore the name if it empty or if it is a comment "<!-- -->" or
+ // if the name is *dummy*.
+ // We ignore dummy because dummy is not a valid docbook element and it is
+ // the internal name given to single paragraphs in the latex output.
+ // This allow us to simplify the code a lot and is a reasonable compromise.
+ if (!name.empty() && name != "!-- --" && name != "dummy") {
+ os << '<' << from_ascii(name);
+ if (!param.empty())
+ os << ' ' << from_ascii(param);
+ os << '>';
+ }
+}
+
+
+void xml::closeTag(odocstream & os, string const & name)
+{
+ if (!name.empty() && name != "!-- --" && name != "dummy")
+ os << "</" << from_ascii(name) << '>';
+}
+
+
+void xml::openTag(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams, Paragraph const & par)
+{
+ Layout const & style = par.layout();
+ string const & name = style.latexname();
+ string param = style.latexparam();
+ Counters & counters = buf.params().documentClass().counters();
+
+ string id = par.getID(buf, runparams);
+
+ string attribute;
+ if (!id.empty()) {
+ if (param.find('#') != string::npos) {
+ string::size_type pos = param.find("id=<");
+ string::size_type end = param.find(">");
+ if( pos != string::npos && end != string::npos)
+ param.erase(pos, end-pos + 1);
+ }
+ attribute = id + ' ' + param;
+ } else {
+ if (param.find('#') != string::npos) {
+ // FIXME UNICODE
+ if (!style.counter.empty())
+ // This uses InternalUpdate at the moment becuase xml output
+ // does not do anything with tracked counters, and it would need
+ // to track layouts if it did want to use them.
+ counters.step(style.counter, InternalUpdate);
+ else
+ counters.step(from_ascii(name), InternalUpdate);
+ int i = counters.value(from_ascii(name));
+ attribute = subst(param, "#", convert<string>(i));
+ } else {
+ attribute = param;
+ }
+ }
+ openTag(os, name, attribute);
+}
+
+
+void xml::closeTag(odocstream & os, Paragraph const & par)
+{
+ Layout const & style = par.layout();
+ closeTag(os, style.latexname());
+}
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file xml.h
+ * This file is part of LyX, the document processor.
+ * License details can be found in the file COPYING.
+ *
+ * \author José Matos
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef XML_H
+#define XML_H
+
+#include "support/docstring.h"
+
+#include <deque>
+#include <memory>
+
+namespace lyx {
+
+class Buffer;
+class Paragraph;
+class OutputParams;
+
+// Inspiration for the *Tag structs and for XMLStream
+// came from MathStream and its cousins.
+
+namespace xml {
+struct StartTag;
+struct EndTag;
+struct CompTag;
+struct ParTag;
+struct FontTag;
+struct CR;
+}
+
+class XMLStream {
+public:
+ ///
+ explicit XMLStream(odocstream & os): os_(os), escape_(ESCAPE_ALL) {}
+ ///
+ odocstream & os() { return os_; }
+ ///
+ // int & tab() { return tab_; }
+ /// closes any font tags that are eligible to be closed,
+ /// i.e., last on the tag_stack_.
+ /// \return false if there are open font tags we could not close.
+ /// because they are "blocked" by open non-font tags on the stack.
+ bool closeFontTags();
+ /// sets a mark so we know what tags to close at the end.
+ /// normally called at the start of a paragraph.
+ void startDivision(bool keep_empty);
+ /// clears the mark set by previous method.
+ /// there should not be any other tags open before it on the stack,
+ /// but if there are, we will close them.
+ void endDivision();
+ ///
+ XMLStream & operator<<(docstring const &);
+ ///
+ XMLStream & operator<<(const char *);
+ ///
+ XMLStream & operator<<(char_type);
+ ///
+ XMLStream & operator<<(int);
+ ///
+ XMLStream & operator<<(char);
+ ///
+ XMLStream & operator<<(xml::StartTag const &);
+ ///
+ XMLStream & operator<<(xml::EndTag const &);
+ ///
+ XMLStream & operator<<(xml::CompTag const &);
+ ///
+ XMLStream & operator<<(xml::ParTag const &);
+ ///
+ XMLStream & operator<<(xml::FontTag const &);
+ ///
+ XMLStream & operator<<(xml::CR const &);
+ ///
+ enum EscapeSettings {
+ ESCAPE_NONE,
+ ESCAPE_AND, // meaning &
+ ESCAPE_ALL // meaning <, >, &, at present
+ };
+ /// Sets what we are going to escape on the NEXT write.
+ /// Everything is reset for the next time.
+ XMLStream & operator<<(EscapeSettings);
+ /// This routine is for debugging the tag stack, etc. Code
+ /// for it is disabled by default, however, so you will need
+ /// to enable it if you want to use it.
+ void dumpTagStack(std::string const & msg);
+private:
+ ///
+ void clearTagDeque();
+ ///
+ bool isTagOpen(xml::StartTag const &) const;
+ ///
+ bool isTagOpen(xml::EndTag const &) const;
+ ///
+ bool isTagPending(xml::StartTag const &) const;
+ ///
+ void writeError(std::string const &) const;
+ ///
+ void writeError(docstring const &) const;
+ ///
+ odocstream & os_;
+ ///
+ EscapeSettings escape_;
+ // What we would really like to do here is simply use a
+ // deque<StartTag>. But we want to store both StartTags and
+ // sub-classes thereof on this stack, which means we run into the
+ // so-called polymorphic class problem with the STL. We therefore have
+ // to use a deque<StartTag *>, which leads to the question who will
+ // own these pointers and how they will be deleted, so we use shared
+ // pointers.
+ ///
+ typedef std::shared_ptr<xml::StartTag> TagPtr;
+ typedef std::deque<TagPtr> TagDeque;
+ ///
+ template <typename T>
+ TagPtr makeTagPtr(T const & tag) { return std::make_shared<T>(tag); }
+ ///
+ TagDeque pending_tags_;
+ ///
+ TagDeque tag_stack_;
+};
+
+namespace xml {
+
+/// Escape the given character, if necessary, to an entity.
+docstring escapeChar(char_type c, XMLStream::EscapeSettings e);
+
+/// Escape the given character, if necessary, to an entity.
+docstring escapeChar(char c, XMLStream::EscapeSettings e);
+
+/// Escape a word instead of a single character
+docstring escapeString(docstring const & raw, XMLStream::EscapeSettings e=XMLStream::ESCAPE_ALL);
+
+/// Converts a string to a form safe for links, etc.
+docstring xmlize(docstring const &str, XMLStream::EscapeSettings e);
+
+/// cleans \param str for use as an attribute by replacing all non-altnum by "_"
+docstring cleanAttr(docstring const & str);
+
+/// \p c must be ASCII
+docstring escapeChar(char c, XMLStream::EscapeSettings e);
+
+/// replaces illegal characters from ID attributes
+docstring cleanID(docstring const &orig);
+
+/// returns a unique numeric ID
+docstring const uniqueID(docstring const & label);
+
+struct FontTag;
+struct EndFontTag;
+
+/// Attributes will be escaped automatically and so should NOT
+/// be escaped before being passed to the constructor.
+struct StartTag
+{
+ ///
+ explicit StartTag(std::string const & tag) : tag_(from_ascii(tag)), keepempty_(false) {}
+ ///
+ explicit StartTag(docstring const & tag) : tag_(tag), keepempty_(false) {}
+ ///
+ explicit StartTag(docstring const & tag, docstring const & attr,
+ bool keepempty = false)
+ : tag_(tag), attr_(attr), keepempty_(keepempty) {}
+ ///
+ explicit StartTag(std::string const & tag, std::string const & attr,
+ bool keepempty = false)
+ : tag_(from_ascii(tag)), attr_(from_ascii(attr)), keepempty_(keepempty) {}
+ ///
+ explicit StartTag(std::string const & tag, docstring const & attr,
+ bool keepempty = false)
+ : tag_(from_ascii(tag)), attr_(attr), keepempty_(keepempty) {}
+ ///
+ virtual ~StartTag() {}
+ /// <tag_ attr_>
+ virtual docstring writeTag() const;
+ /// </tag_>
+ virtual docstring writeEndTag() const;
+ ///
+ virtual FontTag const * asFontTag() const { return 0; }
+ ///
+ virtual bool operator==(StartTag const & rhs) const
+ { return tag_ == rhs.tag_; }
+ ///
+ virtual bool operator!=(StartTag const & rhs) const
+ { return !(*this == rhs); }
+ ///
+ virtual bool operator==(FontTag const & rhs) const;
+ ///
+ docstring tag_;
+ ///
+ docstring attr_;
+ /// whether to keep things like "<tag></tag>" or discard them
+ /// you would want this for td, e.g, but maybe not for a div
+ bool keepempty_;
+};
+
+
+///
+struct EndTag
+{
+ ///
+ explicit EndTag(std::string tag) : tag_(from_ascii(tag)) {}
+ ///
+ explicit EndTag(docstring tag) : tag_(tag) {}
+ ///
+ virtual ~EndTag() {}
+ /// </tag_>
+ virtual docstring writeEndTag() const;
+ ///
+ bool operator==(StartTag const & rhs) const
+ { return tag_ == rhs.tag_; }
+ ///
+ bool operator!=(StartTag const & rhs) const
+ { return !(*this == rhs); }
+ ///
+ virtual EndFontTag const * asFontTag() const { return 0; }
+ ///
+ docstring tag_;
+};
+
+
+/// Tags like <img />
+/// Attributes will be escaped automatically and so should NOT
+/// be escaped before being passed to the constructor.
+struct CompTag
+{
+ ///
+ explicit CompTag(std::string const & tag)
+ : tag_(tag) {}
+ ///
+ explicit CompTag(std::string const & tag, std::string const & attr)
+ : tag_(tag), attr_(attr) {}
+ /// <tag_ attr_ />
+ docstring writeTag() const;
+ ///
+ std::string tag_;
+ ///
+ std::string attr_;
+};
+
+
+/// A special case of StartTag, used exclusively for tags that wrap paragraphs.
+/// parid is only used for HTML output; XML is supposed to use attr for this. TODO: REMOVE PARID.
+struct ParTag : public StartTag
+{
+ ///
+ explicit ParTag(std::string const & tag, const std::string & attr): StartTag(tag, from_utf8(attr)) {}
+ ///
+ explicit ParTag(std::string const & tag, const std::string & attr, const std::string & parid):
+ StartTag(tag, from_utf8(attr + (parid.empty() ? (" id='" + parid + "'") : ""))) {}
+ ///
+ ~ParTag() {}
+};
+
+
+///
+enum FontTypes {
+ // ranges
+ FT_EMPH,
+ FT_NOUN,
+ FT_UBAR,
+ FT_DBAR,
+ FT_WAVE,
+ FT_SOUT,
+ FT_XOUT,
+ // bold
+ FT_BOLD,
+ // shapes
+ FT_UPRIGHT,
+ FT_ITALIC,
+ FT_SLANTED,
+ FT_SMALLCAPS,
+ // families
+ FT_ROMAN,
+ FT_SANS,
+ FT_TYPE,
+ // sizes
+ FT_SIZE_TINY,
+ FT_SIZE_SCRIPT,
+ FT_SIZE_FOOTNOTE,
+ FT_SIZE_SMALL,
+ FT_SIZE_NORMAL,
+ FT_SIZE_LARGE,
+ FT_SIZE_LARGER,
+ FT_SIZE_LARGEST,
+ FT_SIZE_HUGE,
+ FT_SIZE_HUGER,
+ FT_SIZE_INCREASE,
+ FT_SIZE_DECREASE
+
+ // When updating this list, also update fontToTag in both output_docbook.cpp and output_xhtml.cpp,
+ // fontToRole in output_docbook.cpp, and fontToAttribute in output_xhtml.cpp.
+};
+
+
+///
+struct FontTag : public StartTag
+{
+ ///
+ FontTag(docstring const & tag, FontTypes type): StartTag(tag), font_type_(type) {}
+ ///
+ FontTag(docstring const & tag, docstring const & attr, FontTypes type): StartTag(tag, attr), font_type_(type) {}
+ ///
+ FontTag const * asFontTag() const override { return this; }
+ ///
+ bool operator==(StartTag const &) const override;
+ ///
+ FontTypes font_type_;
+};
+
+
+///
+struct EndFontTag : public EndTag
+{
+ ///
+ EndFontTag(docstring const & tag, FontTypes type): EndTag(tag), font_type_(type) {}
+ ///
+ EndFontTag const * asFontTag() const override { return this; }
+ ///
+ FontTypes font_type_;
+};
+
+
+// trivial struct for output of newlines
+struct CR{};
+
+// an illegal tag for internal use
+xml::StartTag const parsep_tag("&LyX_parsep_tag&");
+
+/// Open tag
+void openTag(odocstream & os, std::string const & name,
+ std::string const & attribute = std::string());
+
+/// Open tag
+void openTag(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams, Paragraph const & par);
+
+/// Close tag
+void closeTag(odocstream & os, std::string const & name);
+
+/// Close tag
+void closeTag(odocstream & os, Paragraph const & par);
+
+} // namespace xml
+
+} // namespace lyx
+
+#endif // XML_H