Documentation ¶
Overview ¶
Package text provides text processing facilities used by GMA.
Index ¶
- func AsHTML(o *renderOptSet)
- func AsPlainText(o *renderOptSet)
- func AsPostScript(o *renderOptSet)
- func FromRoman(roman string) (int, error)
- func Render(text string, opts ...func(*renderOptSet)) (string, error)
- func ToRoman(i int) (string, error)
- func WithBullets(bullets ...rune) func(*renderOptSet)
- func WithCompactText(o *renderOptSet)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsHTML ¶
func AsHTML(o *renderOptSet)
AsHTML may be added as an option to the Render function to select HTML output format.
func AsPlainText ¶
func AsPlainText(o *renderOptSet)
AsPlainText may be added as an option to the Render function to select plain text output format.
func AsPostScript ¶
func AsPostScript(o *renderOptSet)
AsPostScript may be added as an option to the Render function to select PostScript output format.
func Render ¶
Render converts its input text (in our simple markup notation described below) to an output format as specified by the option(s) passed after the input text in the parameter list.
The set of options which may follow the string to be formatted include these which select the overall output format:
AsPlainText -- render a text-only version of the input (this is the default) AsHTML -- render an HTML version of the input AsPostScript -- render a PostScript version of the input (requires the GMA PostScript preamble and other supporting code; this merely produces the formatted text block to the PostScript data being produced by the application)
and these options to control specific formatting in the selected output format:
WithBullets(...) -- use a custom bullet sequence WithCompactText -- squish verbose text blocks down a bit* *(PostScript format only)
The markup syntax is simple. Lines are collected together into a single logical line which is then wrapped as appropriate to the output format (which may rely on whatever is printing the output to break lines as it prefers).
A blank line marks a paragraph break.
\\ marks a line break.
//text// sets "text" in Italics*†
**text** sets "text" in boldface*†
*blah... Starts bulleted list item‡
**blah... Starts level-2 bulleted list item‡
***blah... Starts level-3 bulleted list item (and so forth)‡
#blah... Starts enumerated list item‡
##blah... ...and so forth‡
[[name]] Creates a hyperlink to "name" where this name itself adequately identifies the linked-to element in GMA (e.g., the name of a spell).
[[link|name]] Creates a hyperlink called "name" which links to GMA element "link".
\. does nothing but serves to disambiguate things such as ** to begin a section of boldface text from ** to begin a 2nd-level bulleted item since the latter must be at the very start of the line.
There is also a special page-break marker <<-->> which is not actually processed by this package, but some output subsystems recognize it when they see it in the output (e.g., PostScript formatted text blocks).
Tables are specified by a set of lines beginning with a | character.‡ Each column in the table is separated from the others with | characters as well. A | at the very end of the row is optional.
|=Size Code|=Area| | S | 5| | M | 5| | L | 10|
This produces a table like
+-----------+------+ | SIZE CODE | AREA | +-----------+------+ | S | 5 | | M | 5 | | L | 10 | +-----------+------+
Table cells beginning with = are headers (usually placed in the first row)
Cells are left- or right-justified if there is leading or trailing space between the | separators for that cell, respectively. If there is space before and after the text, it is centered. In the example above, the size codes will be centered in their column and the area numbers are right-justified in theirs.
Cells which begin with a hyphen (-) indicate that the cell to their left spans into them. For example:
|=Column A|=Column B|=Column C |stuff |more stuff|and more |a really wide column|- |hello
produces:
+----------+------------+----------+ | COLUMN A | COLUMN B | COLUMN C | +----------+------------+----------+ | stuff | more stuff | and more | | a really wide column | hello | +----------+------------+----------+
Notes:
*May cross line boundaries but not paragraphs.
†May nest as in //Italic **and** bold//.
‡Must appear at the very beginning of a line.
func ToRoman ¶
ToRoman converts an integer value to a Roman numeral string. This will return "0" for a zero value.
func WithBullets ¶
func WithBullets(bullets ...rune) func(*renderOptSet)
WithBullets may be added as an option to the Render function to specify a custom set of bullet characters to use for bulleted lists. The bullets passed to this option are used in order, then the list repeats over as necessary for additional levels.
Example:
formattedText, err := Render(srcText, AsPlainText, WithBullets('*', '-'))
This will alternate between '*' and '-' as bullets at each level.
While the default bullet(s) are chosen appropriately for each output format, no other processing is made to the runes passed here; they are used as-is in each case, but the following special characters are recognized and translated to something sensible in each output format:
- U+2022 Standard bullet ‣ U+2023 Triangle bullet ⁃ U+2043 Hyphen bullet ○ U+25CB Unfilled circle bullet ☞ U+261E Pointing index bullet ★ U+2605 Star bullet
func WithCompactText ¶
func WithCompactText(o *renderOptSet)
WithCompactText may be added as an option to the Render function to specify that a more compact rendering of text blocks in order to conserve paper real estate.
Currently only supported for PostScript output.
Example:
ps, err := Render(srcText, AsPostScript, WithCompactText)
Types ¶
This section is empty.