Liking cljdoc? Tell your friends :D

hara.print.pretty

Enhanced printing functions for rendering Clojure values. The following options are available to control the printer:

General Rendering

:width

Number of characters to try to wrap pretty-printed forms at.

:print-meta

If true, metadata will be printed before values. Defaults to the value of *print-meta* if unset.

Collection Options

:sort-keys

Print maps and sets with ordered keys. Defaults to true, which will sort all collections. If a number, counted collections will be sorted up to the set size. Otherwise, collections are not sorted before printing.

:map-delimiter

The text placed between key-value pairs in a map.

:map-coll-separator

The text placed between a map key and a collection value. The keyword :line will cause line breaks if the whole map does not fit on a single line.

:seq-limit

If set to a positive number, then lists will only render at most the first n elements. This can help prevent unintentional realization of infinite lazy sequences.

Color Options

:print-color

When true, ouptut colored text from print functions.

:color-markup

:ansi for ANSI color text (the default), :html-inline for inline-styled html, :html-classes to use the names of the keys in the :color-scheme map as class names for spans so styling can be specified via CSS.

:color-scheme

Map of syntax element keywords to color codes.

Type Handling

:print-handlers

A lookup function which will return a rendering function for a given class type. This will be tried before the built-in type logic. See the hara.print.pretty.dispatch namespace for some helpful constructors. The returned function should accept the current printer and the value to be rendered, returning a format document.

:print-fallback

Keyword argument specifying how to format unknown values. Puget supports a few different options:

  • :pretty renders values with the default colored representation.
  • :print defers to the standard print method by rendering unknown values using pr-str.
  • :error will throw an exception when types with no defined handler are encountered.
  • A function value will be called with the current printer options and the unknown value and is expected to return a formatting document representing it.
Enhanced printing functions for rendering Clojure values. The following
options are available to control the printer:

#### General Rendering

`:width`

Number of characters to try to wrap pretty-printed forms at.

`:print-meta`

If true, metadata will be printed before values. Defaults to the value of
`*print-meta*` if unset.

#### Collection Options

`:sort-keys`

Print maps and sets with ordered keys. Defaults to true, which will sort all
collections. If a number, counted collections will be sorted up to the set
size. Otherwise, collections are not sorted before printing.

`:map-delimiter`

The text placed between key-value pairs in a map.

`:map-coll-separator`

The text placed between a map key and a collection value. The keyword :line
will cause line breaks if the whole map does not fit on a single line.

`:seq-limit`

If set to a positive number, then lists will only render at most the first n
elements. This can help prevent unintentional realization of infinite lazy
sequences.

#### Color Options

`:print-color`

When true, ouptut colored text from print functions.

`:color-markup`

:ansi for ANSI color text (the default),
:html-inline for inline-styled html,
:html-classes to use the names of the keys in the :color-scheme map
as class names for spans so styling can be specified via CSS.

`:color-scheme`

Map of syntax element keywords to color codes.

#### Type Handling

`:print-handlers`

A lookup function which will return a rendering function for a given class
type. This will be tried before the built-in type logic. See the
`hara.print.pretty.dispatch` namespace for some helpful constructors. The returned
function should accept the current printer and the value to be rendered,
returning a format document.

`:print-fallback`

Keyword argument specifying how to format unknown values. Puget supports a few
different options:

- `:pretty` renders values with the default colored representation.
- `:print` defers to the standard print method by rendering unknown values
  using `pr-str`.
- `:error` will throw an exception when types with no defined handler are
  encountered.
- A function value will be called with the current printer options and the
  unknown value and is expected to return a formatting document representing
  it.
raw docstring

+defaults+clj


canonical-printerclj

(canonical-printer)
(canonical-printer handlers)

constructs a canonical printer

(canonical-printer {}) => hara.print.pretty.CanonicalPrinter

constructs a canonical printer

(canonical-printer {})
=> hara.print.pretty.CanonicalPrinter
raw docstring

clojure-handlersclj

Map of print handlers for 'primary' Clojure types. These should take precedence over the handlers in clojure-interface-handlers.

Map of print handlers for 'primary' Clojure types. These should take
precedence over the handlers in `clojure-interface-handlers`.
raw docstring

clojure-interface-handlersclj

Fallback print handlers for other Clojure interfaces.

Fallback print handlers for other Clojure interfaces.
raw docstring

common-handlersclj

Print handler dispatch combining Java and Clojure handlers with inheritance lookups. Provides a similar experience as the standard Clojure pretty-printer.

Print handler dispatch combining Java and Clojure handlers with inheritance
lookups. Provides a similar experience as the standard Clojure
pretty-printer.
raw docstring

format-docclj

(format-doc printer value)

provides a format given a printer and value

(format-doc (canonical-printer) :hello) => ":hello"

(format-doc (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]

provides a format given a printer and value

(format-doc (canonical-printer) :hello)
=> ":hello"

(format-doc (pretty-printer {}) :hello)
=> [:span [:pass ""] ":hello" [:pass ""]]
raw docstring

format-doc-ednclj

(format-doc-edn printer value)

provides a meta-less print formatter

(format-doc-edn (pretty-printer {}) :hello) => [:span [:pass "[34m"] ":hello" [:pass "[0m"]]

provides a meta-less print formatter

(format-doc-edn (pretty-printer {}) :hello)
=> [:span [:pass ""] ":hello" [:pass ""]]
raw docstring

format-unknownclj

(format-unknown printer value)
(format-unknown printer value repr)
(format-unknown printer value tag repr)

custom printer for an unknown type

(format-unknown (canonical-printer) :hello) => (contains-in [:span "#<" "clojure.lang.Keyword" "@" string? '(" " ":hello") ">"])

custom printer for an unknown type

(format-unknown (canonical-printer) :hello)
=> (contains-in [:span "#<" "clojure.lang.Keyword" "@" string? '(" " ":hello") ">"])
raw docstring

java-handlersclj

Map of print handlers for Java types. This supports syntax for regular expressions, dates, UUIDs, and futures.

Map of print handlers for Java types. This supports syntax for regular
expressions, dates, UUIDs, and futures.
raw docstring

pprintclj

(pprint value)
(pprint value opts)

pretty prints with options

(pprint {:a 1 :b 2 :c (range 5)} {:width 10})

pretty prints with options

(pprint {:a 1 :b 2 :c (range 5)}
        {:width 10})
raw docstring

pprint-strclj

(pprint-str value)
(pprint-str value opts)

returns the string that is printed

(pprint-str {:a 1 :b 2 :c (range 5)} {:width 10})

returns the string that is printed

(pprint-str {:a 1 :b 2 :c (range 5)}
            {:width 10})
raw docstring

pr-handlerclj

(pr-handler printer value)

creates a print handler for printing strings

(pr-handler (canonical-printer) [1 2 3 4]) => "[1 2 3 4]"

creates a print handler for printing strings

(pr-handler (canonical-printer) [1 2 3 4])
=> "[1 2 3 4]"
raw docstring

pretty-printerclj

(pretty-printer opts)

constructs a pretty printer

(pretty-printer {}) => hara.print.pretty.PrettyPrinter

constructs a pretty printer

(pretty-printer {})
=> hara.print.pretty.PrettyPrinter
raw docstring

render-outclj

(render-out printer value)

helper to pprint and pprint-str

(with-out-str (render-out (canonical-printer) {:a 1 :b 2 :c (range 5)})) => "{:a 1 :b 2 :c (0 1 2 3 4)}"

helper to pprint and pprint-str

(with-out-str
  (render-out (canonical-printer)
              {:a 1 :b 2 :c (range 5)}))
=> "{:a 1 :b 2 :c (0 1 2 3 4)}"
raw docstring

tagged-handlerclj

(tagged-handler tag value-fn)

creates a custom handler for a tagged literal

((tagged-handler 'object (fn [x] (map inc x))) (canonical-printer {}) [1 2 3 4]) => [:span "#object" " " [:group "(" [:align '("2" " " "3" " " "4" " " "5")] ")"]]

creates a custom handler for a tagged literal

((tagged-handler 'object (fn [x] (map inc x)))
 (canonical-printer {})
 [1 2 3 4])
=> [:span "#object" " " [:group "(" [:align '("2" " " "3" " " "4" " " "5")] ")"]]
raw docstring

unknown-handlerclj

(unknown-handler printer value)

creates a custom handler for an unknown object

(unknown-handler (canonical-printer) (Thread/currentThread)) => throws

creates a custom handler for an unknown object

(unknown-handler (canonical-printer) (Thread/currentThread))
=> throws
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close