summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/html.cpp48
-rw-r--r--src/html.hpp3
-rw-r--r--src/plain.cpp13
-rw-r--r--src/plain.hpp7
-rw-r--r--src/texo.cpp8
5 files changed, 52 insertions, 27 deletions
diff --git a/src/html.cpp b/src/html.cpp
index 22209f5..c9e3cde 100644
--- a/src/html.cpp
+++ b/src/html.cpp
@@ -8,20 +8,58 @@ TexoHTMLProducer::TexoHTMLProducer(TexoExporter &exporter):
void TexoHTMLProducer::Put(const Texo &piece)
{
switch (piece.type) {
- case Texo::character: exporter.Put(piece.c); break;
- case Texo::paragraph_begin: exporter.PutStr("<p>"); break;
- case Texo::paragraph_end: exporter.PutStr("</p>"); break;
- case Texo::newline: exporter.PutStr("<br/>");
+ case Texo::character: exporter.Put(piece.c); break;
+ case Texo::paragraph_begin: exporter.PutStr("<p>"); break;
+ case Texo::paragraph_end: exporter.PutStr("</p>"); break;
+ case Texo::newline: exporter.PutStr("<br/>"); break;
+ case Texo::bold_begin: exporter.PutStr("<b>"); break;
+ case Texo::bold_end: exporter.PutStr("</b>"); break;
+ case Texo::italic_begin: exporter.PutStr("<i>"); break;
+ case Texo::italic_end: exporter.PutStr("</i>"); break;
+ case Texo::strike_begin: exporter.PutStr("<del>"); break;
+ case Texo::strike_end: exporter.PutStr("</del>"); break;
+ case Texo::underline_begin: exporter.PutStr("<ins>"); break;
+ case Texo::underline_end: exporter.PutStr("</ins>"); break;
+ case Texo::link_begin: BeginLink(piece); break;
+ case Texo::link_end: exporter.PutStr("</a>"); break;
+ case Texo::image: Image(piece); break;
default: break;
}
}
+void TexoHTMLProducer::BeginLink(const Texo &piece)
+{
+ exporter.PutStr("<a");
+ if (piece.link_url) {
+ exporter.PutStr(" href='");
+ exporter.PutStr(piece.link_url);
+ exporter.Put('\'');
+ }
+ exporter.Put('>');
+}
+
+void TexoHTMLProducer::Image(const Texo &piece)
+{
+ exporter.PutStr("<img");
+ if (piece.image_src) {
+ exporter.PutStr(" src='");
+ exporter.PutStr(piece.image_src);
+ exporter.Put('\'');
+ }
+ if (piece.image_alt) {
+ exporter.PutStr(" alt='");
+ exporter.PutStr(piece.image_alt);
+ exporter.Put('\'');
+ }
+ exporter.PutStr("/>");
+}
+
TexoHTMLImporter::TexoHTMLImporter(TexoProducer &producer):
TexoImporter(producer)
{}
void TexoHTMLImporter::Put(const char c)
-{
+{ // TODO by automata
producer.Put(Texo(c));
}
diff --git a/src/html.hpp b/src/html.hpp
index c5b2aa4..265ee39 100644
--- a/src/html.hpp
+++ b/src/html.hpp
@@ -8,6 +8,9 @@ class TexoHTMLProducer: public TexoProducer {
public:
TexoHTMLProducer(TexoExporter &exporter);
void Put(const Texo &piece);
+private:
+ void BeginLink(const Texo &piece);
+ void Image(const Texo &piece);
};
diff --git a/src/plain.cpp b/src/plain.cpp
index d8bc1b1..db5c63b 100644
--- a/src/plain.cpp
+++ b/src/plain.cpp
@@ -1,19 +1,6 @@
#include "plain.hpp"
-TexoPlainProducer::TexoPlainProducer(TexoExporter &exporter):
- TexoProducer(exporter)
-{}
-
-void TexoPlainProducer::Put(const Texo &piece)
-{
- switch (piece.type) {
- case Texo::character: exporter.Put(piece.c);
- default: break;
- }
-}
-
-
TexoPlainImporter::TexoPlainImporter(TexoProducer &producer):
TexoImporter(producer), first(true), space(0), newline(false)
{}
diff --git a/src/plain.hpp b/src/plain.hpp
index c5c613c..8c74bce 100644
--- a/src/plain.hpp
+++ b/src/plain.hpp
@@ -4,13 +4,6 @@
#include "texo.hpp"
-class TexoPlainProducer: public TexoProducer {
-public:
- TexoPlainProducer(TexoExporter &exporter);
- void Put(const Texo &piece);
-};
-
-
class TexoPlainImporter: public TexoImporter {
public:
TexoPlainImporter(TexoProducer &producer);
diff --git a/src/texo.cpp b/src/texo.cpp
index 1a2974a..03b31e7 100644
--- a/src/texo.cpp
+++ b/src/texo.cpp
@@ -1,9 +1,13 @@
#include "texo.hpp"
-Texo::Texo(Type type): type(type), c(0) {}
+Texo::Texo(Type type):
+ type(type), c(0), image_src(0), image_alt(0), link_url(0)
+{}
-Texo::Texo(const char c): type(character), c(c) {}
+Texo::Texo(const char c):
+ type(character), c(c), image_src(0), image_alt(0), link_url(0)
+{}
void TexoExporter::PutStr(const char *str)