Documentation
¶
Overview ¶
Package text provides text processing facilities used by GMA.
Index ¶
- Constants
- func AsHTML(o *renderOptSet)
- func AsPlainText(o *renderOptSet)
- func AsPostScript(o *renderOptSet)
- func CenterPrefix(s string, width int) string
- func CenterSuffix(s string, width int) string
- func CenterText(s string, width int) string
- func CenterTextPadding(strlen, width int) (string, string)
- 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 ¶
const CommonPostScriptPreamble = `` /* 21645-byte string literal not displayed */
The common preamble we use for a lot of the PostScript things we write. This provides some common form generation code among other things.
@@:go:form-preamble:begin:CommonPostScriptPreamble@@
const GMAPostScriptPreamble = `` /* 73683-byte string literal not displayed */
@@:go:form-preamble:end:@@ @@:go:gma-preamble:begin:GMAPostScriptPreamble@@
const MarkupSyntax = `` /* 5210-byte string literal not displayed */
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 CenterPrefix ¶ added in v5.22.0
CenterPrefix returns the string of spaces which will need to go before the given string so that, when the string is printed, it will end up centered inside a field of the given width. If the width is insufficient for the string to be held inside it, the empty string is returned since there will therefore not be any padding that goes to the left of the string.
func CenterSuffix ¶ added in v5.22.0
CenterSuffix is like CenterPrefix but gives the spaces which follow the string to complete the centering operation.
func CenterText ¶ added in v5.22.0
CenterText returns a padded string with the input string s centered within a field of the given width.
func CenterTextPadding ¶ added in v5.22.0
CenterTextPadding takes the number of characters in the string and the field width, and returns the prefix and suffix padding strings.
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 described in gma-markup-syntax(7) and in the MarkupSyntax constant string in this package.
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.