Let me illustrate…
Copyright (C) 1998-2023 Gregory W. Chicares. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
Namespaces | Classes | Functions
html Namespace Reference

Namespace for helpers used for HTML generation. More...

Namespaces

namespace  attr
 Namespace for HTML attributes.
 
namespace  detail
 
namespace  tag
 Namespace for HTML tags.
 

Classes

class  attribute
 Represents a single attribute of an HTML element. More...
 
class  element
 Represents a normal HTML element which can have content inside it. More...
 
class  text
 Represents a piece of text containing HTML. More...
 
class  void_element
 Represents a void HTML element which can't have anything inside it. More...
 

Functions

text operator+ (text t1, text const &t2)
 

Detailed Description

Namespace for helpers used for HTML generation.

Main idea is to avoid generating HTML using raw strings, which is error prone and difficult to read and maintain. One source of errors is forgetting to escape special characters, such as "<" or "&", and html::text class helps with this by providing from() function doing it automatically.

Another one is forgetting to close a tag (or closing a wrong one) and while html::text is too low level to help with this, html::element can be used for structured HTML generation, which guarantees that the result is well-formed. By using predefined constants in html::tag and html::attr namespaces, typos in the element names can also be automatically avoided.

Function Documentation

◆ operator+()

text html::operator+ ( text  t1,
text const &  t2 
)
inline