From f61bebd7fb25beabdf0dc761520030f9059499d6 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 5 Jun 2009 17:48:14 +0000 Subject: [PATCH] HTML output code for a handful of easy insets. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29951 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetBox.cpp | 10 +++++++ src/insets/InsetBox.h | 2 ++ src/insets/InsetBranch.cpp | 7 +++++ src/insets/InsetBranch.h | 2 ++ src/insets/InsetHyperlink.cpp | 12 +++++++++ src/insets/InsetHyperlink.h | 2 ++ src/insets/InsetLabel.cpp | 7 +++++ src/insets/InsetLabel.h | 2 ++ src/insets/InsetLine.cpp | 7 +++++ src/insets/InsetLine.h | 22 +++++++++------- src/insets/InsetNewline.cpp | 7 +++++ src/insets/InsetNewline.h | 2 ++ src/insets/InsetNewpage.cpp | 7 +++++ src/insets/InsetNewpage.h | 2 ++ src/insets/InsetQuotes.cpp | 6 +++++ src/insets/InsetQuotes.h | 2 ++ src/insets/InsetSpace.cpp | 46 +++++++++++++++++++++++++++++++++ src/insets/InsetSpace.h | 2 ++ src/insets/InsetSpecialChar.cpp | 26 +++++++++++++++++++ src/insets/InsetSpecialChar.h | 2 ++ src/insets/InsetText.cpp | 8 ++++++ src/insets/InsetText.h | 2 ++ 22 files changed, 175 insertions(+), 10 deletions(-) diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 43d29d8dcd..852bf94146 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -484,6 +484,16 @@ int InsetBox::docbook(odocstream & os, OutputParams const & runparams) const } +int InsetBox::xhtml(odocstream & os, OutputParams const & runparams) const +{ + // FIXME We also want to do something with the length info, etc, + // presumably as "style='...'". + os << from_ascii("\n"); + InsetText::xhtml(os, runparams); + os << "\n"; +} + + void InsetBox::validate(LaTeXFeatures & features) const { BoxType btype = boxtranslator().find(params_.type); diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h index b4c197769e..c254fb6ea1 100644 --- a/src/insets/InsetBox.h +++ b/src/insets/InsetBox.h @@ -119,6 +119,8 @@ private: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void validate(LaTeXFeatures &) const; /// InsetBoxParams const & params() const { return params_; } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 061d9dac3e..f3dd34f5a5 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -235,6 +235,13 @@ int InsetBranch::docbook(odocstream & os, } +int InsetBranch::xhtml(odocstream & os, + OutputParams const & runparams) const +{ + return isBranchSelected() ? InsetText::xhtml(os, runparams) : 0; +} + + void InsetBranch::tocString(odocstream & os) const { if (isBranchSelected()) diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 640cc67103..6285e458ee 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -74,6 +74,8 @@ private: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void tocString(odocstream &) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index 2c0192df99..0fb69a7cb4 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -181,6 +181,18 @@ int InsetHyperlink::docbook(odocstream & os, OutputParams const &) const } +int InsetHyperlink::xhtml(odocstream & os, OutputParams const &) const +{ + os << "" + << getParam("name") + << ""; + return 0; +} + + void InsetHyperlink::tocString(odocstream & os) const { plaintext(os, OutputParams(0)); diff --git a/src/insets/InsetHyperlink.h b/src/insets/InsetHyperlink.h index d764d2c8c8..8ae3ae717d 100644 --- a/src/insets/InsetHyperlink.h +++ b/src/insets/InsetHyperlink.h @@ -40,6 +40,8 @@ public: int plaintext(odocstream &, OutputParams const &) const; /// int docbook(odocstream &, OutputParams const &) const; + /// + int xhtml(odocstream &, OutputParams const &) const; /// the string that is passed to the TOC void tocString(odocstream &) const; /// diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 3d25aff102..9435c3f040 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -218,4 +218,11 @@ int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const } +int InsetLabel::xhtml(odocstream & os, OutputParams const & runparams) const +{ + // FIXME Does this need to be escaped? + os << ""; + return 0; +} + } // namespace lyx diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index e649643f15..efafd82414 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -44,6 +44,8 @@ public: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// static ParamInfo const & findInfo(std::string const &); /// static std::string defaultCommand() { return "label"; }; diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index 6925d86379..07075bb7dc 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -85,6 +85,13 @@ int InsetLine::docbook(odocstream & os, OutputParams const &) const } +int InsetLine::xhtml(odocstream & os, OutputParams const &) const +{ + os << "
\n"; + return 0; +} + + void InsetLine::validate(LaTeXFeatures & features) const { features.require("lyxline"); diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h index c5435e1e37..b14c899b80 100644 --- a/src/insets/InsetLine.h +++ b/src/insets/InsetLine.h @@ -20,27 +20,29 @@ namespace lyx { class InsetLine : public Inset { public: - + /// InsetLine() {} - + /// InsetCode lyxCode() const { return LINE_CODE; } - + /// void metrics(MetricsInfo &, Dimension &) const; - + /// void draw(PainterInfo & pi, int x, int y) const; - + /// int latex(odocstream &, OutputParams const &) const; - + /// int plaintext(odocstream &, OutputParams const &) const; - + /// int docbook(odocstream &, OutputParams const &) const; - + /// + int xhtml(odocstream &, OutputParams const &) const; + /// void read(Lexer & lex); - + /// void write(std::ostream & os) const; /// We don't need \begin_inset and \end_inset bool directWrite() const { return true; } - + /// DisplayType display() const { return AlignCenter; } /// void validate(LaTeXFeatures & features) const; diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index f5670fb44c..263e9be936 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -173,6 +173,13 @@ int InsetNewline::docbook(odocstream & os, OutputParams const &) const } +int InsetNewline::xhtml(odocstream & os, OutputParams const &) const +{ + os << "
\n"; + return 0; +} + + void InsetNewline::draw(PainterInfo & pi, int x, int y) const { FontInfo font; diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index fc7684ab73..017d8f8201 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -65,6 +65,8 @@ private: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void read(Lexer & lex); /// void write(std::ostream & os) const; diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp index 839ef685dd..ea71596c72 100644 --- a/src/insets/InsetNewpage.cpp +++ b/src/insets/InsetNewpage.cpp @@ -247,6 +247,13 @@ int InsetNewpage::docbook(odocstream & os, OutputParams const &) const } +int InsetNewpage::xhtml(odocstream & os, OutputParams const &) const +{ + os << "
\n"; + return 0; +} + + docstring InsetNewpage::contextMenu(BufferView const &, int, int) const { return from_ascii("context-newpage"); diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h index 95b2791114..3d89cfe639 100644 --- a/src/insets/InsetNewpage.h +++ b/src/insets/InsetNewpage.h @@ -69,6 +69,8 @@ private: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void read(Lexer & lex); /// void write(std::ostream & os) const; diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index d27b125414..30881e174e 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -312,6 +312,12 @@ int InsetQuotes::docbook(odocstream & os, OutputParams const &) const } +int InsetQuotes::xhtml(odocstream & os, OutputParams const & op) const +{ + return docbook(os, op); +} + + void InsetQuotes::tocString(odocstream & os) const { os << displayString(); diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index feb162b06d..aaf32f79fb 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -83,6 +83,8 @@ public: int plaintext(odocstream &, OutputParams const &) const; /// int docbook(odocstream &, OutputParams const &) const; + /// + int xhtml(odocstream &, OutputParams const &) const; /// the string that is passed to the TOC void tocString(odocstream &) const; diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index a9ffe812ac..722c991275 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -680,6 +680,52 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const } +int InsetSpace::xhtml(odocstream & os, OutputParams const &) const +{ + switch (params_.kind) { + case InsetSpaceParams::NORMAL: + os << " "; + break; + case InsetSpaceParams::ENSKIP: + case InsetSpaceParams::ENSPACE: + os << " "; + break; + case InsetSpaceParams::QQUAD: + os << " "; + case InsetSpaceParams::THICK: + case InsetSpaceParams::QUAD: + os << " "; + break; + case InsetSpaceParams::THIN: + os << " "; + break; + case InsetSpaceParams::PROTECTED: + case InsetSpaceParams::MEDIUM: + case InsetSpaceParams::NEGTHIN: + case InsetSpaceParams::NEGMEDIUM: + case InsetSpaceParams::NEGTHICK: + os << " "; + break; + case InsetSpaceParams::HFILL: + case InsetSpaceParams::HFILL_PROTECTED: + case InsetSpaceParams::DOTFILL: + case InsetSpaceParams::HRULEFILL: + case InsetSpaceParams::LEFTARROWFILL: + case InsetSpaceParams::RIGHTARROWFILL: + case InsetSpaceParams::UPBRACEFILL: + case InsetSpaceParams::DOWNBRACEFILL: + // FIXME Can we do anything with those in HTML? + os << '\n'; + break; + case InsetSpaceParams::CUSTOM: + case InsetSpaceParams::CUSTOM_PROTECTED: + // FIXME Probably we could do some sort of blank span? + os << '\n'; + } + return 0; +} + + void InsetSpace::validate(LaTeXFeatures & features) const { if (params_.kind == InsetSpaceParams::NEGMEDIUM || diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h index 716925334e..bc2d685d6d 100644 --- a/src/insets/InsetSpace.h +++ b/src/insets/InsetSpace.h @@ -129,6 +129,8 @@ public: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void validate(LaTeXFeatures & features) const; /// the string that is passed to the TOC void tocString(odocstream &) const; diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 0750187c65..b1ad2ce71c 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -291,6 +291,32 @@ int InsetSpecialChar::docbook(odocstream & os, OutputParams const &) const } +int InsetSpecialChar::xhtml(odocstream & os, OutputParams const &) const +{ + switch (kind_) { + case HYPHENATION: + case LIGATURE_BREAK: + break; + case END_OF_SENTENCE: + os << '.'; + break; + case LDOTS: + os << "…"; + break; + case MENU_SEPARATOR: + os << "⇒"; + break; + case SLASH: + os << "⁄"; + break; + case NOBREAKDASH: + os << '-'; + break; + } + return 0; +} + + void InsetSpecialChar::tocString(odocstream & os) const { plaintext(os, OutputParams(0)); diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h index 5485607c9a..95af71eb1d 100644 --- a/src/insets/InsetSpecialChar.h +++ b/src/insets/InsetSpecialChar.h @@ -64,6 +64,8 @@ public: int plaintext(odocstream &, OutputParams const &) const; /// int docbook(odocstream &, OutputParams const &) const; + /// + int xhtml(odocstream &, OutputParams const &) const; /// the string that is passed to the TOC void tocString(odocstream &) const; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 5c461242e5..0fc3a9a0da 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -34,6 +34,7 @@ #include "MetricsInfo.h" #include "output_docbook.h" #include "output_latex.h" +#include "output_xhtml.h" #include "OutputParams.h" #include "output_plaintext.h" #include "paragraph_funcs.h" @@ -367,6 +368,13 @@ int InsetText::docbook(odocstream & os, OutputParams const & runparams) const } +int InsetText::xhtml(odocstream & os, OutputParams const & runparams) const +{ + xhtmlParagraphs(paragraphs(), buffer(), os, runparams); + return 0; +} + + void InsetText::validate(LaTeXFeatures & features) const { for_each(paragraphs().begin(), paragraphs().end(), diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 1fcbead651..6f509ada45 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -81,6 +81,8 @@ public: /// int docbook(odocstream &, OutputParams const &) const; /// + int xhtml(odocstream &, OutputParams const &) const; + /// void validate(LaTeXFeatures & features) const; /// return x,y of given position relative to the inset's baseline