All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Builtins.h
Go to the documentation of this file.
1 // Copyright 2015 Thomas Trapp
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEXT_BUILTINS_H_INCLUDED
16 #define HEXT_BUILTINS_H_INCLUDED
17 
18 /// @file
19 /// Contains every predefined CaptureFunction.
20 
21 #include "hext/CaptureFunction.h"
22 
23 
24 namespace hext {
25 
26 
27 /// A CaptureFunction that returns the text of an HTML element.
28 /// The intent is to mimic functions like jQuery's text(), IE's innerText() or
29 /// textContent().
30 ///
31 /// @par Example:
32 /// ~~~~~~~~~~~~~
33 /// GumboNode * node = ...; // <div> like<div>a</div>rolling stone</div>
34 /// assert(TextBuiltin(node) == "like a rolling stone");
35 /// ~~~~~~~~~~~~~
36 ///
37 /// @param node: A pointer to a GumboNode.
38 /// @returns A string containing the HTML element's text.
39 extern const CaptureFunction TextBuiltin;
40 
41 
42 /// A CaptureFunction that returns the inner HTML of an HTML element.
43 /// The intent is to mimic innerHtml().
44 ///
45 /// @par Example:
46 /// ~~~~~~~~~~~~~
47 /// GumboNode * node = ...; // <div> like<div>a</div>rolling stone</div>
48 /// assert(InnerHtmlBuiltin(node) == " like<div>a</div>rolling stone");
49 /// ~~~~~~~~~~~~~
50 ///
51 /// @param node: A pointer to a GumboNode.
52 /// @returns A string containing the HTML element's inner HTML.
54 
55 
56 /// A CaptureFunction that returns the inner HTML of an HTML element without
57 /// tags.
58 ///
59 /// @par Example:
60 /// ~~~~~~~~~~~~~
61 /// GumboNode * node = ...; // <div> like<div>a</div>rolling stone</div>
62 /// assert(StripTagsBuiltin(node) == " likearolling stone");
63 /// ~~~~~~~~~~~~~
64 ///
65 /// @param node: A pointer to a GumboNode.
66 /// @returns A string containing the HTML element's inner HTML without tags.
68 
69 
70 } // namespace hext
71 
72 
73 #endif // HEXT_BUILTINS_H_INCLUDED
74 
std::function< std::string(const GumboNode *)> CaptureFunction
A type of std::function that receives an HTML element and returns a string.
const CaptureFunction InnerHtmlBuiltin
A CaptureFunction that returns the inner HTML of an HTML element.
const CaptureFunction StripTagsBuiltin
A CaptureFunction that returns the inner HTML of an HTML element without tags.
Declares hext::CaptureFunction.
const CaptureFunction TextBuiltin
A CaptureFunction that returns the text of an HTML element.