Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81352 / ts2html / highlighter.cpp
diff options
context:
space:
mode:
Commitf5dc138f53ca4eb98063be5723785b79557e9cc3 (patch)
Author
 Dimitar Milev <milev.1996@gmail.com>
2018-10-25 14:28:25 +0300
Committer
 dtrendafilov <trendafilov.dn@gmail.com>
2018-10-25 14:28:25 +0300
Files461884052c9d50364cd00188b3f5d0082c50184e /homework/81352/ts2html/highlighter.cpp
IPL-f5dc138f53ca4eb98063be5723785b79557e9cc3.tar
IPL-f5dc138f53ca4eb98063be5723785b79557e9cc3.tar.gz
IPL-f5dc138f53ca4eb98063be5723785b79557e9cc3.zip
Parenta4c91889a67ec12057d08d21a81a1f4ed677fc67 (diff)
homework1: typescript syntax highlighter (#22)
1 files changed, 32 insertions, 0 deletions
-rw-r--r--homework/81352/ts2html/highlighter.cpp32
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 <sstream>
+#include <iostream>
+#include <unordered_set>
+#include "highlighter.h"
+
+Highlighter::Highlighter(std::vector<Token> tokens): tokens(tokens){}
+
+std::string Highlighter::highlight() {
+ std::ostringstream result;
+ result << "<!doctype><html><head>";
+ result << "<style>.keyword {color:red;} \
+ .operator {color:#0e7c31; font-weight: bold} \
+ .number {color:#d119b2;} .string {color:blue;} \
+ .comment {color:grey; font-style: italic;} \
+ .line_number {opacity: 0.5;} \
+ .decorator {color:#1a1f63; font-style: italic;} \
+ .user_defined_type {color:#105109} \
+ </style></head><body><pre>";
+ if (!this->tokens.empty()) {
+ result << "<span class=\"line_number\">1. </span>";
+ }
+ int line_number = 2;
+ for (Token token: this->tokens) {
+ if (token.getTokenType() == TokenType::NEWLINE) {
+ result << "\n<span class=\"line_number\">" << line_number++ << ". </span>";
+ } else {
+ result << "<span class=\"" << token.getTypeName() << "\">" << token.getTextValue() << "</span>";
+ }
+ }
+ result << "</pre></body></html>";
+ return result.str();
+}