hendrik-weiler / htmldecoratorsparsercplusplus

This class parses decorator annotations from html and replaces variable placeholders.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

htmldecoratorsparser c++

This class parses decorator annotations from html and replaces variable placeholders.

This is the parser of the htmldecorators project

Example

Data: test3 = hello, text = Lorem ipsum

@DecoratorName
@Decorator2()
@Decorator3
<ul></ul>

@DecWithParamVariable(
    path=${test3},
    text="Hello World",
    textWithoutQuotes=Without yes
)
<p>Hello World</p>

<h1>${text}</h1>

The result will be in html:

<ul data-dec-id="htmldec162403918934013120955"></ul>

<p data-dec-id="htmldec16240391893388115993">Hello World</p>

<h1>Lorem ipsum</h1>

The definition would look like this:

-------
Id=htmldec162403918934013120955
Name=DecoratorName
-------
Id=htmldec162403918934013120955
Name=Decorator2
-------
Id=htmldec162403918934013120955
Name=Decorator3
-------
Id=htmldec16240391893388115993
Name=DecWithParamVariable
Key=path, Value=hello // note that the variable was set into the definition and was not replaced in the html
Key=text, Value=hello world
Key=textWithoutQuotes, Value=Without yes

Usage

#include "src/Parser.h"

using HTMLDecorators::IdMap;
using HTMLDecorators::Parser;
...
IdMap GenIds {};

Parser parser = Parser{GenIds};

// without data
string htmlOutput = parser.Parse(htmlstring);
parser.DecoratorList; // The list of extracted decorators

// with data
unordered_map<string,string> data {};
data.insert({"value1","Value 1"});
data.insert({"headline","Headline"});

string htmlOutput = parser.Parse(htmlstring, data);
parser.DecoratorList;

About

This class parses decorator annotations from html and replaces variable placeholders.

License:MIT License


Languages

Language:C++ 98.9%Language:CMake 1.1%