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 prefix? fraction-view))
number : number? prefix? : boolean? fraction-view : (or/c 'mixed 'improper 'decimal)
The fraction-view field specifies how exact non-integer reals should be rendered: As a mixed fraction, an improper fraction, or a decimal, possibly identifying periodic digits.
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
(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)
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?)