HtmlBuilder
A simple C++ header-only HTML 5 Generator library, using a Document Object Model (DOM).
Copyright (c) 2017-2019 SĂ©bastien Rombauts (sebastien.rombauts@gmail.com)
Current status
Deployed in production in a small application.
Support
- Windows 10 - VS2015 / 2017
- Linux Ubuntu 16.04 Clang 7 / GCC 5.4
Features
- DOM Model
- Example featuring Bootstrap's navigation bar
Missing features
- Encoding of HTML Entities (special chars)
- Support for HTML Comments
- Support for CSS inline style (this is probably easy)
Javascript inline script is currently out of scope.
Example
The following example is provided in src/Main.cpp.
Source Code
HTML::Document document("Welcome to HTML");
document.addAttribute("lang", "en");
document << HTML::Header2("Generated HTML") << HTML::Break() << HTML::Break();
document.body() << "Which results in the following HTML page (truncated to fit in this README): ";
document << HTML::Text("Text directly in the body. ") << HTML::Text("Text directly in the body.") << HTML::Break()
<< HTML::Text("Text directly in the body.");
document << HTML::Paragraph("This is the way to go for a big text in a multi-line paragraph.");
document << HTML::Link("Google", "http://google.com").cls("my_style");
document << (HTML::Paragraph("A paragraph. ").addAttribute("style", "font-family:arial")
<< HTML::Text("Text child.") << HTML::Break() << HTML::Text("And more text."));
document << (HTML::List()
<< (HTML::ListItem("Text item"))
<< (HTML::ListItem() << HTML::Link("Github Link", "http://srombauts.github.io").title("SRombaut's Github home page"))
<< (HTML::ListItem() << (HTML::List()
<< HTML::ListItem("val1")
<< HTML::ListItem("val2"))));
document << (HTML::Table()
<< (HTML::Row() << HTML::ColHeader("A") << HTML::ColHeader("B"))
<< (HTML::Row() << HTML::Col("Cell_11") << HTML::Col("Cell_12"))
<< (HTML::Row() << HTML::Col("Cell_21") << HTML::Col("Cell_22"))
<< (HTML::Row() << HTML::Col("") << HTML::Col("Cell_32")));
Generated HTML
Which results in the following HTML page (truncated to fit in this README):
Text directly in the body. Text directly in the body.
Text directly in the body.
This is the way to go for a big text in a multi-line paragraph.
GoogleA paragraph. Text child.
And more text.
- Text item
- Github Link
-
- val1
- val2
A | B |
---|---|
Cell_11 | Cell_12 |
Cell_21 | Cell_22 |
Cell_32 |
Building with CMake
This is a header only library, so just include the include folder and go on.
Get cpplint submodule
git submodule init
git submodule update
Typical generic build (see also "build.bat" or "./build.sh")
mkdir build
cd build
cmake .. # cmake .. -G "Visual Studio 10" # for Visual Studio 2010
cmake --build . # make
Debug build for Unix Makefiles
mkdir Debug
cd Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug # -G "Unix Makefiles"
cmake --build . # make
Release build
mkdir Release
cd Release
cmake .. -DCMAKE_BUILD_TYPE=Release # -G "Unix Makefiles"
cmake --build . # make