/* Copyright (C) 2022 Carl Hetherington This file is part of DCP-o-matic. DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DCP-o-matic. If not, see . */ #include "html_formatter.h" #include using std::unique_ptr; using namespace dcp; HTMLFormatter::HTMLFormatter(boost::filesystem::path file) : StreamFormatter(file) { } void HTMLFormatter::heading(std::string const& text) { tagged("h1", text); } void HTMLFormatter::subheading(std::string const& text) { tagged("h2", text); } unique_ptr HTMLFormatter::document() { auto html = wrapped("html"); auto head = wrapped("head"); auto style = wrapped("style"); _file.puts("li {\n" " margin: 2px;\n" " padding: 2px 2px 2px 1em;\n" "}\n" ); _file.puts("li.ok {\n" " background-color: #00ff00;\n" "}\n" "li.warning {\n" " background-color: #ffa500;\n" "}\n" "li.error {\n" " background-color: #ff0000;\n" "}\n" "li.bv21-error {\n" " background-color: #ff6666;\n" "}\n" "ul {\n" " list-style: none;\n" "}\n" ); return html; } unique_ptr HTMLFormatter::body() { return wrapped("body"); } unique_ptr HTMLFormatter::unordered_list() { return wrapped("ul"); } void HTMLFormatter::list_item(std::string const& text, boost::optional type) { if (type) { _file.puts(dcp::String::compose("
  • %2
  • \n", *type, text).c_str()); } else { _file.puts(dcp::String::compose("
  • %1
  • \n", text).c_str()); } } std::function HTMLFormatter::process_string() { return [](std::string s) { boost::replace_all(s, "<", "<"); boost::replace_all(s, ">", ">"); return s; }; } std::function HTMLFormatter::fixed_width() { return [](std::string s) { return String::compose("%1", s); }; } void HTMLFormatter::tagged(std::string tag, std::string content) { _file.puts(String::compose("<%1>%2\n", tag, content, tag).c_str()); } unique_ptr HTMLFormatter::wrapped(std::string const& tag) { _file.puts(String::compose("<%1>", tag).c_str()); return unique_ptr(new Wrap(this, String::compose("", tag))); }