From a6b07608d8e9de24383d3ebaec20b6b265ed9314 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 10 May 2019 01:35:40 +0200 Subject: [PATCH] Rename XHTMLStream to XMLStream, move it to another file, and prepare for DocBook adoption. xml.cpp/h also merges functionalities from sgml.cpp/h. --- development/attic/qmake/lyx.pro | 4 +- src/BiblioInfo.cpp | 2 +- src/Buffer.cpp | 12 +- src/CMakeLists.txt | 2 +- src/Makefile.am | 4 +- src/Paragraph.cpp | 443 +++++++------- src/Paragraph.h | 7 +- src/ParagraphMetrics.cpp | 2 +- src/insets/Inset.cpp | 2 +- src/insets/Inset.h | 6 +- src/insets/InsetArgument.h | 2 +- src/insets/InsetBibitem.cpp | 10 +- src/insets/InsetBibitem.h | 2 +- src/insets/InsetBibtex.cpp | 31 +- src/insets/InsetBibtex.h | 4 +- src/insets/InsetBox.cpp | 6 +- src/insets/InsetBox.h | 2 +- src/insets/InsetBranch.cpp | 2 +- src/insets/InsetBranch.h | 2 +- src/insets/InsetCaption.cpp | 8 +- src/insets/InsetCaption.h | 4 +- src/insets/InsetCaptionable.cpp | 4 +- src/insets/InsetCitation.cpp | 8 +- src/insets/InsetCitation.h | 2 +- src/insets/InsetCounter.cpp | 4 +- src/insets/InsetCounter.h | 2 +- src/insets/InsetERT.cpp | 2 +- src/insets/InsetERT.h | 2 +- src/insets/InsetExternal.cpp | 5 +- src/insets/InsetExternal.h | 2 +- src/insets/InsetFloat.cpp | 12 +- src/insets/InsetFloat.h | 2 +- src/insets/InsetFloatList.cpp | 20 +- src/insets/InsetFloatList.h | 2 +- src/insets/InsetGraphics.cpp | 30 +- src/insets/InsetGraphics.h | 2 +- src/insets/InsetHyperlink.cpp | 12 +- src/insets/InsetHyperlink.h | 2 +- src/insets/InsetIPA.cpp | 2 +- src/insets/InsetIPA.h | 2 +- src/insets/InsetIPAMacro.cpp | 26 +- src/insets/InsetIPAMacro.h | 4 +- src/insets/InsetInclude.cpp | 10 +- src/insets/InsetInclude.h | 6 +- src/insets/InsetIndex.cpp | 100 ++-- src/insets/InsetIndex.h | 4 +- src/insets/InsetLabel.cpp | 12 +- src/insets/InsetLabel.h | 2 +- src/insets/InsetLine.cpp | 4 +- src/insets/InsetLine.h | 2 +- src/insets/InsetListings.cpp | 24 +- src/insets/InsetListings.h | 2 +- src/insets/InsetNewline.cpp | 4 +- src/insets/InsetNewline.h | 2 +- src/insets/InsetNewpage.cpp | 4 +- src/insets/InsetNewpage.h | 2 +- src/insets/InsetNomencl.cpp | 52 +- src/insets/InsetNomencl.h | 4 +- src/insets/InsetNote.cpp | 2 +- src/insets/InsetNote.h | 2 +- src/insets/InsetPhantom.cpp | 2 +- src/insets/InsetPhantom.h | 2 +- src/insets/InsetQuotes.cpp | 84 ++- src/insets/InsetQuotes.h | 6 +- src/insets/InsetRef.cpp | 16 +- src/insets/InsetRef.h | 2 +- src/insets/InsetSeparator.cpp | 4 +- src/insets/InsetSeparator.h | 2 +- src/insets/InsetSpace.cpp | 4 +- src/insets/InsetSpace.h | 2 +- src/insets/InsetSpecialChar.cpp | 16 +- src/insets/InsetSpecialChar.h | 2 +- src/insets/InsetTOC.cpp | 40 +- src/insets/InsetTOC.h | 8 +- src/insets/InsetTabular.cpp | 49 +- src/insets/InsetTabular.h | 10 +- src/insets/InsetText.cpp | 22 +- src/insets/InsetText.h | 4 +- src/insets/InsetVSpace.cpp | 4 +- src/insets/InsetVSpace.h | 2 +- src/insets/InsetWrap.cpp | 6 +- src/insets/InsetWrap.h | 2 +- src/mathed/InsetMathHull.cpp | 40 +- src/mathed/InsetMathHull.h | 2 +- src/mathed/InsetMathMacroTemplate.cpp | 2 +- src/mathed/InsetMathMacroTemplate.h | 4 +- src/mathed/InsetMathRef.cpp | 6 +- src/output_docbook.cpp | 81 ++- src/output_docbook.h | 3 + src/output_xhtml.cpp | 794 ++++---------------------- src/output_xhtml.h | 270 +-------- src/sgml.cpp | 257 --------- src/sgml.h | 59 -- src/tests/dummy_functions.cpp | 7 + src/tex2lyx/dummy_impl.cpp | 6 + src/xml.cpp | 690 ++++++++++++++++++++++ src/xml.h | 355 ++++++++++++ 97 files changed, 1923 insertions(+), 1884 deletions(-) delete mode 100644 src/sgml.cpp delete mode 100644 src/sgml.h create mode 100644 src/xml.cpp create mode 100644 src/xml.h diff --git a/development/attic/qmake/lyx.pro b/development/attic/qmake/lyx.pro index de5624bcf7..0db456c44a 100644 --- a/development/attic/qmake/lyx.pro +++ b/development/attic/qmake/lyx.pro @@ -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 \ diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index bf7fb85ed6..f43d4149ab 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -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); diff --git a/src/Buffer.cpp b/src/Buffer.cpp index c8941e3043..03368dc876 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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 << "" << (doctitle.empty() ? from_ascii("LyX Document") : - html::htmlize(doctitle, XHTMLStream::ESCAPE_ALL)) + xml::xmlize(doctitle, XMLStream::ESCAPE_ALL)) << "\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 << "\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 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) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7793179431..d7cf9c7bc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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, +# Copyright (c) 2006-2011 Peter K�mmel, # project(${_lyx}) diff --git a/src/Makefile.am b/src/Makefile.am index ddc82fb1da..f6a77dc0bd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 837dc0dd48..10b6456adf 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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(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 & tagsToOpen, - vector & tagsToClose, - bool & flag, FontState curstate, html::FontTypes type) + +void doFontSwitchXHTML(vector & tagsToOpen, + vector & 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 tagsToOpen; - vector tagsToClose; + vector tagsToOpen; + vector 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::const_iterator cit = tagsToClose.begin(); - vector::const_iterator cen = tagsToClose.end(); + vector::const_iterator cit = tagsToClose.begin(); + vector::const_iterator cen = tagsToClose.end(); for (; cit != cen; ++cit) xs << *cit; - vector::const_iterator sit = tagsToOpen.begin(); - vector::const_iterator sen = tagsToOpen.end(); + vector::const_iterator sit = tagsToOpen.begin(); + vector::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 << " "; + xs << XMLStream::ESCAPE_NONE << " "; else xs << c; } diff --git a/src/Paragraph.h b/src/Paragraph.h index 3b5f2b8162..60b829e813 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -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, diff --git a/src/ParagraphMetrics.cpp b/src/ParagraphMetrics.cpp index 1d3ce0db5c..0cbe3e9a76 100644 --- a/src/ParagraphMetrics.cpp +++ b/src/ParagraphMetrics.cpp @@ -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" diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 77a1449826..904ac81686 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -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(); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 457ff44cb9..1366ca59f2 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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 diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 15d3b85fd2..8cc3e08722 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -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; diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index c70e92ea73..85c6a5990f 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -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 , 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(); } diff --git a/src/insets/InsetBibitem.h b/src/insets/InsetBibitem.h index eda3a4626f..22e3ac112b 100644 --- a/src/insets/InsetBibitem.h +++ b/src/insets/InsetBibitem.h @@ -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 diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 15953e1cde..3bfc593013 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -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 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::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(); } diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index a46619367b..db7005d2da 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -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; //@} diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 8a867ee234..0b2ab3eea1 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -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(); } diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h index 6dd671c9a4..4e9894548c 100644 --- a/src/insets/InsetBox.h +++ b/src/insets/InsetBox.h @@ -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; /// diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index ad7cbc5cdc..6d87af7fae 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -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; diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index be926d99f5..1723fd1484 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -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; /// diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 32ead24679..42f951989c 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -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_ << ' '; diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index a651a71a56..be0d163041 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -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; diff --git a/src/insets/InsetCaptionable.cpp b/src/insets/InsetCaptionable.cpp index 1a2e5f0670..61c9acc3b8 100644 --- a/src/insets/InsetCaptionable.cpp +++ b/src/insets/InsetCaptionable.cpp @@ -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(); } diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 497f313f45..0335b9c771 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -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 "" + - html::htmlize(content, XHTMLStream::ESCAPE_ALL) + ""; + return "" + + xml::xmlize(content, XMLStream::ESCAPE_ALL) + ""; } } // 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(); } diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index b2a738cd9e..c7cd8dcb60 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -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; /// diff --git a/src/insets/InsetCounter.cpp b/src/insets/InsetCounter.cpp index 5b2d1dbf31..85efd3add2 100644 --- a/src/insets/InsetCounter.cpp +++ b/src/insets/InsetCounter.cpp @@ -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 diff --git a/src/insets/InsetCounter.h b/src/insets/InsetCounter.h index a050532e09..65334a3836 100644 --- a/src/insets/InsetCounter.h +++ b/src/insets/InsetCounter.h @@ -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; /// diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index e3863ea09d..403df75032 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -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(); } diff --git a/src/insets/InsetERT.h b/src/insets/InsetERT.h index 30938e0ee0..6ef43760d9 100644 --- a/src/insets/InsetERT.h +++ b/src/insets/InsetERT.h @@ -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? diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index f604a1fb9d..7fd96cbb1d 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -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(); } diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index eefce3a10d..b03e416de8 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -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; /// diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 5e1dd3d7fc..a37b954947 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -11,6 +11,7 @@ */ #include +#include #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; } diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index 53c584c40a..f58c89c2f6 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -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 diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp index 1ba8dea8e7..e711feebf4 100644 --- a/src/insets/InsetFloatList.cpp +++ b/src/insets/InsetFloatList.cpp @@ -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(); } diff --git a/src/insets/InsetFloatList.h b/src/insets/InsetFloatList.h index 7d1df4765a..7841709640 100644 --- a/src/insets/InsetFloatList.h +++ b/src/insets/InsetFloatList.h @@ -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); /// diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 92de4c043f..a5a9ef320e 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -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(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 << "" ; @@ -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(); } diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index be4a31773a..46a746b9d4 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -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. */ diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index a225a8eb0b..6246ff840a 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -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 << "" - << sgml::escapeString(getParam("name")) + << xml::escapeString(getParam("name")) << ""; 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(); } diff --git a/src/insets/InsetHyperlink.h b/src/insets/InsetHyperlink.h index d5da130d76..0e0e8d3446 100644 --- a/src/insets/InsetHyperlink.h +++ b/src/insets/InsetHyperlink.h @@ -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 diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp index ac2b7d8422..e11f0cc1f5 100644 --- a/src/insets/InsetIPA.cpp +++ b/src/insets/InsetIPA.cpp @@ -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; diff --git a/src/insets/InsetIPA.h b/src/insets/InsetIPA.h index d499edfdc8..003c1bad56 100644 --- a/src/insets/InsetIPA.h +++ b/src/insets/InsetIPA.h @@ -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; /// diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp index 4b2369b379..91c5c88176 100644 --- a/src/insets/InsetIPAMacro.cpp +++ b/src/insets/InsetIPAMacro.cpp @@ -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 "͡" (toptiebar) // or "͜" (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 << "˥" - << XHTMLStream::ESCAPE_NONE << "˩"; + xs << XMLStream::ESCAPE_NONE << "˥" + << XMLStream::ESCAPE_NONE << "˩"; break; case TONE_RISING: - xs << XHTMLStream::ESCAPE_NONE << "˩" - << XHTMLStream::ESCAPE_NONE << "˥"; + xs << XMLStream::ESCAPE_NONE << "˩" + << XMLStream::ESCAPE_NONE << "˥"; break; case TONE_HIGH_RISING: - xs << XHTMLStream::ESCAPE_NONE << "˧" - << XHTMLStream::ESCAPE_NONE << "˥"; + xs << XMLStream::ESCAPE_NONE << "˧" + << XMLStream::ESCAPE_NONE << "˥"; break; case TONE_LOW_RISING: - xs << XHTMLStream::ESCAPE_NONE << "˩" - << XHTMLStream::ESCAPE_NONE << "˧"; + xs << XMLStream::ESCAPE_NONE << "˩" + << XMLStream::ESCAPE_NONE << "˧"; break; case TONE_HIGH_RISING_FALLING: - xs << XHTMLStream::ESCAPE_NONE << "˨" - << XHTMLStream::ESCAPE_NONE << "˥" - << XHTMLStream::ESCAPE_NONE << "˨"; + xs << XMLStream::ESCAPE_NONE << "˨" + << XMLStream::ESCAPE_NONE << "˥" + << XMLStream::ESCAPE_NONE << "˨"; break; } return docstring(); diff --git a/src/insets/InsetIPAMacro.h b/src/insets/InsetIPAMacro.h index fb35adb763..b985ef3b7b 100644 --- a/src/insets/InsetIPAMacro.h +++ b/src/insets/InsetIPAMacro.h @@ -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; /// diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 5f1af32640..ba52db91c2 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -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 << ""; return docstring(); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 66487bc934..64e01e46d5 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -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. diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 5e375e9fdb..11a8545280 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -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 const levels = - getVectorFromString(latexstr, from_ascii("!"), true); + getVectorFromString(latexstr, from_ascii("!"), true); std::vector const levels_plain = - getVectorFromString(plainstr, from_ascii("!"), true); + getVectorFromString(plainstr, from_ascii("!"), true); vector::const_iterator it = levels.begin(); vector::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 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::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(); } diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 504eb84720..46fe845769 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -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); /// diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 30211b8e19..4432493319 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -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 << ""; 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(); } diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index ab54e5e959..8d063168b6 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -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); /// diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index c1c890c2ed..d76ba16c3d 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -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(); } diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h index f518297445..7be587028f 100644 --- a/src/insets/InsetLine.h +++ b/src/insets/InsetLine.h @@ -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; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index f2af5813bd..7f98186630 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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; diff --git a/src/insets/InsetListings.h b/src/insets/InsetListings.h index 4be28f850d..2b6de4e0f8 100644 --- a/src/insets/InsetListings.h +++ b/src/insets/InsetListings.h @@ -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; /// diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index b20886c830..4930dd902a 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -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(); } diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index e0a13f38d4..8ea59366d8 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -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); /// diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp index 145cec96c6..b108885f9c 100644 --- a/src/insets/InsetNewpage.cpp +++ b/src/insets/InsetNewpage.cpp @@ -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(); } diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h index 4a7d60d010..749d5972d8 100644 --- a/src/insets/InsetNewpage.h +++ b/src/insets/InsetNewpage.h @@ -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); /// diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 880f0fff52..5e8813c398 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -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 << "" - << sgml::escapeString(getParam("symbol")) + << xml::escapeString(getParam("symbol")) << ""; 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 << "\n" << "" - << sgml::escapeString(getParam("symbol")) + << xml::escapeString(getParam("symbol")) << "\n" << "" - << sgml::escapeString(getParam("description")) + << xml::escapeString(getParam("description")) << "\n" <<"\n"; return 4; @@ -200,7 +200,7 @@ struct NomenclEntry { typedef map EntryMap; -docstring InsetPrintNomencl::xhtml(XHTMLStream &, OutputParams const & op) const +docstring InsetPrintNomencl::xhtml(XMLStream &, OutputParams const & op) const { shared_ptr 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(); } diff --git a/src/insets/InsetNomencl.h b/src/insets/InsetNomencl.h index 4d11a47d79..35887e88cd 100644 --- a/src/insets/InsetNomencl.h +++ b/src/insets/InsetNomencl.h @@ -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; /// diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 9f4c5ed1d0..d9eb2f3699 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -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(); diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index 9df1a501a2..e40b769854 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -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; /// diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index f8c3c38955..4771cb83ee 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -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(); } diff --git a/src/insets/InsetPhantom.h b/src/insets/InsetPhantom.h index 46e8576678..9d363374a0 100644 --- a/src/insets/InsetPhantom.h +++ b/src/insets/InsetPhantom.h @@ -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; /// diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index 2f70f87222..d7f7510ebd 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -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 = "‚"; + break; + case 0x2019: // ' + res = "’"; + break; + case 0x2018: // ` + res = "‘"; + break; + case 0x2039: // < + res = "‹"; + break; + case 0x203a: // > + res = "›"; + break; + case 0x0027: // ' (plain) + res = "'"; + break; + case 0x201e: // ,, + res = "„"; + break; + case 0x201d: // '' + res = "”"; + break; + case 0x201c: // `` + res = "“"; + break; + case 0x00ab: // << + res = "«"; + break; + case 0x00bb: // >> + res = "»"; + break; + case 0x0022: // " + res = """; + break; + case 0x300c: // LEFT CORNER BRACKET + res = "「"; + break; + case 0x300d: // RIGHT CORNER BRACKET + res = "」"; + break; + case 0x300e: // LEFT WHITE CORNER BRACKET + res = "『"; + break; + case 0x300f: // RIGHT WHITE CORNER BRACKET + res = "』"; + break; + case 0x300a: // LEFT DOUBLE ANGLE BRACKET + res = "《"; + break; + case 0x300b: // RIGHT DOUBLE ANGLE BRACKET + res = "》"; + break; + case 0x3008: // LEFT ANGLE BRACKET + res = "〈"; + break; + case 0x3009: // RIGHT ANGLE BRACKET + res = "〉"; + break; + default: + break; + } + + return from_ascii(res); +} + + map InsetQuotesParams::getTypes() const { map 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(); } diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index ea33b0eea0..939e6d61b4 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -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 &); diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 79dfad2480..ac4a3a93d7 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -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 << ""; } else { os << ""; } } else { os << "" << getParam("name") << ""; @@ -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(); } diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 8683ecf989..5839033c25 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -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; /// diff --git a/src/insets/InsetSeparator.cpp b/src/insets/InsetSeparator.cpp index af7fb644cd..42ff09e70a 100644 --- a/src/insets/InsetSeparator.cpp +++ b/src/insets/InsetSeparator.cpp @@ -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(); } diff --git a/src/insets/InsetSeparator.h b/src/insets/InsetSeparator.h index 2d256d6bee..2433b8247b 100644 --- a/src/insets/InsetSeparator.h +++ b/src/insets/InsetSeparator.h @@ -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); /// diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index a5fed47fbf..34ce9b51f6 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -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(); } diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h index 2784022955..0b6ea5135c 100644 --- a/src/insets/InsetSpace.h +++ b/src/insets/InsetSpace.h @@ -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; /// diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 740061e031..01007f6651 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -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 << "​"; + xs << XMLStream::ESCAPE_NONE << "​"; break; case LIGATURE_BREAK: - xs << XHTMLStream::ESCAPE_NONE << "‌"; + xs << XMLStream::ESCAPE_NONE << "‌"; break; case END_OF_SENTENCE: xs << '.'; break; case LDOTS: - xs << XHTMLStream::ESCAPE_NONE << "…"; + xs << XMLStream::ESCAPE_NONE << "…"; break; case MENU_SEPARATOR: - xs << XHTMLStream::ESCAPE_NONE << "⇒"; + xs << XMLStream::ESCAPE_NONE << "⇒"; break; case SLASH: - xs << XHTMLStream::ESCAPE_NONE << "⁄"; + xs << XMLStream::ESCAPE_NONE << "⁄"; break; case NOBREAKDASH: - xs << XHTMLStream::ESCAPE_NONE << "‑"; + xs << XMLStream::ESCAPE_NONE << "‑"; break; case PHRASE_LYX: xs << "LyX"; @@ -584,7 +584,7 @@ docstring InsetSpecialChar::xhtml(XHTMLStream & xs, OutputParams const &) const xs << "TeX"; break; case PHRASE_LATEX2E: - xs << "LaTeX2" << XHTMLStream::ESCAPE_NONE << "ε"; + xs << "LaTeX2" << XMLStream::ESCAPE_NONE << "ε"; break; case PHRASE_LATEX: xs << "LaTeX"; diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h index 982b1d51a3..6b33572bd7 100644 --- a/src/insets/InsetSpecialChar.h +++ b/src/insets/InsetSpecialChar.h @@ -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; /// diff --git a/src/insets/InsetTOC.cpp b/src/insets/InsetTOC.cpp index 29b7540cc2..a3739d74f5 100644 --- a/src/insets/InsetTOC.cpp +++ b/src/insets/InsetTOC.cpp @@ -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(); } diff --git a/src/insets/InsetTOC.h b/src/insets/InsetTOC.h index 4d48c3220f..00f6c7688b 100644 --- a/src/insets/InsetTOC.h +++ b/src/insets/InsetTOC.h @@ -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 //@{ diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 82cbfc7287..70f691917b 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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); } diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 3e8a6bcfab..355a2520e9 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -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; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index c76f0dbf4a..ac10443d00 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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(); } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 6c9790b135..0ad33a1f16 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -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; diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index 4cdd1ba6ed..24ea9aa636 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -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(); } diff --git a/src/insets/InsetVSpace.h b/src/insets/InsetVSpace.h index b2c8ac9780..16e50da096 100644 --- a/src/insets/InsetVSpace.h +++ b/src/insets/InsetVSpace.h @@ -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); /// diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index fe56091a75..4460f99c9b 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -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; } diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h index 3bf837876a..8df38e97f5 100644 --- a/src/insets/InsetWrap.h +++ b/src/insets/InsetWrap.h @@ -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; /// diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 8e16787fe7..a117af6cdc 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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(""); @@ -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(); } diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 9c27e0e374..32e4f09fa0 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -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; /// diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp index dd9bec9acc..50362552fb 100644 --- a/src/mathed/InsetMathMacroTemplate.cpp +++ b/src/mathed/InsetMathMacroTemplate.cpp @@ -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(); } diff --git a/src/mathed/InsetMathMacroTemplate.h b/src/mathed/InsetMathMacroTemplate.h index 978aa64ed7..da629fbe2b 100644 --- a/src/mathed/InsetMathMacroTemplate.h +++ b/src/mathed/InsetMathMacroTemplate.h @@ -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; /// diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp index 6a911afa57..9eaad0c033 100644 --- a/src/mathed/InsetMathRef.cpp +++ b/src/mathed/InsetMathRef.cpp @@ -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 << ""; else os << "\">"; } else { os << "" << asString(cell(1)) << ""; diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index a1a188952b..45af41bece 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -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 << "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; } diff --git a/src/output_docbook.h b/src/output_docbook.h index 46e495f005..819c2035e4 100644 --- a/src/output_docbook.h +++ b/src/output_docbook.h @@ -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; diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 469b316ea4..dcc3f69c33 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -24,7 +24,7 @@ #include "Paragraph.h" #include "ParagraphList.h" #include "ParagraphParameters.h" -#include "sgml.h" +#include "xml.h" #include "Text.h" #include "TextClass.h" @@ -44,212 +44,102 @@ using namespace lyx::support; namespace lyx { -namespace html { -docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e) -{ - docstring str; - switch (e) { - case XHTMLStream::ESCAPE_NONE: - str += c; - break; - case XHTMLStream::ESCAPE_ALL: - if (c == '<') { - str += "<"; - break; - } else if (c == '>') { - str += ">"; - break; - } - // fall through - case XHTMLStream::ESCAPE_AND: - if (c == '&') - str += "&"; - else - str +=c ; - break; - } - return str; -} - - -// escape what needs escaping -docstring htmlize(docstring const & str, XHTMLStream::EscapeSettings e) -{ - odocstringstream d; - docstring::const_iterator it = str.begin(); - docstring::const_iterator en = str.end(); - for (; it != en; ++it) - d << escapeChar(*it, e); - return d.str(); -} - - -docstring escapeChar(char c, XHTMLStream::EscapeSettings e) -{ - LATTEST(static_cast(c) < 0x80); - return escapeChar(static_cast(c), e); -} - - -docstring cleanAttr(docstring const & str) -{ - docstring newname; - docstring::const_iterator it = str.begin(); - docstring::const_iterator en = str.end(); - for (; it != en; ++it) { - char_type const c = *it; - newname += isAlnumASCII(c) ? c : char_type('_'); - } - return newname; -} - - -docstring StartTag::writeTag() const -{ - docstring output = '<' + from_utf8(tag_); - if (!attr_.empty()) - output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE); - output += ">"; - return output; +docstring const & fontToHtmlTag(xml::FontTypes type) +{ + switch(type) { + case xml::FontTypes::FT_EMPH: + return from_utf8("em"); + case xml::FontTypes::FT_BOLD: + return from_utf8("b"); + case xml::FontTypes::FT_NOUN: + return from_utf8("dfn"); + case xml::FontTypes::FT_UBAR: + case xml::FontTypes::FT_WAVE: + case xml::FontTypes::FT_DBAR: + return from_utf8("u"); + case xml::FontTypes::FT_SOUT: + case xml::FontTypes::FT_XOUT: + return from_utf8("del"); + case xml::FontTypes::FT_ITALIC: + return from_utf8("i"); + case xml::FontTypes::FT_UPRIGHT: + case xml::FontTypes::FT_SLANTED: + case xml::FontTypes::FT_SMALLCAPS: + case xml::FontTypes::FT_ROMAN: + case xml::FontTypes::FT_SANS: + case xml::FontTypes::FT_TYPE: + case xml::FontTypes::FT_SIZE_TINY: + case xml::FontTypes::FT_SIZE_SCRIPT: + case xml::FontTypes::FT_SIZE_FOOTNOTE: + case xml::FontTypes::FT_SIZE_SMALL: + case xml::FontTypes::FT_SIZE_NORMAL: + case xml::FontTypes::FT_SIZE_LARGE: + case xml::FontTypes::FT_SIZE_LARGER: + case xml::FontTypes::FT_SIZE_LARGEST: + case xml::FontTypes::FT_SIZE_HUGE: + case xml::FontTypes::FT_SIZE_HUGER: + case xml::FontTypes::FT_SIZE_INCREASE: + case xml::FontTypes::FT_SIZE_DECREASE: + return from_utf8("span"); + } + // kill warning + return docstring(); } -docstring StartTag::writeEndTag() const -{ - string output = ""; - return from_utf8(output); -} - - -bool StartTag::operator==(FontTag const & rhs) const -{ - return rhs == *this; -} - - -docstring EndTag::writeEndTag() const -{ - string output = ""; - return from_utf8(output); -} - - -ParTag::ParTag(std::string const & tag, std::string attr, - std::string const & parid) - : StartTag(tag) -{ - if (!parid.empty()) - attr += " id='" + parid + "'"; - attr_ = attr; -} - - -docstring CompTag::writeTag() const -{ - docstring output = '<' + from_utf8(tag_); - if (!attr_.empty()) - output += ' ' + html::htmlize(from_utf8(attr_), XHTMLStream::ESCAPE_NONE); - output += " />"; - return output; -} - - - namespace { -string fontToTag(html::FontTypes type) +string fontToAttribute(xml::FontTypes type) { switch(type) { - case FT_EMPH: - return "em"; - case FT_BOLD: - return "b"; - case FT_NOUN: - return "dfn"; - case FT_UBAR: - case FT_WAVE: - case FT_DBAR: - return "u"; - case FT_SOUT: - case FT_XOUT: - return "del"; - case FT_ITALIC: - return "i"; - case FT_UPRIGHT: - case FT_SLANTED: - case FT_SMALLCAPS: - case FT_ROMAN: - case FT_SANS: - case FT_TYPE: - case FT_SIZE_TINY: - case FT_SIZE_SCRIPT: - case FT_SIZE_FOOTNOTE: - case FT_SIZE_SMALL: - case FT_SIZE_NORMAL: - case FT_SIZE_LARGE: - case FT_SIZE_LARGER: - case FT_SIZE_LARGEST: - case FT_SIZE_HUGE: - case FT_SIZE_HUGER: - case FT_SIZE_INCREASE: - case FT_SIZE_DECREASE: - return "span"; - } - // kill warning - return ""; -} - -string fontToAttribute(html::FontTypes type) -{ - switch(type) { - case FT_EMPH: - case FT_BOLD: + case xml::FontTypes::FT_EMPH: + case xml::FontTypes::FT_BOLD: return ""; - case FT_NOUN: + case xml::FontTypes::FT_NOUN: return "class='lyxnoun'"; - case FT_UBAR: + case xml::FontTypes::FT_UBAR: return ""; - case FT_DBAR: + case xml::FontTypes::FT_DBAR: return "class='dline'"; - case FT_XOUT: - case FT_SOUT: + case xml::FontTypes::FT_XOUT: + case xml::FontTypes::FT_SOUT: return "class='strikeout'"; - case FT_WAVE: + case xml::FontTypes::FT_WAVE: return "class='wline'"; - case FT_ITALIC: + case xml::FontTypes::FT_ITALIC: return ""; - case FT_UPRIGHT: + case xml::FontTypes::FT_UPRIGHT: return "style='font-style:normal;'"; - case FT_SLANTED: + case xml::FontTypes::FT_SLANTED: return "style='font-style:oblique;'"; - case FT_SMALLCAPS: + case xml::FontTypes::FT_SMALLCAPS: return "style='font-variant:small-caps;'"; - case FT_ROMAN: + case xml::FontTypes::FT_ROMAN: return "style='font-family:serif;'"; - case FT_SANS: + case xml::FontTypes::FT_SANS: return "style='font-family:sans-serif;'"; - case FT_TYPE: + case xml::FontTypes::FT_TYPE: return "style='font-family:monospace;'"; - case FT_SIZE_TINY: - case FT_SIZE_SCRIPT: - case FT_SIZE_FOOTNOTE: + case xml::FontTypes::FT_SIZE_TINY: + case xml::FontTypes::FT_SIZE_SCRIPT: + case xml::FontTypes::FT_SIZE_FOOTNOTE: return "style='font-size:x-small;'"; - case FT_SIZE_SMALL: + case xml::FontTypes::FT_SIZE_SMALL: return "style='font-size:small;'"; - case FT_SIZE_NORMAL: + case xml::FontTypes::FT_SIZE_NORMAL: return "style='font-size:normal;'"; - case FT_SIZE_LARGE: + case xml::FontTypes::FT_SIZE_LARGE: return "style='font-size:large;'"; - case FT_SIZE_LARGER: - case FT_SIZE_LARGEST: + case xml::FontTypes::FT_SIZE_LARGER: + case xml::FontTypes::FT_SIZE_LARGEST: return "style='font-size:x-large;'"; - case FT_SIZE_HUGE: - case FT_SIZE_HUGER: + case xml::FontTypes::FT_SIZE_HUGE: + case xml::FontTypes::FT_SIZE_HUGER: return "style='font-size:xx-large;'"; - case FT_SIZE_INCREASE: + case xml::FontTypes::FT_SIZE_INCREASE: return "style='font-size:larger;'"; - case FT_SIZE_DECREASE: + case xml::FontTypes::FT_SIZE_DECREASE: return "style='font-size:smaller;'"; } // kill warning @@ -259,487 +149,29 @@ string fontToAttribute(html::FontTypes type) } // end anonymous namespace -FontTag::FontTag(FontTypes type) - : StartTag(fontToTag(type), fontToAttribute(type)), font_type_(type) -{} - - -bool FontTag::operator==(StartTag const & tag) const -{ - FontTag const * const ftag = tag.asFontTag(); - if (!ftag) - return false; - return (font_type_ == ftag->font_type_); -} - - -EndFontTag::EndFontTag(FontTypes type) - : EndTag(fontToTag(type)), font_type_(type) -{} - -} // namespace html - - - -//////////////////////////////////////////////////////////////// -/// -/// XHTMLStream -/// -//////////////////////////////////////////////////////////////// - -XHTMLStream::XHTMLStream(odocstream & os) - : os_(os), escape_(ESCAPE_ALL) -{} - - -#ifdef XHTML_DEBUG -void XHTMLStream::dumpTagStack(string const & msg) +xml::FontTag xhtmlStartFontTag(xml::FontTypes type) { - *this << html::CR(); - writeError(msg); - *this << html::CR(); - writeError("Tag Stack"); - TagDeque::const_reverse_iterator it = tag_stack_.rbegin(); - TagDeque::const_reverse_iterator en = tag_stack_.rend(); - for (; it != en; ++it) { - writeError(it->get()->tag_); - } - writeError("End Tag Stack"); - *this << html::CR(); - writeError("Pending Tags"); - it = pending_tags_.rbegin(); - en = pending_tags_.rend(); - for (; it != en; ++it) { - writeError(it->get()->tag_); - } - writeError("End Pending Tags"); - *this << html::CR(); + return xml::FontTag(fontToHtmlTag(type), from_utf8(fontToAttribute(type)), type); } -#endif -void XHTMLStream::writeError(std::string const & s) const +xml::EndFontTag xhtmlEndFontTag(xml::FontTypes type) { - LYXERR0(s); - os_ << from_utf8("\n"); + return xml::EndFontTag(fontToHtmlTag(type), type); } - -namespace { - // an illegal tag for internal use - static html::StartTag const parsep_tag("&LyX_parsep_tag&"); -} // namespace - - -bool XHTMLStream::closeFontTags() -{ - if (isTagPending(parsep_tag)) - // we haven't had any content - return true; - -#ifdef XHTML_DEBUG - dumpTagStack("Beging Close Font Tags"); -#endif - - // this may be a useless check, since we ought at least to have - // the parsep_tag. but it can't hurt too much to be careful. - if (tag_stack_.empty()) - return true; - - // first, we close any open font tags we can close - TagPtr curtag = tag_stack_.back(); - while (curtag->asFontTag()) { - os_ << curtag->writeEndTag(); - tag_stack_.pop_back(); - // this shouldn't happen, since then the font tags - // weren't in any other tag. - LASSERT(!tag_stack_.empty(), return true); - curtag = tag_stack_.back(); - } - -#ifdef XHTML_DEBUG - dumpTagStack("End Close Font Tags"); -#endif - - if (*curtag == parsep_tag) - return true; - - // so we've hit a non-font tag. - writeError("Tags still open in closeFontTags(). Probably not a problem,\n" - "but you might want to check these tags:"); - TagDeque::const_reverse_iterator it = tag_stack_.rbegin(); - TagDeque::const_reverse_iterator const en = tag_stack_.rend(); - for (; it != en; ++it) { - if (**it == parsep_tag) - break; - writeError((*it)->tag_); - } - return false; -} - - -void XHTMLStream::startDivision(bool keep_empty) -{ - pending_tags_.push_back(makeTagPtr(html::StartTag(parsep_tag))); - if (keep_empty) - clearTagDeque(); -#ifdef XHTML_DEBUG - dumpTagStack("StartDivision"); -#endif -} - - -void XHTMLStream::endDivision() -{ - if (isTagPending(parsep_tag)) { - // this case is normal. it just means we didn't have content, - // so the parsep_tag never got moved onto the tag stack. - while (!pending_tags_.empty()) { - // clear all pending tags up to and including the parsep tag. - // note that we work from the back, because we want to get rid - // of everything that hasn't been used. - TagPtr const cur_tag = pending_tags_.back(); - pending_tags_.pop_back(); - if (*cur_tag == parsep_tag) - break; - } - -#ifdef XHTML_DEBUG - dumpTagStack("EndDivision"); -#endif - - return; - } - - if (!isTagOpen(parsep_tag)) { - writeError("No division separation tag found in endDivision()."); - return; - } - - // this case is also normal, if the parsep tag is the last one - // on the stack. otherwise, it's an error. - while (!tag_stack_.empty()) { - TagPtr const cur_tag = tag_stack_.back(); - tag_stack_.pop_back(); - if (*cur_tag == parsep_tag) - break; - writeError("Tag `" + cur_tag->tag_ + "' still open at end of paragraph. Closing."); - os_ << cur_tag->writeEndTag(); - } - -#ifdef XHTML_DEBUG - dumpTagStack("EndDivision"); -#endif -} - - -void XHTMLStream::clearTagDeque() -{ - while (!pending_tags_.empty()) { - TagPtr const tag = pending_tags_.front(); - if (*tag != parsep_tag) - // tabs? - os_ << tag->writeTag(); - tag_stack_.push_back(tag); - pending_tags_.pop_front(); - } -} - - -XHTMLStream & XHTMLStream::operator<<(docstring const & d) -{ - clearTagDeque(); - os_ << html::htmlize(d, escape_); - escape_ = ESCAPE_ALL; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(const char * s) -{ - clearTagDeque(); - docstring const d = from_ascii(s); - os_ << html::htmlize(d, escape_); - escape_ = ESCAPE_ALL; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(char_type c) -{ - clearTagDeque(); - os_ << html::escapeChar(c, escape_); - escape_ = ESCAPE_ALL; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(char c) -{ - clearTagDeque(); - os_ << html::escapeChar(c, escape_); - escape_ = ESCAPE_ALL; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(int i) -{ - clearTagDeque(); - os_ << i; - escape_ = ESCAPE_ALL; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(EscapeSettings e) -{ - escape_ = e; - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag) -{ - if (tag.tag_.empty()) - return *this; - pending_tags_.push_back(makeTagPtr(tag)); - if (tag.keepempty_) - clearTagDeque(); - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag) -{ - if (tag.tag_.empty()) - return *this; - pending_tags_.push_back(makeTagPtr(tag)); - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag) -{ - if (tag.tag_.empty()) - return *this; - clearTagDeque(); - os_ << tag.writeTag(); - *this << html::CR(); - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(html::FontTag const & tag) -{ - if (tag.tag_.empty()) - return *this; - pending_tags_.push_back(makeTagPtr(tag)); - return *this; -} - - -XHTMLStream & XHTMLStream::operator<<(html::CR const &) -{ - // tabs? - os_ << from_ascii("\n"); - return *this; -} - - -bool XHTMLStream::isTagOpen(html::StartTag const & stag) const -{ - TagDeque::const_iterator sit = tag_stack_.begin(); - TagDeque::const_iterator const sen = tag_stack_.end(); - for (; sit != sen; ++sit) - if (**sit == stag) - return true; - return false; -} - - -bool XHTMLStream::isTagOpen(html::EndTag const & etag) const -{ - TagDeque::const_iterator sit = tag_stack_.begin(); - TagDeque::const_iterator const sen = tag_stack_.end(); - for (; sit != sen; ++sit) - if (etag == **sit) - return true; - return false; -} - - -bool XHTMLStream::isTagPending(html::StartTag const & stag) const -{ - TagDeque::const_iterator sit = pending_tags_.begin(); - TagDeque::const_iterator const sen = pending_tags_.end(); - for (; sit != sen; ++sit) - if (**sit == stag) - return true; - return false; -} - - -// this is complicated, because we want to make sure that -// everything is properly nested. the code ought to make -// sure of that, but we won't assert (yet) if we run into -// a problem. we'll just output error messages and try our -// best to make things work. -XHTMLStream & XHTMLStream::operator<<(html::EndTag const & etag) -{ - if (etag.tag_.empty()) - return *this; - - // if this tag is pending, we can simply discard it. - if (!pending_tags_.empty()) { - - if (etag == *pending_tags_.back()) { - // we have , so we discard it and remove it - // from the pending_tags_. - pending_tags_.pop_back(); - return *this; - } - - // there is a pending tag that isn't the one we are trying - // to close. - - // is this tag itself pending? - // non-const iterators because we may call erase(). - TagDeque::iterator dit = pending_tags_.begin(); - TagDeque::iterator const den = pending_tags_.end(); - for (; dit != den; ++dit) { - if (etag == **dit) { - // it was pending, so we just erase it - writeError("Tried to close pending tag `" + etag.tag_ - + "' when other tags were pending. Last pending tag is `" - + to_utf8(pending_tags_.back()->writeTag()) - + "'. Tag discarded."); - pending_tags_.erase(dit); - return *this; - } - } - // so etag isn't itself pending. is it even open? - if (!isTagOpen(etag)) { - writeError("Tried to close `" + etag.tag_ - + "' when tag was not open. Tag discarded."); - return *this; - } - // ok, so etag is open. - // our strategy will be as below: we will do what we need to - // do to close this tag. - string estr = "Closing tag `" + etag.tag_ - + "' when other tags are pending. Discarded pending tags:\n"; - for (dit = pending_tags_.begin(); dit != den; ++dit) - estr += to_utf8(html::htmlize((*dit)->writeTag(), XHTMLStream::ESCAPE_ALL)) + "\n"; - writeError(estr); - // clear the pending tags... - pending_tags_.clear(); - // ...and then just fall through. - } - - // make sure there are tags to be closed - if (tag_stack_.empty()) { - writeError("Tried to close `" + etag.tag_ - + "' when no tags were open!"); - return *this; - } - - // is the tag we are closing the last one we opened? - if (etag == *tag_stack_.back()) { - // output it... - os_ << etag.writeEndTag(); - // ...and forget about it - tag_stack_.pop_back(); - return *this; - } - - // we are trying to close a tag other than the one last opened. - // let's first see if this particular tag is still open somehow. - if (!isTagOpen(etag)) { - writeError("Tried to close `" + etag.tag_ - + "' when tag was not open. Tag discarded."); - return *this; - } - - // so the tag was opened, but other tags have been opened since - // and not yet closed. - // if it's a font tag, though... - if (etag.asFontTag()) { - // it won't be a problem if the other tags open since this one - // are also font tags. - TagDeque::const_reverse_iterator rit = tag_stack_.rbegin(); - TagDeque::const_reverse_iterator ren = tag_stack_.rend(); - for (; rit != ren; ++rit) { - if (etag == **rit) - break; - if (!(*rit)->asFontTag()) { - // we'll just leave it and, presumably, have to close it later. - writeError("Unable to close font tag `" + etag.tag_ - + "' due to open non-font tag `" + (*rit)->tag_ + "'."); - return *this; - } - } - - // so we have e.g.: - // this is bold - // and are being asked to closed em. we want: - // this is bold - // first, we close the intervening tags... - TagPtr curtag = tag_stack_.back(); - // ...remembering them in a stack. - TagDeque fontstack; - while (etag != *curtag) { - os_ << curtag->writeEndTag(); - fontstack.push_back(curtag); - tag_stack_.pop_back(); - curtag = tag_stack_.back(); - } - os_ << etag.writeEndTag(); - tag_stack_.pop_back(); - - // ...and restore the other tags. - rit = fontstack.rbegin(); - ren = fontstack.rend(); - for (; rit != ren; ++rit) - pending_tags_.push_back(*rit); - return *this; - } - - // it wasn't a font tag. - // so other tags were opened before this one and not properly closed. - // so we'll close them, too. that may cause other issues later, but it - // at least guarantees proper nesting. - writeError("Closing tag `" + etag.tag_ - + "' when other tags are open, namely:"); - TagPtr curtag = tag_stack_.back(); - while (etag != *curtag) { - writeError(curtag->tag_); - if (*curtag != parsep_tag) - os_ << curtag->writeEndTag(); - tag_stack_.pop_back(); - curtag = tag_stack_.back(); - } - // curtag is now the one we actually want. - os_ << curtag->writeEndTag(); - tag_stack_.pop_back(); - - return *this; -} - -// End code for XHTMLStream - namespace { // convenience functions -inline void openParTag(XHTMLStream & xs, Layout const & lay, +inline void openParTag(XMLStream & xs, Layout const & lay, std::string parlabel) { - xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel); + xs << xml::ParTag(lay.htmltag(), lay.htmlattr(), parlabel); } -void openParTag(XHTMLStream & xs, Layout const & lay, +void openParTag(XMLStream & xs, Layout const & lay, ParagraphParameters const & params, std::string parlabel) { @@ -750,35 +182,35 @@ void openParTag(XHTMLStream & xs, Layout const & lay, return; } string attrs = lay.htmlattr() + " style='text-align: " + align + ";'"; - xs << html::ParTag(lay.htmltag(), attrs, parlabel); + xs << xml::ParTag(lay.htmltag(), attrs, parlabel); } -inline void closeTag(XHTMLStream & xs, Layout const & lay) +inline void closeTag(XMLStream & xs, Layout const & lay) { - xs << html::EndTag(lay.htmltag()); + xs << xml::EndTag(lay.htmltag()); } -inline void openLabelTag(XHTMLStream & xs, Layout const & lay) +inline void openLabelTag(XMLStream & xs, Layout const & lay) { - xs << html::StartTag(lay.htmllabeltag(), lay.htmllabelattr()); + xs << xml::StartTag(lay.htmllabeltag(), lay.htmllabelattr()); } -inline void closeLabelTag(XHTMLStream & xs, Layout const & lay) +inline void closeLabelTag(XMLStream & xs, Layout const & lay) { - xs << html::EndTag(lay.htmllabeltag()); + xs << xml::EndTag(lay.htmllabeltag()); } -inline void openItemTag(XHTMLStream & xs, Layout const & lay) +inline void openItemTag(XMLStream & xs, Layout const & lay) { - xs << html::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true); + xs << xml::StartTag(lay.htmlitemtag(), lay.htmlitemattr(), true); } -void openItemTag(XHTMLStream & xs, Layout const & lay, +void openItemTag(XMLStream & xs, Layout const & lay, ParagraphParameters const & params) { // FIXME Are there other things we should handle here? @@ -788,13 +220,13 @@ void openItemTag(XHTMLStream & xs, Layout const & lay, return; } string attrs = lay.htmlattr() + " style='text-align: " + align + ";'"; - xs << html::StartTag(lay.htmlitemtag(), attrs); + xs << xml::StartTag(lay.htmlitemtag(), attrs); } -inline void closeItemTag(XHTMLStream & xs, Layout const & lay) +inline void closeItemTag(XMLStream & xs, Layout const & lay) { - xs << html::EndTag(lay.htmlitemtag()); + xs << xml::EndTag(lay.htmlitemtag()); } // end of convenience functions @@ -844,7 +276,7 @@ ParagraphList::const_iterator findEndOfEnvironment( ParagraphList::const_iterator makeParagraphs(Buffer const & buf, - XHTMLStream & xs, + XMLStream & xs, OutputParams const & runparams, Text const & text, ParagraphList::const_iterator const & pbegin, @@ -861,7 +293,7 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf, // FIXME We should see if there's a label to be output and // do something with it. if (par != pbegin) - xs << html::CR(); + xs << xml::CR(); // We want to open the paragraph tag if: // (i) the current layout permits multiple paragraphs @@ -918,11 +350,11 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf, if (close_par) { closeTag(xs, lay); - xs << html::CR(); + xs << xml::CR(); } if (!deferred.empty()) { - xs << XHTMLStream::ESCAPE_NONE << deferred << html::CR(); + xs << XMLStream::ESCAPE_NONE << deferred << xml::CR(); } } return pend; @@ -930,7 +362,7 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf, ParagraphList::const_iterator makeBibliography(Buffer const & buf, - XHTMLStream & xs, + XMLStream & xs, OutputParams const & runparams, Text const & text, ParagraphList::const_iterator const & pbegin, @@ -938,14 +370,14 @@ ParagraphList::const_iterator makeBibliography(Buffer const & buf, { // FIXME XHTML // Use TextClass::htmlTOCLayout() to figure out how we should look. - xs << html::StartTag("h2", "class='bibliography'") + xs << xml::StartTag("h2", "class='bibliography'") << pbegin->layout().labelstring(false) - << html::EndTag("h2") - << html::CR() - << html::StartTag("div", "class='bibliography'") - << html::CR(); + << xml::EndTag("h2") + << xml::CR() + << xml::StartTag("div", "class='bibliography'") + << xml::CR(); makeParagraphs(buf, xs, runparams, text, pbegin, pend); - xs << html::EndTag("div"); + xs << xml::EndTag("div"); return pend; } @@ -958,7 +390,7 @@ bool isNormalEnv(Layout const & lay) ParagraphList::const_iterator makeEnvironment(Buffer const & buf, - XHTMLStream & xs, + XMLStream & xs, OutputParams const & runparams, Text const & text, ParagraphList::const_iterator const & pbegin, @@ -971,7 +403,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, // open tag for this environment openParTag(xs, bstyle, pbegin->magicLabel()); - xs << html::CR(); + xs << xml::CR(); // we will on occasion need to remember a layout from before. Layout const * lastlay = nullptr; @@ -997,7 +429,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, case LATEX_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: { - // There are two possiblities in this case. + // There are two possibilities in this case. // One is that we are still in the environment in which we // started---which we will be if the depth is the same. if (par->params().depth() == origdepth) { @@ -1028,20 +460,20 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, xs << lbl; closeLabelTag(xs, style); } - xs << html::CR(); + xs << xml::CR(); } } else { // some kind of list if (style.labeltype == LABEL_MANUAL) { openLabelTag(xs, style); sep = par->firstWordLyXHTML(xs, runparams); closeLabelTag(xs, style); - xs << html::CR(); + xs << xml::CR(); } else { openLabelTag(xs, style); xs << par->params().labelString(); closeLabelTag(xs, style); - xs << html::CR(); + xs << xml::CR(); } } } // end label output @@ -1051,7 +483,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, docstring deferred = par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)), true, true, sep); - xs << XHTMLStream::ESCAPE_NONE << deferred; + xs << XMLStream::ESCAPE_NONE << deferred; ++par; // We may not want to close the tag yet, in particular: @@ -1066,7 +498,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, lastlay = &style; } else closeItemTag(xs, style); - xs << html::CR(); + xs << xml::CR(); } // The other possibility is that the depth has increased, in which // case we need to recurse. @@ -1096,13 +528,13 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf, if (lastlay != nullptr) closeItemTag(xs, *lastlay); closeTag(xs, bstyle); - xs << html::CR(); + xs << xml::CR(); return pend; } void makeCommand(Buffer const & buf, - XHTMLStream & xs, + XMLStream & xs, OutputParams const & runparams, Text const & text, ParagraphList::const_iterator const & pbegin) @@ -1132,7 +564,7 @@ void makeCommand(Buffer const & buf, pbegin->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, pbegin))); closeTag(xs, style); - xs << html::CR(); + xs << xml::CR(); } } // end anonymous namespace @@ -1140,7 +572,7 @@ void makeCommand(Buffer const & buf, void xhtmlParagraphs(Text const & text, Buffer const & buf, - XHTMLStream & xs, + XMLStream & xs, OutputParams const & runparams) { ParagraphList const & paragraphs = text.paragraphs(); @@ -1151,7 +583,7 @@ void xhtmlParagraphs(Text const & text, pit_type bpit = runparams.par_begin; pit_type const epit = runparams.par_end; LASSERT(bpit < epit, - { xs << XHTMLStream::ESCAPE_NONE << "\n"; return; }); + { xs << XMLStream::ESCAPE_NONE << "\n"; return; }); OutputParams ourparams = runparams; ParagraphList::const_iterator const pend = diff --git a/src/output_xhtml.h b/src/output_xhtml.h index a9ee0ea090..562d380a2d 100644 --- a/src/output_xhtml.h +++ b/src/output_xhtml.h @@ -16,6 +16,7 @@ #include "support/docstream.h" #include "support/strfwd.h" +#include "xml.h" #include #include @@ -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() {} - /// - virtual docstring writeTag() const; - /// - 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 "" 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() {} - /// - 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 -/// 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) {} - /// - docstring writeTag() const; - /// - std::string tag_; - /// - std::string attr_; -}; - - -/// A special case of StartTag, used exclusively for tags that wrap paragraphs. -struct ParTag : public StartTag -{ - /// - explicit ParTag(std::string const & tag, std::string attr, - std::string const & parid); - /// - ~ParTag() {} -}; - - -/// -enum FontTypes { - // ranges - FT_EMPH, - FT_NOUN, - FT_UBAR, - FT_DBAR, - FT_WAVE, - FT_SOUT, - FT_XOUT, - // bold - FT_BOLD, - // shapes - FT_UPRIGHT, - FT_ITALIC, - FT_SLANTED, - FT_SMALLCAPS, - // families - FT_ROMAN, - FT_SANS, - FT_TYPE, - // sizes - FT_SIZE_TINY, - FT_SIZE_SCRIPT, - FT_SIZE_FOOTNOTE, - FT_SIZE_SMALL, - FT_SIZE_NORMAL, - FT_SIZE_LARGE, - FT_SIZE_LARGER, - FT_SIZE_LARGEST, - FT_SIZE_HUGE, - FT_SIZE_HUGER, - FT_SIZE_INCREASE, - FT_SIZE_DECREASE -}; - - /// -struct FontTag : public StartTag -{ - /// - explicit FontTag(FontTypes type); - /// - FontTag const * asFontTag() const { return this; } - /// - bool operator==(StartTag const &) const; - /// - FontTypes font_type_; -}; - - +xml::FontTag xhtmlStartFontTag(xml::FontTypes type); /// -struct EndFontTag : public EndTag -{ - /// - explicit EndFontTag(FontTypes type); - /// - EndFontTag const * asFontTag() const { return this; } - /// - FontTypes font_type_; -}; - - -// trivial struct for output of newlines -struct CR{}; - -} // namespace html - -class XHTMLStream { -public: - /// - explicit XHTMLStream(odocstream & os); - /// - odocstream & os() { return os_; } - /// - // int & tab() { return tab_; } - /// closes any font tags that are eligible to be closed, - /// i.e., last on the tag_stack_. - /// \return false if there are open font tags we could not close. - /// because they are "blocked" by open non-font tags on the stack. - bool closeFontTags(); - /// sets a mark so we know what tags to close at the end. - /// normally called at the start of a paragraph. - void startDivision(bool keep_empty); - /// clears the mark set by previous method. - /// there should not be any other tags open before it on the stack, - /// but if there are, we will close them. - void endDivision(); - /// - XHTMLStream & operator<<(docstring const &); - /// - XHTMLStream & operator<<(const char *); - /// - XHTMLStream & operator<<(char_type); - /// - XHTMLStream & operator<<(int); - /// - XHTMLStream & operator<<(char); - /// - XHTMLStream & operator<<(html::StartTag const &); - /// - XHTMLStream & operator<<(html::EndTag const &); - /// - XHTMLStream & operator<<(html::CompTag const &); - /// - XHTMLStream & operator<<(html::ParTag const &); - /// - XHTMLStream & operator<<(html::FontTag const &); - /// - XHTMLStream & operator<<(html::CR const &); - /// - enum EscapeSettings { - ESCAPE_NONE, - ESCAPE_AND, // meaning & - ESCAPE_ALL // meaning <, >, &, at present - }; - /// Sets what we are going to escape on the NEXT write. - /// Everything is reset for the next time. - XHTMLStream & operator<<(EscapeSettings); - /// This routine is for debugging the tag stack, etc. Code - /// for it is disabled by default, however, so you will need - /// to enable it if you want to use it. - void dumpTagStack(std::string const & msg); -private: - /// - void clearTagDeque(); - /// - bool isTagOpen(html::StartTag const &) const; - /// - bool isTagOpen(html::EndTag const &) const; - /// - bool isTagPending(html::StartTag const &) const; - /// - void writeError(std::string const &) const; - /// - odocstream & os_; - /// - EscapeSettings escape_; - // What we would really like to do here is simply use a - // deque. 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, 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 TagPtr; - typedef std::deque TagDeque; - /// - template - TagPtr makeTagPtr(T const & tag) { return std::make_shared(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 diff --git a/src/sgml.cpp b/src/sgml.cpp deleted file mode 100644 index 2facb3ed53..0000000000 --- a/src/sgml.cpp +++ /dev/null @@ -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 - -#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 -#include -#include - -using namespace std; -using namespace lyx::support; - -namespace lyx { - - -docstring sgml::escapeChar(char_type c) -{ - docstring str; - switch (c) { - case ' ': - str += " "; - break; - case '&': - str += "&"; - break; - case '<': - str += "<"; - break; - case '>': - str += ">"; - break; -#if 0 - case '$': - str += "$"; - break; - case '#': - str += "#"; - break; - case '%': - str += "%"; - break; - case '[': - str += "["; - break; - case ']': - str += "]"; - break; - case '{': - str += "{"; - break; - case '}': - str += "}"; - break; - case '~': - str += "˜"; - break; - case '"': - str += """; - break; - case '\\': - str += "\"; - break; -#endif - default: - str += c; - break; - } - return str; -} - - -docstring sgml::escapeString(docstring const & raw) -{ - docstring bin; - bin.reserve(raw.size() * 2); // crude approximation is sufficient - for (size_t i = 0; i != raw.size(); ++i) - bin += sgml::escapeChar(raw[i]); - - return bin; -} - - -docstring const sgml::uniqueID(docstring const & label) -{ - // thread-safe - static atomic_uint seed(1000); - return label + convert(++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 MangledMap; - static QThreadStorage tMangledNames; - static QThreadStorage 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(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 << "'; -} - - -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(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 diff --git a/src/sgml.h b/src/sgml.h deleted file mode 100644 index a46c9fa833..0000000000 --- a/src/sgml.h +++ /dev/null @@ -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 diff --git a/src/tests/dummy_functions.cpp b/src/tests/dummy_functions.cpp index ca6edc38d0..f57061614f 100644 --- a/src/tests/dummy_functions.cpp +++ b/src/tests/dummy_functions.cpp @@ -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 diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp index c850cd97c1..fc5098d1f1 100644 --- a/src/tex2lyx/dummy_impl.cpp +++ b/src/tex2lyx/dummy_impl.cpp @@ -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 diff --git a/src/xml.cpp b/src/xml.cpp new file mode 100644 index 0000000000..2c30f1548d --- /dev/null +++ b/src/xml.cpp @@ -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 + +#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 +#include +#include +#include +#include + +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace xml { + + +docstring escapeChar(char_type c, XMLStream::EscapeSettings e) +{ + docstring str; + switch (e) { // For HTML: always ESCAPE_NONE. For XML: it depends, hence the parameter. + case XMLStream::ESCAPE_NONE: + str += c; + break; + case XMLStream::ESCAPE_ALL: + if (c == '<') { + str += "<"; + break; + } else if (c == '>') { + str += ">"; + break; + } + // fall through + case XMLStream::ESCAPE_AND: + if (c == '&') + str += "&"; + else + str +=c ; + break; + } + return str; +} + + +// escape what needs escaping +docstring xmlize(docstring const &str, XMLStream::EscapeSettings e) { + odocstringstream d; + docstring::const_iterator it = str.begin(); + docstring::const_iterator en = str.end(); + for (; it != en; ++it) + d << escapeChar(*it, e); + return d.str(); +} + + +docstring escapeChar(char c, XMLStream::EscapeSettings e) { + LATTEST(static_cast(c) < 0x80); + return escapeChar(static_cast(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(""); +} + + +bool StartTag::operator==(FontTag const &rhs) const { + return rhs == *this; +} + + +docstring EndTag::writeEndTag() const { + return 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("\n"); +} + + +void XMLStream::writeError(docstring const &s) const { + LYXERR0(s); + os_ << 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 , 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.: + // this is bold + // and are being asked to closed em. we want: + // this is bold + // 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(++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 MangledMap; + static QThreadStorage tMangledNames; + static QThreadStorage 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(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 << "'; +} + + +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(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 diff --git a/src/xml.h b/src/xml.h new file mode 100644 index 0000000000..45fb52f0cd --- /dev/null +++ b/src/xml.h @@ -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 +#include + +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. 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, 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 TagPtr; + typedef std::deque TagDeque; + /// + template + TagPtr makeTagPtr(T const & tag) { return std::make_shared(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() {} + /// + virtual docstring writeTag() const; + /// + 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 "" 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() {} + /// + 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 +/// 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) {} + /// + 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 -- 2.39.2