diff options
-rw-r--r-- | example/filter_html.cpp | 18 | ||||
-rw-r--r-- | example/plain_to_html.cpp | 2 | ||||
-rw-r--r-- | src/html.cpp | 48 | ||||
-rw-r--r-- | src/html.hpp | 3 | ||||
-rw-r--r-- | src/plain.cpp | 13 | ||||
-rw-r--r-- | src/plain.hpp | 7 | ||||
-rw-r--r-- | src/texo.cpp | 8 |
7 files changed, 70 insertions, 29 deletions
diff --git a/example/filter_html.cpp b/example/filter_html.cpp new file mode 100644 index 0000000..ced8f5f --- /dev/null +++ b/example/filter_html.cpp @@ -0,0 +1,18 @@ +#include <stdio.h> +#include <html.hpp> +#include <file.hpp> + +int main() +{ + TexoFileExporter exporter(stdout); + TexoHTMLProducer producer(exporter); + TexoHTMLImporter importer(producer); + importer.PutStr( + "<script>EVIL MAGIC</script>\n" + "<a href='#'>Some</a> br:<br/>\n" + "<p class='evil_too'>And paragraphs work well too...</p>\n" + "<b>You</b> <i>can</i> <del>use</del> <ins>some</ins> witchcraft.\n" + ); + return 0; + return 0; +} diff --git a/example/plain_to_html.cpp b/example/plain_to_html.cpp index 86171a6..9a81652 100644 --- a/example/plain_to_html.cpp +++ b/example/plain_to_html.cpp @@ -1,6 +1,4 @@ #include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <html.hpp> #include <plain.hpp> #include <file.hpp> 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) |