" });\n"
" highlight_current_focus_idx ();\n");
+struct html_doctypedecl : public xml::doctypedecl
+{
+ void write_as_xml (pretty_printer *pp,
+ int depth, bool indent) const final override
+ {
+ if (indent)
+ {
+ for (int i = 0; i < depth; ++i)
+ pp_string (pp, " ");
+ }
+ pp_string (pp, "<!DOCTYPE html\n"
+ " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
+ if (indent)
+ pp_newline (pp);
+ }
+};
+
/* html_builder's ctor. */
html_builder::html_builder (diagnostic_context &context,
gcc_assert (m_line_maps);
m_document = std::make_unique<xml::document> ();
+ m_document->m_doctypedecl = std::make_unique<html_doctypedecl> ();
{
auto html_element = std::make_unique<xml::element> ("html", false);
html_element->set_attr ("xmlns",
document::write_as_xml (pretty_printer *pp, int depth, bool indent) const
{
pp_string (pp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- pp_string (pp, "<!DOCTYPE html\n"
- " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
- " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
- if (indent)
- pp_newline (pp);
+ if (m_doctypedecl)
+ m_doctypedecl->write_as_xml (pp, depth, indent);
for (auto &iter : m_children)
iter->write_as_xml (pp, depth, indent);
}
namespace selftest {
+static void
+test_no_dtd ()
+{
+ xml::document doc;
+ pretty_printer pp;
+ doc.write_as_xml (&pp, 0, true);
+ ASSERT_STREQ
+ (pp_formatted_text (&pp),
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+}
+
static void
test_printer ()
{
void
xml_cc_tests ()
{
+ test_no_dtd ();
test_printer ();
test_attribute_ordering ();
}
struct node_with_children;
struct document;
struct element;
+ struct doctypedecl;
struct node
{
{
void write_as_xml (pretty_printer *pp,
int depth, bool indent) const final override;
+
+ std::unique_ptr<doctypedecl> m_doctypedecl;
+};
+
+struct doctypedecl : public node
+{
+ // still abstract
};
struct element : public node_with_children