Simple Tree Text Markup: Simple Markup for Display as Text or in GUI
This is a tree-based combinator library for simple markup, mainly for displaying messages in a REPL. It features horizontal and vertical composition as well as framed markup. Its main distinguishing feature is its ability to embed source locations, which can be rendered as links.
This package comes with separate modules for inspecting and constructing markup - simple-tree-text-markup/data and simple-tree-text-markup/construct, respectively. Markup can also be constructed through a custom output port, supplied by simple-tree-text-markup/port.
There’s also a module simple-tree-text-markup/text that renders markup to text. Rendering markup to GUI is quite context-specific. Hence, the code for rendering to GUIs is implemented with specific applications, such as DrRacket or the test engine.
1 Markup Representation
(require simple-tree-text-markup/data) | |
package: simple-tree-text-markup-lib |
This module defines the representation for markup as a set of struct definitions. It should be required when inspecting markup, For constructing markup, see simple-tree-text-markup/construct.
A markup object can be one of the following:
a string
an empty-markup
an image-markup
struct
(struct empty-markup ())
struct
(struct horizontal-markup (markups))
markups : (listof markup?)
struct
(struct vertical-markup (markups))
markups : (listof markup?)
struct
(struct srcloc-markup (srcloc markup))
srcloc : srcloc? markup : markup?
struct
(struct framed-markup (markup))
markup : markup?
struct
(struct image-markup (data alt-markup))
data : any/c alt-markup : markup?
If rendering of data is not possible, alt-markup can be substituted.
struct
(struct record-dc-datum (datum width height) #:extra-constructor-name make-record-dc-datum) datum : any/c width : natural-number/c height : natural-number/c
struct
(struct number-markup ( number exact-prefix inexact-prefix fraction-view)) number : number? exact-prefix : (or/c 'always 'never 'when-necessary) inexact-prefix : (or/c 'always 'never 'when-necessary) fraction-view : (or/c 'mixed 'improper 'decimal #f)
The exact-prefix argument specifies whether the representation should carry a #e prefix: Always, never, or when necessary to identify a representation that would otherwise be considered inexact.
Similarly for inexact-prefix. Note however that 'when-necessary is usually equivalent to 'never, as inexact numbers are always printed with a decimal dot, which is sufficient to identify a number representation as inexact.
The fraction-view field specifies how exact non-integer reals - fractions - should be rendered: As a mixed fraction, an improper fraction, or a decimal, possibly identifying periodic digits. For 'decimal, if it’s not possible to render the number as a decimal exactly, a fraction representation might be generated. For 'mixed an improper fraction representation might be generated if a mixed representation could not be read back.
If fraction-view is #f, this option comes from some unspecified user preference.
2 Markup Construction
(require simple-tree-text-markup/construct) | |
package: simple-tree-text-markup-lib |
While the struct definitions in simple-tree-text-markup/data can also be used for constructing markup, the procedures exported here are somewhat more convenient to use, and do a fair amount of normalization upon constructions.
procedure
(srcloc-markup srcloc markup) → markup?
srcloc : srcloc? markup : markup?
procedure
(framed-markup markup) → markup?
markup : markup?
value
value
procedure
(number number [ #:exact-prefix exact-prefix #:inexact-prefix inexact-prefix #:fraction-view fraction-view]) → markup? number : number? exact-prefix : (or/c 'always 'never 'when-necessary) = 'never
inexact-prefix : (or/c 'always 'never 'when-necessary) = 'never fraction-view : (or/c #f 'mixed 'improper 'decimal) = #f
The exact-prefix argument specifies whether the representation should carry a #e prefix: Always, never, or when necessary to identify a representation that would otherwise be considered inexact.
Similarly for inexact-prefix. Note however that 'when-necessary is usually equivalent to 'never, as inexact numbers are always printed with a decimal dot, which is sufficient to identify a number representation as inexact.
The fraction-view field specifies how exact non-integer reals - fractions - should be rendered: As a mixed fraction, an improper fraction, or a decimal, possibly identifying periodic digits. For 'decimal, if it’s not possible to render the number as a decimal exactly, a fraction representation might be generated. For 'mixed an improper fraction representation might be generated if a mixed representation could not be read back.
If fraction-view is #f, this option comes from some unspecified user preference.
procedure
(horizontal markup ...) → markup?
markup : markup?
procedure
(markup-transform-image-data transform-image-data markup) → markup? transform-image-data : (any/c . -> . any/c) markup : markup?
3 Rendering Markup to Text
(require simple-tree-text-markup/text) | |
package: simple-tree-text-markup-lib |
This module renders markup to text by printing to a port.
procedure
(display-markup markup [output-port]) → any
markup : markup? output-port : output-port? = (current-output-port)
procedure
(number-markup->string number [ #:exact-prefix exact-prefix #:inexact-prefix inexact-prefix #:fraction-view fraction-view]) → string? number : number? exact-prefix : (or/c 'always 'never 'when-necessary) = 'never
inexact-prefix : (or/c 'always 'never 'when-necessary) = 'never fraction-view : (or/c #f 'mixed 'improper 'decimal) = #f
4 Generating Markup From a Port
(require simple-tree-text-markup/port) | |
package: simple-tree-text-markup-lib |
This modules define procedures for creating output ports whose output is captured as a markup object.
procedure
(make-markup-output-port special->markup)
→
output-port? (-> markup?) special->markup : (any/c . -> . markup?)
The thunk will return whatever has been output to the port as a markup object.
The port also supports write-special: Any object output through it will be converted into markup by the special->markup procedure.
procedure
(make-markup-output-port/unsafe special->markup)
→
output-port? (-> markup?) special->markup : (any/c . -> . markup?)