Code Samples
Sage supports code samples,
including automatic syntax highlighting for a variety of
programming languages.
For example, to show a sample of SQL code…
[.sql]
select *
from acct a
where a.acct_nbr < 100
order by a.name
[end]
The above produces this…
select *
from acct a
where a.acct_nbr < 100
order by a.name
In general, a tag starting with a period indicates a code sample:
the language's name or file extension follows the period.
Sage offers two styles of code samples: inline and block.
The above example uses the block style,
where the start and end tags are each alone on their own lines
in the Sage source file (except for whitespace and/or comments).
Block code samples are appropriate when you have an entire line
(or more) of code. Sage renders code blocks inside a rounded
rectangle, of the full page width, with an automatic horizontal
scroll bar in case the code is too wide to fit on the page.
Additionally, in the upper-right corner of this box,
Sage indicates the name of the programming language,
and includes a button to copy the entire sample to the clipboard
(as plain text).
For shorter code samples, such as a single keyword or identifier,
or a brief expression, place the start and end tags on the same
line as the other content. For example...
In SQL, the [.sql]delete from[end][...] statement
deletes rows from a specified table.
You'll typically include a [.sql]where[end] clause [-]
unless you want to delete all rows!
Use a [.sql]select count(*)[end]... statement to find
out how many rows a table has.
The above produces this…
In SQL, the delete from… statement deletes rows from a specified table. You'll typically include a where clause – unless you want to delete all rows! Use a select count(*)... statement to find out how many rows a table has.
Note that inline code samples do not word wrap –
the entire sample will remain intact on a single line.
If your code sample is long enough that this causes problems,
either make it a block sample, or break the sample up into
two or more smaller samples (separated by a space or line break),
so the browser will have an opportunity to break the line.
In SQL, the delete from… statement deletes rows from a specified table. You'll typically include a where clause – unless you want to delete all rows! Use a select count(*)... statement to find out how many rows a table has.
To display a general code example (not syntax highlighted in any
particular language), use the [code] tag.
For example…
The command-line syntax is:
[code]
EXIT [/B] [exitCode]
/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE
exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the
process exit code with that number.
[end]
The above produces…
The command-line syntax is: EXIT [/B] [exitCode] /B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE exitCode specifies a numeric number. if /B is specified, sets ERRORLEVEL that number. If quitting CMD.EXE, sets the process exit code with that number.
The command-line syntax is: EXIT [/B] [exitCode] /B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE exitCode specifies a numeric number. if /B is specified, sets ERRORLEVEL that number. If quitting CMD.EXE, sets the process exit code with that number.
If you need the string [end] to appear in the code sample,
modify the start tag to specify a different terminating tag.
For example…
Here is a typical SQL Server query[...]
[.sql end=stop]
select [start], [end], [name], [amount]
from [order_detail]
where [end] is not null
[stop]
Because the string [end] appears in the query itself,
we need to instruct Sage to use a different terminating tag.
The notation [.sql end=stop] tells Sage to look
for the tag [stop] instead of [end].
You can use whatever you like for the alternative terminating
tag, but stop is the conventional backup
(and quit is the usual next option, if both end and stop
appear in the sample).
The above SQL sample produces…
Here is a typical SQL Server query… select [start], [end], [name], [amount] from [order_detail] where [end] is not null
Here is a typical SQL Server query… select [start], [end], [name], [amount] from [order_detail] where [end] is not null
The num attribute indicates that Sage should number
the lines of a code sample…
[.pas num]
function Max(x, y: Integer): Integer;
begin
if x >= y then
Result := x
else
Result := y;
end;
[end]
The above produces…
1│ function Max(x, y: Integer): Integer;
2│ begin
3│ if x >= y then
4│ Result := x
5│ else
6│ Result := y;
7│ end;
By default, the line numbers start at 1,
but you can override this by specifying the
starting line number as the value for the num
attribute…
[.pas num=101]
function Max(x, y: Integer): Integer;
begin
if x >= y then
Result := x
else
Result := y;
end;
[end]
The above produces…
101│ function Max(x, y: Integer): Integer;
102│ begin
103│ if x >= y then
104│ Result := x
105│ else
106│ Result := y;
107│ end;
The starting line number must be non-negative.
In a code sample, no Sage markup is recognized.
Instead, all text (until the terminating tag)
is taken verbatim.
The advantage of this approach is that you can
paste a code example, of any size, into a Sage file,
and (other than the [end] tag) not have to worry
about escaping any special characters.
⏱ Last Modified: 10/24 9:45:52 am