SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
format_html.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <iostream>
13
16#include <seqan3/version.hpp>
17
18namespace seqan3::detail
19{
20
33class format_html : public format_help_base<format_html>
34{
37
39 friend base_type;
40
41public:
45 format_html() = default;
46 format_html(format_html const & pf) = default;
47 format_html & operator=(format_html const & pf) = default;
48 format_html(format_html &&) = default;
50 ~format_html() = default;
51
53 format_html(std::vector<std::string> const & names, bool const advanced = false) : base_type{names, advanced} {};
55
56private:
59 {
60 if (is_dl)
61 {
62 std::cout << "</dl>\n";
63 is_dl = false;
64 }
65 }
66
69 {
70 if (is_p)
71 {
72 std::cout << "</p>\n";
73 is_p = false;
74 }
75 }
76
79 {
80 // Print HTML boilerplate header.
81 std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "
82 << "http://www.w3.org/TR/html4/strict.dtd\">\n"
83 << "<html lang=\"en\">\n"
84 << "<head>\n"
85 << "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n"
86 << "<title>" << escape_special_xml_chars(meta.app_name) << " &mdash; "
88 << "</head>\n"
89 << "<body>\n";
90
91 std::cout << "<h1>" << to_html(meta.app_name) << "</h1>\n"
92 << "<div>" << to_html(meta.short_description) << "</div>\n";
93 }
94
98 void print_section(std::string const & title)
99 {
100 // SEQAN_ASSERT_NOT_MSG(isDl && isP, "Current <dl> and <p> are mutually exclusive.");
103 std::cout << "<h2>" << to_html(title) << "</h2>\n";
104 }
105
109 void print_subsection(std::string const & title)
110 {
111 // SEQAN_ASSERT_NOT_MSG(isDl && isP, "Current <dl> and <p> are mutually exclusive.");
114 std::cout << "<h3>" << to_html(title) << "</h3>\n";
115 }
116
122 void print_line(std::string const & text, bool line_is_paragraph)
123 {
124 // SEQAN_ASSERT_NOT_MSG(isDl && isP, "Current <dl> and <p> are mutually exclusive.");
126 if (!is_p) // open parapgraph
127 {
128 std::cout << "<p>\n";
129 is_p = true;
130 }
131 std::cout << to_html(text) << "\n";
132 if (line_is_paragraph)
134 else
135 std::cout << "<br>\n";
136 }
137
147 void print_list_item(std::string const & term, std::string const & desc)
148 {
149 // SEQAN_ASSERT_NOT_MSG(isDl && isP, "Current <dl> and <p> are mutually exclusive.");
151
152 if (!is_dl)
153 {
154 std::cout << "<dl>\n";
155 is_dl = true;
156 }
157 std::cout << "<dt>" << to_html(term) << "</dt>\n"
158 << "<dd>" << to_html(desc) << "</dd>\n";
159 }
160
163 {
165
166 // Print HTML boilerplate footer.
167 std::cout << "</body></html>";
168 }
169
175 {
177 std::string result;
178 std::vector<std::string> open_tags; // acts as a stack of html tags
179
180 for (auto it = input.begin(); it != input.end(); ++it)
181 {
182 if (*it == '\\')
183 {
184 // Handle escape sequence, we interpret only "\-", "\fI", and "\fB".
185 ++it;
186 assert(!(it == input.end()));
187 if (*it == '-')
188 {
189 result.push_back(*it);
190 }
191 else if (*it == 'f')
192 {
193 ++it;
194 assert(!(it == input.end()));
195 if (*it == 'I')
196 {
197 open_tags.push_back("em");
198 result.append("<em>");
199 }
200 else if (*it == 'B')
201 {
202 open_tags.push_back("strong");
203 result.append("<strong>");
204 }
205 else if (*it == 'P')
206 {
207 assert(!open_tags.empty());
208 result.append("</");
209 result.append(open_tags.back());
210 result.append(">");
211 open_tags.pop_back();
212 }
213 else
214 {
215 result.append("\\f");
216 result.push_back(*it);
217 }
218 }
219 else
220 {
221 result.push_back('\\');
222 result.push_back(*it);
223 }
224 }
225 else
226 {
227 result.push_back(*it);
228 }
229 }
230
231 return result;
232 }
233
239 {
240 return "<strong>" + str + "</strong>";
241 }
242
244 bool is_dl{false};
246 bool is_p{false};
247};
248
249} // namespace seqan3::detail
T append(T... args)
T back(T... args)
T begin(T... args)
std::string escape_special_xml_chars(std::string const &original)
Escapes certain characters for correct output.
Definition format_base.hpp:142
The format that contains all helper functions needed in all formats for printing the interface descri...
Definition format_base.hpp:197
argument_parser_meta_data meta
Stores all meta information about the application.
Definition format_base.hpp:421
The format that prints the help page as html to std::cout.
Definition format_html.hpp:34
format_html(format_html &&)=default
Defaulted.
std::string to_html(std::string const &input)
Converts console output formatting to the HTML equivalent.
Definition format_html.hpp:174
format_html & operator=(format_html &&)=default
Defaulted.
std::string in_bold(std::string const &str)
Format string as in_bold.
Definition format_html.hpp:238
void maybe_close_list()
Closes HTML list tag (dl) if needed.
Definition format_html.hpp:58
friend base_type
Befriend the base class to give access to the private member functions.
Definition format_html.hpp:39
void print_line(std::string const &text, bool line_is_paragraph)
Prints a text in HTML format to std::cout.
Definition format_html.hpp:122
bool is_dl
Current state is either inside a html <dl> tag (true) or not (false).
Definition format_html.hpp:244
void print_footer()
Prints a help page footer in HTML format to std::cout.
Definition format_html.hpp:162
void maybe_close_paragraph()
Closes HTML paragraph tag (p) if needed.
Definition format_html.hpp:68
bool is_p
Current state is either inside a html <p> tag (true) or not (false).
Definition format_html.hpp:246
format_html & operator=(format_html const &pf)=default
Defaulted.
void print_header()
Prints a help page header in HTML format to std::cout.
Definition format_html.hpp:78
void print_subsection(std::string const &title)
Prints a subsection title in HTML format to std::cout.
Definition format_html.hpp:109
void print_section(std::string const &title)
Prints a section title in HTML format to std::cout.
Definition format_html.hpp:98
format_html(format_html const &pf)=default
Defaulted.
~format_html()=default
Defaulted.
format_html()=default
Defaulted.
void print_list_item(std::string const &term, std::string const &desc)
Prints a help page list_item in HTML format to std::cout.
Definition format_html.hpp:147
format_html(std::vector< std::string > const &names, bool const advanced=false)
Initializes a format_help_base object.
Definition format_html.hpp:53
T empty(T... args)
T end(T... args)
Provides the format_base struct containing all helper functions that are needed in all formats.
@ advanced
Definition auxiliary.hpp:252
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T pop_back(T... args)
T push_back(T... args)
std::string app_name
The application name that will be displayed on the help page.
Definition auxiliary.hpp:289
std::string short_description
A short description of the application (e.g. "A tool for mapping reads to the genome").
Definition auxiliary.hpp:293
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Provides SeqAn version macros and global variables.
Hide me