Rename XHTMLStream to XMLStream, move it to another file, and prepare for DocBook adoption.

xml.cpp/h also merges functionalities from sgml.cpp/h.
This commit is contained in:
Thibaut Cuvelier 2019-05-10 01:35:40 +02:00 committed by Pavel Sanda
parent 9cec35697a
commit a6b07608d8
97 changed files with 1922 additions and 1883 deletions

View File

@ -125,7 +125,7 @@ SOURCES += \
../../src/Server.cpp \
../../src/ServerSocket.cpp \
../../src/Session.cpp \
../../src/sgml.cpp \
../../src/xml.cpp \
../../src/Spacing.cpp \
../../src/TexRow.cpp \
../../src/TexStream.cpp \
@ -476,7 +476,7 @@ HEADERS += \
../../src/Server.h \
../../src/ServerSocket.h \
../../src/Session.h \
../../src/sgml.h \
../../src/xml.h \
../../src/Spacing.h \
../../src/TexRow.h \
../../src/TexStream.h \

View File

@ -1159,7 +1159,7 @@ docstring BibTeXInfo::getValueForKey(string const & oldkey, Buffer const & buf,
}
if (cleanit)
ret = html::cleanAttr(ret);
ret = xml::cleanAttr(ret);
// make sure it is not too big
support::truncateWithEllipsis(ret, maxsize);

View File

@ -57,7 +57,7 @@
#include "PDFOptions.h"
#include "Session.h"
#include "SpellChecker.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "TexRow.h"
#include "Text.h"
@ -2195,13 +2195,13 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os, string const &
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;
}
@ -2259,7 +2259,7 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os,
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();
@ -2325,7 +2325,7 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os,
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();
@ -4123,7 +4123,7 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
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) {

View File

@ -1,7 +1,7 @@
# 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<EFBFBD>mmel, <syntheticpp@gmx.net>
#
project(${_lyx})

View File

@ -172,7 +172,7 @@ SOURCEFILESCORE = \
RowPainter.cpp \
Server.cpp \
ServerSocket.cpp \
sgml.cpp \
xml.cpp \
Session.cpp \
Spacing.cpp \
TexRow.cpp \
@ -279,7 +279,7 @@ HEADERFILESCORE = \
Server.h \
ServerSocket.h \
Session.h \
sgml.h \
xml.h \
Spacing.h \
SpellChecker.h \
TexRow.h \

View File

@ -37,9 +37,10 @@
#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"
@ -2930,7 +2931,7 @@ bool Paragraph::emptyTag() const
}
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) {
@ -2939,7 +2940,7 @@ string Paragraph::getID(Buffer const & buf, OutputParams const & runparams)
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)) + "'";
}
}
}
@ -2958,14 +2959,14 @@ pos_type Paragraph::firstWordDocBook(odocstream & os, OutputParams const & runpa
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;
@ -3038,7 +3039,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
if (style.pass_thru)
os.put(c);
else
os << sgml::escapeChar(c);
os << xml::escapeChar(c, XMLStream::EscapeSettings::ESCAPE_ALL);
}
font_old = font.fontInfo();
}
@ -3055,27 +3056,29 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
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;
@ -3110,8 +3113,8 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
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) {
@ -3124,260 +3127,260 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
// 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;
@ -3399,7 +3402,7 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
char_type c = getUChar(buf.masterBuffer()->params(),
runparams, i);
if (c == ' ' && (style.free_spacing || runparams.free_spacing))
xs << XHTMLStream::ESCAPE_NONE << "&nbsp;";
xs << XMLStream::ESCAPE_NONE << "&nbsp;";
else
xs << c;
}

View File

@ -50,7 +50,7 @@ class PainterInfo;
class ParagraphParameters;
class TocBackend;
class WordLangTuple;
class XHTMLStream;
class XMLStream;
class otexstream;
class FontSpan {
@ -203,7 +203,7 @@ public:
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,
@ -211,10 +211,11 @@ public:
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,

View File

@ -31,7 +31,7 @@
#include "LyXRC.h"
#include "Row.h"
#include "OutputParams.h"
#include "sgml.h"
#include "xml.h"
#include "TextClass.h"
#include "TexRow.h"

View File

@ -472,7 +472,7 @@ int Inset::docbook(odocstream &, OutputParams const &) const
}
docstring Inset::xhtml(XHTMLStream & xs, OutputParams const &) const
docstring Inset::xhtml(XMLStream & xs, OutputParams const &) const
{
xs << "[[Inset: " << from_ascii(insetName(lyxCode())) << "]]";
return docstring();

View File

@ -64,7 +64,7 @@ class ParIterator;
class Text;
class TocBackend;
class TocList;
class XHTMLStream;
class XMLStream;
class otexstream;
namespace graphics { class PreviewLoader; }
@ -343,11 +343,11 @@ public:
/// 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

View File

@ -56,7 +56,7 @@ public:
///
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;

View File

@ -343,7 +343,7 @@ void InsetBibitem::updateBuffer(ParIterator const & it, UpdateType utype, bool c
}
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
@ -352,11 +352,11 @@ docstring InsetBibitem::xhtml(XHTMLStream & xs, OutputParams const &) const
// 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();
}

View File

@ -58,7 +58,7 @@ public:
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

View File

@ -28,6 +28,7 @@
#include "LaTeXFeatures.h"
#include "output_latex.h"
#include "output_xhtml.h"
#include "xml.h"
#include "OutputParams.h"
#include "PDFOptions.h"
#include "texstream.h"
@ -1008,7 +1009,7 @@ int InsetBibtex::plaintext(odocstringstream & os,
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;
@ -1019,7 +1020,7 @@ int InsetBibtex::plaintext(odocstringstream & os,
// 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";
@ -1034,10 +1035,10 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
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();
@ -1049,27 +1050,27 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
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();
}

View File

@ -64,7 +64,9 @@ public:
///
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;
//@}

View File

@ -721,7 +721,7 @@ int InsetBox::docbook(odocstream & os, OutputParams const & runparams) 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 + "'";
@ -737,10 +737,10 @@ docstring InsetBox::xhtml(XHTMLStream & xs, OutputParams const & runparams) cons
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();
}

View File

@ -137,7 +137,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///

View File

@ -333,7 +333,7 @@ int InsetBranch::docbook(odocstream & os,
}
docstring InsetBranch::xhtml(XHTMLStream & xs, OutputParams const & rp) const
docstring InsetBranch::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (producesOutput()) {
OutputParams newrp = rp;

View File

@ -78,7 +78,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -302,7 +302,7 @@ int InsetCaption::docbook(odocstream & os,
}
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();
@ -317,9 +317,9 @@ docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const
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;
}
@ -364,7 +364,7 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os,
}
docstring InsetCaption::getCaptionAsHTML(XHTMLStream & xs,
docstring InsetCaption::getCaptionAsHTML(XMLStream & xs,
OutputParams const & runparams) const
{
xs << full_label_ << ' ';

View File

@ -31,7 +31,7 @@ public:
/// 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:
@ -78,7 +78,7 @@ 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;

View File

@ -87,11 +87,11 @@ docstring InsetCaptionable::getCaptionHTML(OutputParams const & runparams) 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();
}

View File

@ -322,8 +322,8 @@ inline docstring wrapCitation(docstring const & key,
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
@ -554,14 +554,14 @@ int InsetCitation::docbook(odocstream & os, OutputParams const &) const
}
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();
}

View File

@ -58,7 +58,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -17,7 +17,7 @@
#include "LaTeXFeatures.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "TextClass.h"
@ -194,7 +194,7 @@ int InsetCounter::docbook(odocstream &, OutputParams const &) const
}
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

View File

@ -41,7 +41,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -183,7 +183,7 @@ string InsetERT::params2string(CollapseStatus status)
}
docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}

View File

@ -54,7 +54,7 @@ private:
///
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?

View File

@ -33,6 +33,7 @@
#include "output_latex.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "xml.h"
#include "TocBackend.h"
#include "frontends/alert.h"
@ -789,7 +790,7 @@ int InsetExternal::docbook(odocstream & os,
}
docstring InsetExternal::xhtml(XHTMLStream & xs,
docstring InsetExternal::xhtml(XMLStream & xs,
OutputParams const & runparams) const
{
bool const external_in_tmpdir = !runparams.nice;
@ -804,7 +805,7 @@ docstring InsetExternal::xhtml(XHTMLStream & xs,
if (buffer().isClone() && buffer().isExporting())
throw ConversionException();
}
xs << XHTMLStream::ESCAPE_NONE << ods.str();
xs << XMLStream::ESCAPE_NONE << ods.str();
return docstring();
}

View File

@ -149,7 +149,7 @@ public:
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;
///

View File

@ -11,6 +11,7 @@
*/
#include <config.h>
#include <xml.h>
#include "InsetFloat.h"
#include "InsetCaption.h"
@ -32,6 +33,7 @@
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
#include "InsetList.h"
#include "support/debug.h"
#include "support/docstream.h"
@ -334,7 +336,7 @@ void InsetFloat::validate(LaTeXFeatures & features) const
}
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);
@ -342,12 +344,12 @@ docstring InsetFloat::xhtml(XHTMLStream & xs, OutputParams const & rp) const
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
@ -358,7 +360,7 @@ docstring InsetFloat::xhtml(XHTMLStream & xs, OutputParams const & rp) const
// 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;
}

View File

@ -101,7 +101,7 @@ private:
///
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

View File

@ -172,7 +172,7 @@ int InsetFloatList::plaintext(odocstringstream & os,
}
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"))];
@ -239,14 +239,14 @@ docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams const & op) const {
// 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();
@ -255,14 +255,14 @@ docstring InsetFloatList::xhtml(XHTMLStream &, OutputParams const & op) const {
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();
}

View File

@ -45,7 +45,7 @@ public:
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);
///

View File

@ -68,7 +68,7 @@ TODO
#include "Mover.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
@ -107,7 +107,7 @@ namespace Alert = frontend::Alert;
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?
@ -177,7 +177,7 @@ void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
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))
{
}
@ -185,7 +185,7 @@ InsetGraphics::InsetGraphics(Buffer * buf)
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());
@ -502,10 +502,6 @@ docstring InsetGraphics::createDocBookAttributes() const
// 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)) {
@ -942,14 +938,14 @@ static int writeImageObject(char const * format, odocstream & os,
{
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 << "\"/>" ;
@ -1078,7 +1074,7 @@ string InsetGraphics::prepareHTMLFile(OutputParams const & runparams) const
}
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);
@ -1087,7 +1083,7 @@ docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const
<< 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();
}
@ -1115,7 +1111,7 @@ docstring InsetGraphics::xhtml(XHTMLStream & xs, OutputParams const & op) const
string const attr = imgstyle + "src='" + output_file + "' alt='image: "
+ output_file + "'";
xs << html::CompTag("img", attr);
xs << xml::CompTag("img", attr);
return docstring();
}

View File

@ -80,7 +80,7 @@ public:
///
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.
*/

View File

@ -22,7 +22,7 @@
#include "LaTeXFeatures.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "support/docstream.h"
@ -218,20 +218,20 @@ int InsetHyperlink::docbook(odocstream & os, OutputParams const &) const
os << "<ulink url=\""
<< subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
<< "\">"
<< 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();
}

View File

@ -53,7 +53,7 @@ public:
///
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

View File

@ -233,7 +233,7 @@ void InsetIPA::latex(otexstream & os, OutputParams const & runparams_in) const
}
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;

View File

@ -77,7 +77,7 @@ public:
///
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;
///

View File

@ -312,7 +312,7 @@ int InsetIPADeco::docbook(odocstream & os, OutputParams const & runparams) 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 "&#x361;" (toptiebar)
// or "&#x35c;" (bottomtiebar) would need to be inserted just in the mid
@ -556,29 +556,29 @@ int InsetIPAChar::docbook(odocstream & /*os*/, OutputParams const &) const
}
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 << "&#x2e5;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e9;";
xs << XMLStream::ESCAPE_NONE << "&#x2e5;"
<< XMLStream::ESCAPE_NONE << "&#x2e9;";
break;
case TONE_RISING:
xs << XHTMLStream::ESCAPE_NONE << "&#x2e9;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e5;";
xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
<< XMLStream::ESCAPE_NONE << "&#x2e5;";
break;
case TONE_HIGH_RISING:
xs << XHTMLStream::ESCAPE_NONE << "&#x2e7;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e5;";
xs << XMLStream::ESCAPE_NONE << "&#x2e7;"
<< XMLStream::ESCAPE_NONE << "&#x2e5;";
break;
case TONE_LOW_RISING:
xs << XHTMLStream::ESCAPE_NONE << "&#x2e9;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e7;";
xs << XMLStream::ESCAPE_NONE << "&#x2e9;"
<< XMLStream::ESCAPE_NONE << "&#x2e7;";
break;
case TONE_HIGH_RISING_FALLING:
xs << XHTMLStream::ESCAPE_NONE << "&#x2e8;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e5;"
<< XHTMLStream::ESCAPE_NONE << "&#x2e8;";
xs << XMLStream::ESCAPE_NONE << "&#x2e8;"
<< XMLStream::ESCAPE_NONE << "&#x2e5;"
<< XMLStream::ESCAPE_NONE << "&#x2e8;";
break;
}
return docstring();

View File

@ -81,7 +81,7 @@ private:
///
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;
///
@ -152,7 +152,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -937,7 +937,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
}
docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
docstring InsetInclude::xhtml(XMLStream & xs, OutputParams const & rp) const
{
if (rp.inComment)
return docstring();
@ -947,11 +947,11 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
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();
}
@ -988,10 +988,10 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
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();

View File

@ -96,7 +96,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
@ -159,8 +159,8 @@ private:
/// 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.

View File

@ -27,7 +27,7 @@
#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"
@ -55,7 +55,7 @@ namespace lyx {
InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
: InsetCollapsible(buf), params_(params)
: InsetCollapsible(buf), params_(params)
{}
@ -67,7 +67,7 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
otexstringstream os;
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
&& params_.index != "idx") {
&& params_.index != "idx") {
os << "\\sindex[";
os << escape(params_.index);
os << "]{";
@ -112,12 +112,12 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
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();
@ -138,27 +138,27 @@ void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) cons
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 << '@';
}
@ -191,13 +191,13 @@ int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
}
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();
}
@ -707,7 +707,7 @@ bool operator<(IndexEntry const & lhs, IndexEntry const & rhs)
} // namespace
docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const
{
BufferParams const & bp = buffer().masterBuffer()->params();
@ -747,14 +747,14 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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();
@ -774,11 +774,11 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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;
}
}
@ -789,11 +789,11 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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;
}
}
@ -802,7 +802,7 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// close the entry.
if (level == 1 && !eit->same_main(last)) {
// close entry
xs << html::EndTag("li") << html::CR();
xs << xml::EndTag("li") << xml::CR();
}
}
@ -812,7 +812,7 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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);
@ -830,8 +830,8 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
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
@ -844,14 +844,14 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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 {
@ -866,20 +866,20 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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;
}
}
@ -888,16 +888,16 @@ docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
// 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();
}

View File

@ -59,7 +59,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void latex(otexstream &, OutputParams const &) const;
///
@ -105,7 +105,7 @@ public:
///
void latex(otexstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///

View File

@ -27,7 +27,7 @@
#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"
@ -351,24 +351,24 @@ int InsetLabel::plaintext(odocstringstream & os,
}
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();
}

View File

@ -55,7 +55,7 @@ public:
///
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);
///

View File

@ -190,9 +190,9 @@ int InsetLine::docbook(odocstream & os, OutputParams const &) const
}
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();
}

View File

@ -43,7 +43,7 @@ private:
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;

View File

@ -433,21 +433,21 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) 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();
@ -457,21 +457,21 @@ docstring InsetListings::xhtml(XHTMLStream & os, OutputParams const & rp) const
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;

View File

@ -56,7 +56,7 @@ private:
///
void latex(otexstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///

View File

@ -178,9 +178,9 @@ int InsetNewline::docbook(odocstream & os, OutputParams const &) 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();
}

View File

@ -65,7 +65,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///

View File

@ -255,9 +255,9 @@ int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
}
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();
}

View File

@ -68,7 +68,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///

View File

@ -30,7 +30,7 @@
#include "LyX.h"
#include "OutputParams.h"
#include "output_xhtml.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
@ -55,7 +55,7 @@ namespace lyx {
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")))
{}
@ -108,13 +108,13 @@ int InsetNomencl::plaintext(odocstringstream & os,
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();
}
@ -124,10 +124,10 @@ int InsetNomencl::docbookGlossary(odocstream & os) const
{
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;
@ -200,7 +200,7 @@ struct NomenclEntry {
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");
@ -234,42 +234,42 @@ docstring InsetPrintNomencl::xhtml(XHTMLStream &, OutputParams const & op) const
// 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();
}

View File

@ -50,7 +50,7 @@ public:
///
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
@ -94,7 +94,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
InsetCode lyxCode() const;
///

View File

@ -290,7 +290,7 @@ int InsetNote::docbook(odocstream & os, OutputParams const & runparams_in) 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();

View File

@ -90,7 +90,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///

View File

@ -367,7 +367,7 @@ int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) const
}
docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const
docstring InsetPhantom::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}

View File

@ -81,7 +81,7 @@ private:
///
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;
///

View File

@ -536,6 +536,79 @@ docstring InsetQuotesParams::getHTMLQuote(char_type c) const
}
docstring InsetQuotesParams::getXMLQuote(char_type c) const
{
string res;
switch (c){
case 0x201a: // ,
res = "&#8218;";
break;
case 0x2019: // '
res = "&#8217;";
break;
case 0x2018: // `
res = "&#8216;";
break;
case 0x2039: // <
res = "&#8249;";
break;
case 0x203a: // >
res = "&#8250;";
break;
case 0x0027: // ' (plain)
res = "&#x27;";
break;
case 0x201e: // ,,
res = "&#8222;";
break;
case 0x201d: // ''
res = "&#8221;";
break;
case 0x201c: // ``
res = "&#8220;";
break;
case 0x00ab: // <<
res = "&#171;";
break;
case 0x00bb: // >>
res = "&#187;";
break;
case 0x0022: // "
res = "&#34;";
break;
case 0x300c: // LEFT CORNER BRACKET
res = "&#x300c;";
break;
case 0x300d: // RIGHT CORNER BRACKET
res = "&#x300d;";
break;
case 0x300e: // LEFT WHITE CORNER BRACKET
res = "&#x300e;";
break;
case 0x300f: // RIGHT WHITE CORNER BRACKET
res = "&#x300f;";
break;
case 0x300a: // LEFT DOUBLE ANGLE BRACKET
res = "&#x300a;";
break;
case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
res = "&#x300b;";
break;
case 0x3008: // LEFT ANGLE BRACKET
res = "&#x3008;";
break;
case 0x3009: // RIGHT ANGLE BRACKET
res = "&#x3009;";
break;
default:
break;
}
return from_ascii(res);
}
map<string, docstring> InsetQuotesParams::getTypes() const
{
map<string, docstring> res;
@ -946,10 +1019,11 @@ int InsetQuotes::plaintext(odocstringstream & os,
}
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
@ -969,14 +1043,14 @@ docstring InsetQuotes::getQuoteEntity() const {
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();
}

View File

@ -82,6 +82,8 @@ public:
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);
@ -146,7 +148,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
@ -180,7 +182,7 @@ private:
///
docstring displayString() const;
///
docstring getQuoteEntity() const;
docstring getQuoteEntity(bool isHTML) const;
///
InsetQuotesParams::QuoteStyle getStyle(std::string const &);

View File

@ -24,7 +24,7 @@
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "sgml.h"
#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
@ -315,16 +315,16 @@ int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const
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>";
@ -334,7 +334,7 @@ int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const
}
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);
@ -375,10 +375,10 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const & op) const
// 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();
}

View File

@ -65,7 +65,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -174,9 +174,9 @@ int InsetSeparator::docbook(odocstream & os, OutputParams const &) 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();
}

View File

@ -79,7 +79,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void read(Lexer & lex);
///

View File

@ -762,7 +762,7 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
}
docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
docstring InsetSpace::xhtml(XMLStream & xs, OutputParams const &) const
{
string output;
switch (params_.kind) {
@ -822,7 +822,7 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
break;
}
// don't escape the entities!
xs << XHTMLStream::ESCAPE_NONE << from_ascii(output);
xs << XMLStream::ESCAPE_NONE << from_ascii(output);
return docstring();
}

View File

@ -129,7 +129,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures & features) const;
///

View File

@ -551,31 +551,31 @@ int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) 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 << "&#8203;";
xs << XMLStream::ESCAPE_NONE << "&#8203;";
break;
case LIGATURE_BREAK:
xs << XHTMLStream::ESCAPE_NONE << "&#8204;";
xs << XMLStream::ESCAPE_NONE << "&#8204;";
break;
case END_OF_SENTENCE:
xs << '.';
break;
case LDOTS:
xs << XHTMLStream::ESCAPE_NONE << "&hellip;";
xs << XMLStream::ESCAPE_NONE << "&hellip;";
break;
case MENU_SEPARATOR:
xs << XHTMLStream::ESCAPE_NONE << "&rArr;";
xs << XMLStream::ESCAPE_NONE << "&rArr;";
break;
case SLASH:
xs << XHTMLStream::ESCAPE_NONE << "&frasl;";
xs << XMLStream::ESCAPE_NONE << "&frasl;";
break;
case NOBREAKDASH:
xs << XHTMLStream::ESCAPE_NONE << "&#8209;";
xs << XMLStream::ESCAPE_NONE << "&#8209;";
break;
case PHRASE_LYX:
xs << "LyX";
@ -584,7 +584,7 @@ docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const
xs << "TeX";
break;
case PHRASE_LATEX2E:
xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "&#x3b5;";
xs << "LaTeX2" << XMLStream::ESCAPE_NONE << "&#x3b5;";
break;
case PHRASE_LATEX:
xs << "LaTeX";

View File

@ -78,7 +78,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void toString(odocstream &) const;
///

View File

@ -136,11 +136,11 @@ int InsetTOC::docbook(odocstream & os, OutputParams const &) 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();
@ -152,11 +152,11 @@ void InsetTOC::makeTOCEntry(XHTMLStream & xs,
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();
@ -177,13 +177,13 @@ void InsetTOC::makeTOCWithDepth(XHTMLStream & xs,
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;
}
@ -191,18 +191,18 @@ void InsetTOC::makeTOCWithDepth(XHTMLStream & xs,
// 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
@ -210,11 +210,11 @@ void InsetTOC::makeTOCWithDepth(XHTMLStream & xs,
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();
@ -225,17 +225,17 @@ void InsetTOC::makeTOCNoDepth(XHTMLStream & xs,
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") {
@ -252,9 +252,9 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
// 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();
@ -263,9 +263,9 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
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.
@ -277,7 +277,7 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
else
makeTOCNoDepth(xs, *toc, op);
xs << html::EndTag("div") << html::CR();
xs << xml::EndTag("div") << xml::CR();
return ods.str();
}

View File

@ -46,7 +46,7 @@ public:
///
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);
///
@ -65,11 +65,11 @@ public:
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
//@{

View File

@ -3649,14 +3649,14 @@ int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
}
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;
@ -3700,17 +3700,17 @@ docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
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;
@ -3728,20 +3728,20 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
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);
@ -3750,7 +3750,7 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
// 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)) &&
@ -3758,14 +3758,14 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
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)) &&
@ -3773,21 +3773,21 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
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;
}
@ -4167,7 +4167,7 @@ void InsetTableCell::addToToc(DocIterator const & di, bool output_active,
}
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);
@ -4203,7 +4203,6 @@ void InsetTableCell::metrics(MetricsInfo & mi, Dimension & dim) const
}
/////////////////////////////////////////////////////////////////////
//
// InsetTabular
@ -6028,7 +6027,7 @@ int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
}
docstring InsetTabular::xhtml(XHTMLStream & xs, OutputParams const & rp) const
docstring InsetTabular::xhtml(XMLStream & xs, OutputParams const & rp) const
{
return tabular.xhtml(xs, rp);
}

View File

@ -44,7 +44,7 @@ class FuncStatus;
class Lexer;
class OutputParams;
class Paragraph;
class XHTMLStream;
class XMLStream;
///
@ -72,7 +72,7 @@ public:
/// 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;
@ -573,7 +573,7 @@ public:
///
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,
@ -908,7 +908,7 @@ public:
/// 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
@ -981,7 +981,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void validate(LaTeXFeatures & features) const;
///

View File

@ -45,7 +45,7 @@
#include "ParagraphParameters.h"
#include "ParIterator.h"
#include "Row.h"
#include "sgml.h"
#include "xml.h"
#include "TexRow.h"
#include "texstream.h"
#include "TextClass.h"
@ -590,19 +590,19 @@ int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
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);
}
@ -621,7 +621,7 @@ docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) con
// 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
@ -639,7 +639,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
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();
@ -651,15 +651,15 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
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)
@ -672,10 +672,10 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
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();
}

View File

@ -83,7 +83,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
enum XHTMLOptions {
JustText = 0,
@ -93,7 +93,7 @@ public:
WriteEverything = 7
};
///
docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
docstring insetAsXHTML(XMLStream &, OutputParams const &,
XHTMLOptions) const;
///
void validate(LaTeXFeatures & features) const;

View File

@ -231,11 +231,11 @@ int InsetVSpace::docbook(odocstream & os, OutputParams const &) 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();
}

View File

@ -56,7 +56,7 @@ private:
/// 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);
///

View File

@ -217,17 +217,17 @@ int InsetWrap::docbook(odocstream & os, OutputParams const & runparams) const
}
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;
}

View File

@ -74,7 +74,7 @@ private:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
bool insetAllowed(InsetCode) const;
///

View File

@ -41,7 +41,7 @@
#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"
@ -2416,7 +2416,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
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 << '>';
@ -2446,9 +2446,9 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
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("\"/>");
@ -2585,7 +2585,7 @@ void InsetMathHull::mathAsLatex(WriteStream & os) const
}
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;
@ -2611,14 +2611,14 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
} 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;
@ -2629,10 +2629,10 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
} 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);
}
}
@ -2672,11 +2672,11 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
}
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;
}
}
@ -2699,10 +2699,10 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
// 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();
}

View File

@ -146,7 +146,7 @@ public:
///
int docbook(odocstream &, OutputParams const &) const;
///
docstring xhtml(XHTMLStream &, OutputParams const &) const;
docstring xhtml(XMLStream &, OutputParams const &) const;
///
void mathmlize(MathStream &) const;
///

View File

@ -1263,7 +1263,7 @@ int InsetMathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition)
}
docstring InsetMathMacroTemplate::xhtml(XHTMLStream &, OutputParams const &) const
docstring InsetMathMacroTemplate::xhtml(XMLStream &, OutputParams const &) const
{
return docstring();
}

View File

@ -21,7 +21,7 @@
namespace lyx {
class OutputParams;
class XHTMLStream;
class XMLStream;
/// This class contains the macro definition.
class InsetMathMacroTemplate : public InsetMathNest {
@ -52,7 +52,7 @@ public:
/// 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;
///

View File

@ -24,7 +24,7 @@
#include "MathSupport.h"
#include "OutputParams.h"
#include "ParIterator.h"
#include "sgml.h"
#include "xml.h"
#include "insets/InsetCommand.h"
@ -186,14 +186,14 @@ int InsetMathRef::docbook(odocstream & os, OutputParams const & runparams) const
{
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>";

View File

@ -23,7 +23,7 @@
#include "Paragraph.h"
#include "ParagraphList.h"
#include "ParagraphParameters.h"
#include "sgml.h"
#include "xml.h"
#include "Text.h"
#include "TextClass.h"
@ -41,6 +41,45 @@ namespace lyx {
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)
@ -115,10 +154,10 @@ ParagraphList::const_iterator makeParagraph(
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;
@ -140,7 +179,7 @@ ParagraphList::const_iterator makeEnvironment(
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[";
@ -156,23 +195,23 @@ ParagraphList::const_iterator makeEnvironment(
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:
@ -183,10 +222,10 @@ ParagraphList::const_iterator makeEnvironment(
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 {
@ -212,7 +251,7 @@ ParagraphList::const_iterator makeEnvironment(
switch (bstyle.latextype) {
case LATEX_ENVIRONMENT:
if (!bstyle.innertag().empty()) {
sgml::closeTag(os, bstyle.innertag());
xml::closeTag(os, bstyle.innertag());
os << '\n';
}
break;
@ -226,10 +265,10 @@ ParagraphList::const_iterator makeEnvironment(
// 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;
@ -240,7 +279,7 @@ ParagraphList::const_iterator makeEnvironment(
os << "]]>";
// Closing outer tag
sgml::closeTag(os, *pbegin);
xml::closeTag(os, *pbegin);
return pend;
}
@ -259,22 +298,22 @@ ParagraphList::const_iterator makeCommand(
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;
@ -307,7 +346,7 @@ ParagraphList::const_iterator makeCommand(
}
}
// Close outter tag
sgml::closeTag(os, *pbegin);
xml::closeTag(os, *pbegin);
return pend;
}

View File

@ -14,9 +14,12 @@
#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;

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#include "support/docstream.h"
#include "support/strfwd.h"
#include "xml.h"
#include <deque>
#include <memory>
@ -23,286 +24,27 @@
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() {}
};
xml::FontTag xhtmlStartFontTag(xml::FontTypes type);
///
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_;
};
///
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

View File

@ -1,257 +0,0 @@
/**
* \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 += "&amp;";
break;
case '<':
str += "&lt;";
break;
case '>':
str += "&gt;";
break;
#if 0
case '$':
str += "&dollar;";
break;
case '#':
str += "&num;";
break;
case '%':
str += "&percnt;";
break;
case '[':
str += "&lsqb;";
break;
case ']':
str += "&rsqb;";
break;
case '{':
str += "&lcub;";
break;
case '}':
str += "&rcub;";
break;
case '~':
str += "&tilde;";
break;
case '"':
str += "&quot;";
break;
case '\\':
str += "&bsol;";
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

View File

@ -1,59 +0,0 @@
// -*- 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

View File

@ -5,6 +5,7 @@
#include "LyXRC.h"
#include "support/Messages.h"
#include "xml.h"
using namespace std;
@ -49,4 +50,10 @@ string alignmentToCSS(LyXAlignment)
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

View File

@ -114,4 +114,10 @@ string alignmentToCSS(LyXAlignment)
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

690
src/xml.cpp Normal file
View File

@ -0,0 +1,690 @@
/**
* \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 += "&lt;";
break;
} else if (c == '>') {
str += "&gt;";
break;
}
// fall through
case XMLStream::ESCAPE_AND:
if (c == '&')
str += "&amp;";
else
str +=c ;
break;
}
return str;
}
// escape what needs escaping
docstring xmlize(docstring const &str, XMLStream::EscapeSettings e) {
odocstringstream d;
docstring::const_iterator it = str.begin();
docstring::const_iterator en = str.end();
for (; it != en; ++it)
d << escapeChar(*it, e);
return d.str();
}
docstring escapeChar(char c, XMLStream::EscapeSettings e) {
LATTEST(static_cast<unsigned char>(c) < 0x80);
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

355
src/xml.h Normal file
View File

@ -0,0 +1,355 @@
// -*- 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