Dextrin.Document.Formatter (Dextrin v0.2.0)

Copy Markdown View Source

A document's syntax tree laid out the way Dextrin.Text.Formatter lays out a value -- every non-empty collection over lines, one entry per line, indented -- with every comment kept beside the entry it belongs to (design/comment-retention.md, "The rules").

Layout only. Every token is written exactly as it was -- a literal's spelling, a key's form, an escape -- and only the space between tokens changes: indentation, line breaks, commas, and blank lines, of which at most one is kept wherever the source had any between entries. A document with no comments therefore comes out as the pretty printer writes its value.

Where a comment goes, by lines alone: a comment on the line of the token or entry before it trails that, and so does every comment line straight after it, aligned under its #; any other block of comment lines goes above the next entry, or at the end of its collection when none follows. A comment between a key or a tag and its value stays between them, and the value moves to the next line.

Summary

Functions

The text of the document tree, laid out. :indent is the spaces per level (2).

Functions

format(node, opts \\ [])

@spec format(Ichor.Syntax.Node.t(), keyword()) :: String.t()

The text of the document tree, laid out. :indent is the spaces per level (2).