Object pascal subset
HelpNDoc's scripting system is a subset of the Object Pascal language. In addition to usual object Pascal code, HelpNDoc provides an extensive set of API methods which can be used to automate multiple tasks from project creation to control how documentation is generated.
A typical script includes:
1. Variable and constant definitions
const
constant1 = 'Hello';
var
variable1, variable2: string;
var
variable3: integer;
2. Procedure and function definitions
procedure test1();
begin
variable1 := constant1 + ' World';
end;
function test2(): string;
begin
Result := constant1 + ' Universe';
end;
3. Main program code
begin
test1();
Print(variable1);
Print(test2());
end.
Template specific code structure
Template script files usually include a mix of text (e.g. HTML) and Pascal code. To simplify this process and avoid having to use multiple print statements, template script files uses a convention similar to ASP.net or PHP code: everything not surrounded by <% and %> is treated as raw content and exported as-is. As an example:
<html>
<head>
<title><% print('Hello World');%></title>
</head>
<body>
<% for var i := 0 to 10 do begin %>
Hello <%= i %>
<% end; %>
</body>
</html>
Will output:
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10
</body>
</html>
Note: <%= 'Hello World' %> is the same as <% print('Hello World'); %>