HTags plugin for Take Command / TCC / 4NT
beta version 0.60.4 2013-04-24
Generating HTML from within a TCC batch file can be tricky, since many of the characters required for HTML — less-than and greater-than signs and ampersands in particular — also have special meaning to TCC. This plugin provides functions which make it easy to write HTML tags and entities from Take Command.
To use this plugin, copy HTAGS.DLL to some known location on your
hard drive. Load the plugin with a
PLUGIN /L command. For
plugin /l c:\bin\tcmd\htags\htags.dll
If you copy the .DLL to a subdirectory named
within your Take Command program directory, the plugin will be loaded
automatically by each new instance of TCC.
This plugin takes advantage of Unicode’s “Halfwidth and Fullwidth Forms” block, specifically the characters at U+FF01 through U+FF5E. These characters correspond to ASCII characters 0x21 through 0x7E, and when redirected to a file with //UnicodeOutput=No, they will be automatically translated back to their ASCII equivalents. But TCC doesn’t assign any significance to the characters in this range, so they can be safely used in a batch file. In particular, HTags makes heavy use of U+FF05 (fullwidth percent sign), U+FF06 (fullwidth ampersand), U+FF1C (fullwidth less-than sign), and U+FF1E (fullwidth greater-than sign.) Using these characters gives us HTML tags and entities which can be used in batch files and functions, displayed on screen or redirected to a file, without tripping over TCC’s special syntax characters.
Depending on your font, whether TCC is running in a standalone console window or within a Take Command tab, the phase of the moon, and general Windows witchiness, these characters may or may not appear the same on-screen as their ASCII equivalents. If you see empty boxes instead of normal-looking characters, try a different font. The default “Raster Fonts” works well for me, although it’s not terribly attractive.
One consequence of this approach is that TCC’s Unicode output option must be turned off. If //UnicodeOutput=Yes, then redirected characters will not be translated into ASCII, and you’ll get strange characters in the output file. When any of the new functions are called the plugin will check that Unicode output is disabled, and display an error message if it isn’t.
The syntax definitions in the following text use these conventions for clarity:
|indicates text which must be typed exactly as shown.|
|indicates optional text, which may be typed as shown or omitted.|
|Bold italic||names a required argument; a value must be supplied.|
|Regular italic||names an optional argument.|
|ellipsis…||after an argument means that more than one may be given.|
|string||the text to process|
The appearance of this function’s output depends on both the character set and the display font. In general, if an entity shows up as a question mark, either the corresponding character does not exist in the current character set, or else this plugin just doesn’t recognize the entity. If an entity appears as a hollow rectangle, it’s usually because the display fonts doesn’t contain a glyph for that character.
C:\> echo %@deentitize[“Here Today — Here Tomorrow!” ®]
"Here Today -- Here Tomorrow!" (R)
|n||which document type to return:|
|0: HTML 5 (default)|
|1: HTML 4.01 strict|
|2: HTML 4.01 transitional|
|3: HTML 4.01 frameset|
|16: XHTML 1.0 strict|
|17: XHTML 1.0 transitional|
|18: XHTML 1.0 frameset|
C:\> echo %@doctype
|tag||an HTML tag|
|string||the string to enclose in tags|
tag will be used verbatim for the opening
tag. For the closing tag, a slash will be prefixed, and
tag will be truncated at the first space (if
any). The string will be entitized according
to the current plugin settings. It is possible to nest one
@ENTAG function within the string
argument of another
C:\> echo %@entag[p,This is a test.]
<p>This is a test.</p>
C:\> echo %@entag[p class="demo","This is a test", he said.]
<p class="demo">“This is a test”, he said.</p>
C:\> echo %@entag[p,"This is %@entag[em,only] a test", he said.]
<p>“This is <em>only</em> a test”, he said.</p>
|string||the string to be entitized|
See also the HTAGS command, which allows you to change options controlling entitization.
C:\> echo %@entitize["Quick & Silver's"]
“Quick & Silver’s”
|string||the text of the comment|
C:\> echo %@hcomment[Hello, world.]
<!-- Hello, world. -->
|string||the string to be decoded|
Only sequences of a percent sign followed by two valid hexadecimal digits will be replaced. Anything else (e.g. a percent sign followed by a single hex digit) will be returned unchanged. The null character, %00, is not allowed.
C:\> echo %@hexdec[This%%20is%%20a%%20test.]
This is a test.
|string||the string to be hex-encoded|
The characters not replaced with hex codes are letters, digits,
and these symbols:
#$+-./:;=?@_ To define a
different list of characters not to hex-encode, create an environment variable
C:\> echo %@hexenc[This is a test.]
|char||a single character, or|
|string||the name of an HTML entity|
If a single character is specified, the plugin will attempt to find a matching named entity, e.g. &. Failing that, it will return a decimal numeric entity, e.g. @. If a multicharacter string is specified, the plugin will assume it’s the name of an HTML entity, and just wrap it fore-and-aft with an ampersand and a semicolon.
C:\> echo %@makeentity[copy] %@makeentity[@]
|tag||an HTML tag|
The argument is simply wrapped in less-than and greater-than signs.
C:\> echo %@tag[p class="bodytext"]
|insert line numbers; |
|create a header row|
|CSS class name for the TABLE tag|
|CSS style info for the TABLE tag|
|CSS class name for column n TD tags|
|CSS style info for column n TD tags|
|CSS class name for line-number TD tags; implies /L|
|CSS style info for line-number TD tags; implies /L|
|CSS class name for TD tags of even-numbered rows|
|CSS class name for TD tags of odd-numbered rows|
|CSS style info for TD tags of even-numbered rows|
|CSS style info for TD tags of odd-numbered rows|
|arrayname||a two-dimensional array variable|
The arrayname is required. The variable should
be declared and filled with data before running
first dimension of the array is the row number; the second is the column number.
Array cells will be entitized; any empty cell will be stored as a non-breakable
• Note: This command is disabled in TCC/LE, and in 4NT/Take Command prior to v10. It is only available in versions which support array variables.
|don’t change||always replace with "||“ or ” (best guess)||2|
|don’t change||always replace with ||best guess||2|
|don’t change||replace -- with —||1|
|don’t change||replace with '||replace with '||‘ or ’ (best guess)||3|
|resets all options to their default states|
At this time, all of the options set or reported by
control details of how characters in strings are converted to HTML
QUOTES controls how the ASCII double-quote
character " is handled;
SPACES controls the ASCII
space character; DASH determines whether or not a double dash, surrounded
by spaces, is converted to an — and APOS controls the ASCII
DEFAULTS resets all of the above options
to their default values.
If no options are specified,
HTAGS will display the current
settings and the plugin version.
All strings in this plugin are limited to 16,383 characters. Attempting to pass or return a string longer than 16,383 characters may result in an error message, silent truncation, or possibly even a crash.
HTags is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.