PrettyDoc.jl

An easy-to-use and lightweight text layout combinator library, serving high-quality pretty printing, text code generation, etc.
Author thautwarm
Popularity
6 Stars
Updated Last
1 Year Ago
Started In
July 2022

PrettyDoc

API Build Status Coverage

The idea is to combine a Document out of many small components, then using a layouter to convert it to an easily renderable SimpleDocStream

This is an easy-to-use and lightweight text layout combinator library.

import PrettyDoc as PD
const squote = "\""
struct Block
    name::String
    contents::Union{String, Vector{Block}}
end

function render_block(self::Block)
    if self.contents isa Vector
        return PD.vsep(
            PD.seg(self.name) + PD.seg("{"),
            PD.vsep(map(render_block, self.contents)) >> 4,
            PD.seg("}")
        )
    end
    return PD.seg(self.name) + PD.seg(squote * escape_string(self.contents) * squote)
end

block = Block(
    "A",
    [
        Block("C", "ccc"),
        Block("B",
            [
                Block("C", "ccc"),
            ]
        ),
        Block("C", "ccc"),
        Block("C", "ccc"),
    ]
)

string(render_block(block))

=>

A {
    C "ccc"
    B {
        C "ccc"
    }
    C "ccc"
    C "ccc"
}

See the API documentation for the available combinator functions.

Required Packages

Used By Packages

No packages found.