11#include <QXmlStreamWriter>
19 nodes.prepend (std::move (node));
25 nodes.push_back (std::move (node));
31 return { std::move (n1), std::move (n2) };
36 return { .Name_ = name, .Children_ = { contents } };
41 if (contents.isEmpty ())
43 return Tag { .Name_ = name, .Children_ = { contents } };
48 void TagToHtml (
const Tag& tag, QXmlStreamWriter& w)
50 w.writeStartElement (tag.
Name_);
52 for (
const auto& [name, value] : tag.
Attrs_)
53 w.writeAttribute (name, value);
58 [&w] (
const QString& str) { w.writeCharacters (str); },
59 [&w] (
const Tag& childTag) { TagToHtml (childTag, w); });
73 QXmlStreamWriter w { &result };
76 w.setAutoFormatting (
true);
77 w.setAutoFormattingIndent (*config.
Indent_);
81 w.writeStartDocument ();
85 [&w] (
Html5Dtd) { w.writeDTD (
"html"_qba); },
86 [&w] (
const CustomDtd& dtd) { w.writeDTD (dtd.Dtd_); });
91 w.writeEndDocument ();
101 Attrs_.push_back ({ std::move (key), std::move (value) });
114 .Attrs_ = { {
"xmlns"_qba,
"http://www.w3.org/1999/xhtml"_qs } },
115 .Children_ = std::move (children),
121 return { .Name_ =
"meta"_qba, .Attrs_ = { {
"charset"_qba, charset } } };
126 return { .Name_ =
"title"_qba, .Children_ = { title } };
131 return { .Name_ =
"style"_qba, .Children_ = { style } };
136 return { .Name_ =
"body"_qba, .Children_ = std::move (children) };
141 return { .Name_ =
"img"_qba, .Attrs_ = { {
"src"_qba, url } } };
146 const auto& w = QString::number (size.width ());
147 const auto& h = QString::number (size.height ());
151 .Attrs_ = { {
"src"_qba, url }, {
"width"_qba, w }, {
"height"_qba, h } },
157 return { .Name_ =
"li"_qba, .Children_ = std::move (children) };
162 return { .Name_ =
"ul"_qba, .Children_ = std::move (children) };
167 return { .Name_ =
"p"_qba, .Children_ = std::move (children) };
173 result.reserve (rows);
175 for (
size_t r = 0; r < rows; ++r)
178 rowCells.reserve (cols);
179 for (
size_t c = 0; c < cols; ++c)
180 rowCells.push_back (
Tag { .Name_ =
"td"_qba, .Children_ = cell (r, c) });
182 result.push_back (
Tag { .Name_ =
"tr"_qba, .Children_ = std::move (rowCells) });
auto Visit(const Either< Left, Right > &either, Args &&... args)
constexpr auto operator+(RawStr< N1, Char > s1, CtString< N2, Char > s2) noexcept
std::variant< Tag, QString, NoNode > Node
UTIL_SLL_API Tag & WithAttr(QByteArray, QString) &&
static UTIL_SLL_API Tag WithText(const QByteArray &name, const QString &contents)
UTIL_SLL_API T Serialize(const TagSerializeConfig &={}) const
static UTIL_SLL_API Node WithTextNonEmpty(const QByteArray &name, const QString &contents)
std::optional< int > Indent_