Skip to content

Commit c0418a2

Browse files
committed
Many improvements to @longcode docs
1 parent c900e5a commit c0418a2

2 files changed

Lines changed: 71 additions & 22 deletions

File tree

src/LongcodeTag.asciidoc

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
:doctitle: @longCode tag
22

3-
link:index[PasDoc] uses the tag @longcode to mark example code which
4-
is preformatted so the layout should not be changed in the output. In
5-
addition link:index[PasDoc] will add code highlighting like in the
6-
Delphi IDE (see also link:CodeTag[@code]).
7-
8-
For compatibility with older pasdoc behaviour, you must specify an extra
9-
"marker" character at the beginning and at the end of text that will be
10-
formatted. Any character can be used but it is best to avoid the space
11-
character or any other character that cannot be seen. The common
12-
practice is to use "#" as the marker character. In previous pasdoc
13-
versions, this marker was used to mark end of longcode text. But
14-
currently longcode parameters are just parsed to the next matching
15-
closing parenthesis (just like parameters for any other tag).
16-
17-
Example:
3+
Use the tag `@longCode` to include a piece of Pascal code in the documentation. This is usually a short example how to use the identifier you're documenting.
4+
5+
The Pascal code will be displayed:
6+
7+
- using a fixed-width font,
8+
- the formatting inside (whitespaces, like spaces and newlines) will be preserved (except removing a common prefix of whitespace from all the lines, see below),
9+
- and the code will be syntax-highlighted, using colors and bold/italic to show the structure of the code.
10+
11+
Example usage:
1812

1913
[source,pascal]
2014
----
2115
(*Some example use of TForm.OnCreate :
2216
23-
@longCode(#
17+
@longCode(
2418
procedure TForm1.FormCreate(Sender: TObject);
2519
var
2620
I: Integer;
@@ -35,12 +29,67 @@ Example:
3529
// It will be formatted as if it were meaningful pascal code.
3630
end;
3731
end;
38-
#)
32+
)
3933
*)
34+
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
4035
----
4136

42-
Note that this tag does not expand its parameter (see
43-
link:TagsParameters[TagsParameters]), which means that @-tags are
44-
_not_ expanded inside the parameter of this tag, paragraphs are _not_
45-
inserted, and you can simply write @ char to get it in the output (no
46-
need to double it, like @@).
37+
This example will result in a description that looks like this in HTML (with the default CSS):
38+
39+
image::assets/images/longcode.png[Sunset]
40+
41+
The `@longCode` tag does not _expand_ the given parameter (see link:TagsParameters[TagsParameters]), which means that:
42+
43+
- Other @-tags are _not_ expanded inside the `@longCode` contents,
44+
- paragraphs are _not_ inserted and in general whitespace has no special meaning,
45+
- you can simply write a single `@` char to get it in the output (no need to double it, like `@@`). For example this is valid:
46+
+
47+
[source,pascal]
48+
----
49+
{ Do something with the pointer to an Integer. Use like this:
50+
@longCode(
51+
var
52+
MyInteger: Integer;
53+
begin
54+
Foo(@MyInteger);
55+
end;
56+
) }
57+
procedure Foo(const A: PInteger);
58+
----
59+
60+
To make it comfortable to write, we remove "initial whitespace" from all the lines in the included Pascal code. To determine what is exactly the _"initial whitespace"_, we find the longest common prefix of all lines in the `@longCode` parameter that contains only whitespace, and then we remove it from all the lines. This way all the following examples are equivalent:
61+
62+
[source,pascal]
63+
----
64+
{ @longCode(
65+
Foo;
66+
Bar;
67+
)
68+
}
69+
procedure Sample1;
70+
71+
{ @longCode(
72+
Foo;
73+
Bar;
74+
)
75+
}
76+
procedure Sample2;
77+
78+
{ @longCode(
79+
Foo;
80+
Bar;
81+
)
82+
}
83+
procedure Sample3;
84+
85+
{ @longCode(
86+
Foo;
87+
Bar;
88+
)
89+
}
90+
procedure Sample4;
91+
----
92+
93+
The contents of the `@longCode` tag span to the matching closing parenthesis, just like for all other `@tags`.
94+
95+
In the past, `@longCode` required a special marker character at the beginning and at the end of the text (the convention was to use `#` for this, but any character was valid). This is no longer necessary and is just ignored by the current pasdoc versions. For backward compatibility, if the first and last character of the `@longCode` parameter (before any trimming and indentation removal) are the same, it is treated as a marker character and removed. You will usually not notice this -- as these characters are almost always whitespace or are different.

src/assets/images/longcode.png

66.5 KB
Loading

0 commit comments

Comments
 (0)