From f5dc138f53ca4eb98063be5723785b79557e9cc3 Mon Sep 17 00:00:00 2001 From: Dimitar Milev Date: Thu, 25 Oct 2018 14:28:25 +0300 Subject: homework1: typescript syntax highlighter (#22) --- homework/81352/ts2html/highlighter.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 homework/81352/ts2html/highlighter.cpp (limited to 'homework/81352/ts2html/highlighter.cpp') diff --git a/homework/81352/ts2html/highlighter.cpp b/homework/81352/ts2html/highlighter.cpp new file mode 100644 index 0000000..6c44066 --- /dev/null +++ b/homework/81352/ts2html/highlighter.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include "highlighter.h" + +Highlighter::Highlighter(std::vector tokens): tokens(tokens){} + +std::string Highlighter::highlight() { + std::ostringstream result; + result << ""; + result << "
";
+    if (!this->tokens.empty()) {
+        result << "1. ";
+    }
+    int line_number = 2;
+    for (Token token: this->tokens) { 
+        if (token.getTokenType() == TokenType::NEWLINE) {
+            result << "\n" << line_number++ << ". ";
+        } else {
+            result << "" << token.getTextValue() << "";
+        }
+    }
+    result << "
"; + return result.str(); +} -- cgit v1.3.1-23-gd82d