2026-07-18 18:48:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <variant>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using strings_t = std::vector<std::string>;
|
|
|
|
|
using attr_t = std::variant<int, float, std::string>;
|
|
|
|
|
|
|
|
|
|
class HTML;
|
|
|
|
|
using html_element_t = std::variant<std::string,HTML>;
|
|
|
|
|
using elements_t = std::vector<html_element_t>;
|
|
|
|
|
|
|
|
|
|
const std::string preamble_tag = "!DOCTYPE html";
|
|
|
|
|
const std::vector<std::string> block_elements {
|
|
|
|
|
"!DOCTYPE", "html", "head", "body",
|
|
|
|
|
"address", "article", "aside", "blockquote", "details", "dialog",
|
|
|
|
|
"div", "dl", "dt", "dd", "fieldset", "figcaption", "figure", "footer", "form",
|
|
|
|
|
"kt-part", "kt-chapter", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "img", "li",
|
|
|
|
|
"main", "nav", "ol", "p", "section", "table", "ul", "td", "tr", "pre" };
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const elements_t& elements);
|
|
|
|
|
std::string to_string(elements_t e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HTML {
|
|
|
|
|
public:
|
|
|
|
|
operator std::string() {
|
|
|
|
|
std::stringstream ss {}; ss << *this; return ss.str(); };
|
|
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML(const std::string& tag) :
|
2026-07-18 18:48:23 +02:00
|
|
|
m_tag(tag) {};
|
|
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML(const std::string& tag, const std::string& text) :
|
2026-07-18 18:48:23 +02:00
|
|
|
m_tag(tag), m_text({text}) {};
|
|
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML(const std::string& tag, elements_t elements) :
|
2026-07-18 18:48:23 +02:00
|
|
|
m_tag(tag), m_elements(elements) {};
|
|
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML& attr(const std::string& name, attr_t value);
|
|
|
|
|
HTML& attrs(const std::string& s);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML& cls(const std::string& name) { return attr("class", name); };
|
|
|
|
|
HTML& sty(const std::string& css) { return attr("style", css); };
|
|
|
|
|
HTML& id(const std::string& id) { return attr("id", id); };
|
2026-07-18 18:48:23 +02:00
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
bool void_element(const std::string& tag) const;
|
|
|
|
|
bool empty_element(const std::string& tag) const;
|
2026-07-18 18:48:23 +02:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const HTML& h);
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& os, const std::vector<HTML>& hv);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string m_tag {};
|
|
|
|
|
std::vector<std::pair<std::string, attr_t>> m_attrs {};
|
|
|
|
|
std::string m_text {};
|
|
|
|
|
elements_t m_elements {};
|
|
|
|
|
|
|
|
|
|
inline static const std::vector<std::string> m_void_tags {
|
|
|
|
|
"!DOCTYPE html", "area", "base", "br", "col", "command", "embed", "hr","img",
|
|
|
|
|
"input", "keygen", "link", "meta", "param", "source", "track", "wbr" };
|
|
|
|
|
|
|
|
|
|
inline static const std::vector<std::string> m_empty_tags { "script" };
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace html {
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
HTML elt(const std::string& tag);
|
|
|
|
|
HTML elt(const std::string& tag, const std::string& text);
|
|
|
|
|
HTML elt(const std::string& tag, elements_t elements);
|
|
|
|
|
HTML elt(const std::string& tag, HTML e, elements_t elts);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
//HTML preamble();
|
|
|
|
|
//HTML head(strings_t css_filenames, strings_t js_filenames);
|
|
|
|
|
|
|
|
|
|
elements_t page(
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
const std::string& title,
|
2026-07-18 18:48:23 +02:00
|
|
|
std::string page_title,
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
const std::string& output_dir,
|
|
|
|
|
const std::string& nav,
|
2026-07-18 18:48:23 +02:00
|
|
|
int max_level,
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
const std::string& toc,
|
|
|
|
|
const std::string& text,
|
|
|
|
|
const std::string& date,
|
|
|
|
|
const std::string& version,
|
|
|
|
|
const std::string& copyright,
|
|
|
|
|
const std::string& css,
|
2026-07-18 18:48:23 +02:00
|
|
|
strings_t css_filenames = {},
|
|
|
|
|
strings_t js_filenames = {},
|
|
|
|
|
strings_t local_fonts = {},
|
|
|
|
|
std::string logo = {});
|
|
|
|
|
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
void add_title(elements_t& body, const std::string& title, const std::string& logo="");
|
|
|
|
|
void add_title(elements_t& body, const std::string& title, const std::string& logo);
|
2026-07-18 18:48:23 +02:00
|
|
|
void add_nav(elements_t& body, int max_level);
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
void add_text(elements_t& body, const std::string& text, const std::string& toc_text, bool text_only);
|
2026-07-18 18:48:23 +02:00
|
|
|
void add_bottom_spacer(elements_t& body);
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
void add_status_bar(elements_t& body, const std::string& date, const std::string& version, const std::string& copyright);
|
2026-07-18 18:48:23 +02:00
|
|
|
void add_page_cache(elements_t& body);
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
void add_js_links(elements_t& body, const std::vector<std::string>& js_filenames, const std::string& output_dir);
|
2026-07-18 18:48:23 +02:00
|
|
|
elements_t make_page(
|
|
|
|
|
elements_t body,
|
Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a
named, logically related group of klammer definitions — with an
operative, idempotent declaration (:requires and :files load in order
at the declaration point, relative to the declaring file). A bare
symbol given to ktext -k, kdesc --input, or :requires resolves to
x/x.k on the search path: the document's directory, then
KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset
lists the available sets. sks/sks.k is the first declared klammerset,
so `-k sks` loads the SKS by name. The engine's lookup classes were
renamed *_set → *_registry to keep the two concepts apart, and the
whole C++ tree now follows standard const-correctness conventions.
tst/ gains klammerset_test.sh (18 cases).
(from dev 64b1abf23e56)
2026-07-30 23:50:07 +02:00
|
|
|
std::string page_title, const std::string& css,
|
|
|
|
|
const std::vector<std::string>& css_filenames,
|
|
|
|
|
const std::vector<std::string>& local_fonts);
|
|
|
|
|
|
|
|
|
|
bool tag_is_block_element(const std::string& tag);
|
|
|
|
|
std::string make_paragraphs(const std::string& html_text);
|
|
|
|
|
std::string minimize_css(const std::string& src);
|
|
|
|
|
std::string minimize_js(const std::string& src);
|
2026-07-18 18:48:23 +02:00
|
|
|
|
|
|
|
|
}
|