From 5dd4f05089608a66c435d6be36d4bc93dc425986 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 27 Sep 2019 18:35:47 +0300 Subject: Prework for HTML. --- example/filter_html.cpp | 18 ++++++++++++++++++ example/plain_to_html.cpp | 2 -- src/html.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++----- src/html.hpp | 3 +++ src/plain.cpp | 13 ------------- src/plain.hpp | 7 ------- src/texo.cpp | 8 ++++++-- 7 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 example/filter_html.cpp 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 +#include +#include + +int main() +{ + TexoFileExporter exporter(stdout); + TexoHTMLProducer producer(exporter); + TexoHTMLImporter importer(producer); + importer.PutStr( + "\n" + "Some br:
\n" + "

And paragraphs work well too...

\n" + "You can use some 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 -#include -#include #include #include #include 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("

"); break; - case Texo::paragraph_end: exporter.PutStr("

"); break; - case Texo::newline: exporter.PutStr("
"); + case Texo::character: exporter.Put(piece.c); break; + case Texo::paragraph_begin: exporter.PutStr("

"); break; + case Texo::paragraph_end: exporter.PutStr("

"); break; + case Texo::newline: exporter.PutStr("
"); break; + case Texo::bold_begin: exporter.PutStr(""); break; + case Texo::bold_end: exporter.PutStr(""); break; + case Texo::italic_begin: exporter.PutStr(""); break; + case Texo::italic_end: exporter.PutStr(""); break; + case Texo::strike_begin: exporter.PutStr(""); break; + case Texo::strike_end: exporter.PutStr(""); break; + case Texo::underline_begin: exporter.PutStr(""); break; + case Texo::underline_end: exporter.PutStr(""); break; + case Texo::link_begin: BeginLink(piece); break; + case Texo::link_end: exporter.PutStr(""); break; + case Texo::image: Image(piece); break; default: break; } } +void TexoHTMLProducer::BeginLink(const Texo &piece) +{ + exporter.PutStr("'); +} + +void TexoHTMLProducer::Image(const Texo &piece) +{ + 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) -- cgit v1.2.3