Liking cljdoc? Tell your friends :D

Preset Layout Catalog

Built-in layouts live in clj-string-layout.presets and are also re-exported from clj-string-layout.layout for backwards compatibility. Presets are plain layout config maps, so they can be passed directly to layout, layout-str, or layout-seq, or assoc'd with options such as :width, :display-width, :col-widths, or :raw?.

For the higher-level named-format API, see the table API guide and the examples gallery.

(require '[clj-string-layout.core :refer [layout]]
         '[clj-string-layout.presets :as presets])

Plain Column Layouts

VarAlignmentBehavior
layout-plain-leftLeftTwo spaces between columns, no borders.
layout-plain-centerCenterTwo spaces between columns, no borders.
layout-plain-rightRightTwo spaces between columns, no borders.

Separated-Value Layouts

VarSeparatorBehavior
layout-tsvTabVerbatim tab-separated cells. Escape with escape/tsv-cell.
layout-csvCommaVerbatim comma-separated cells. Escape with escape/csv-cell.
layout-pipe-separatedPipeCompact pipe-separated cells without Markdown header rows.

Box-Drawing Layouts

VarAlignmentFill-aware
layout-ascii-box-leftLeftNo
layout-ascii-box-centerCenterNo
layout-ascii-box-rightRightNo
layout-ascii-box-fill-leftLeftYes
layout-ascii-box-fill-centerCenterYes
layout-ascii-box-fill-rightRightYes

Norton Commander-Style Layouts

VarAlignmentFill-aware
layout-norton-commander-leftLeftNo
layout-norton-commander-centerCenterNo
layout-norton-commander-rightRightNo
layout-norton-commander-fill-leftLeftYes
layout-norton-commander-fill-centerCenterYes
layout-norton-commander-fill-rightRightYes

ASCII Grid Layouts

ASCII grid layouts use only +, -, and |.

VarAlignmentFill-aware
layout-ascii-grid-leftLeftNo
layout-ascii-grid-centerCenterNo
layout-ascii-grid-rightRightNo
layout-ascii-grid-fill-leftLeftYes
layout-ascii-grid-fill-centerCenterYes
layout-ascii-grid-fill-rightRightYes

Terminal And Documentation Layouts

VarFormatBehavior
layout-psql-leftPostgreSQL psqlLeft-aligned cells with a separator after the first row.
layout-psql-rightPostgreSQL psqlRight-aligned cells with a separator after the first row.
layout-rst-simplereStructuredTextSimple table with top, header, and bottom rules.
layout-org-leftOrg modeLeft-aligned table with a separator after the first row.
layout-org-rightOrg modeRight-aligned table with a separator after the first row.

Markdown Layouts

VarAlignmentFill-aware
layout-markdown-leftLeftNo
layout-markdown-centerCenterNo
layout-markdown-rightRightNo
layout-markdown-fill-leftLeftYes
layout-markdown-fill-centerCenterYes
layout-markdown-fill-rightRightYes

HTML Layouts

VarBehavior
layout-html-tableEmits <table>, one <tr> per input row, and verbatim <td> contents.
layout-html-table-readableSame shape, but left-aligns cell contents for more readable source output.
(layout "Alice why\na raven" presets/layout-html-table)
;; => ["<table>"
;;     "  <tr><td>Alice</td><td>why</td></tr>"
;;     "  <tr><td>a</td><td>raven</td></tr>"
;;     "</table>"]

Escaping Untrusted Cells

Markup and separated-value presets emit cell contents verbatim. Escape input cells before rendering when the data is not already safe for the target format:

(require '[clj-string-layout.escape :as escape])

(layout (escape/map-cells escape/html [["<Alice>" "tea & cake"]])
        presets/layout-html-table)
;; => ["<table>"
;;     "  <tr><td>&lt;Alice&gt;</td><td>tea &amp; cake</td></tr>"
;;     "</table>"]

(layout (escape/map-cells escape/markdown-cell [["name" "a|b"]])
        presets/layout-markdown-left)
;; => ["| name | a\\|b |"
;;     "|:---- |:----- |"]

Additional helpers include escape/tsv-cell, escape/org-cell, escape/rst-cell, and escape/log-safe.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close