Skip to content

the-sett/elm-pretty-printer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contacts for Support

Status

  • 13-Dec-2025 - Published as version 3.3.0

    Added new "flatAlt" feature. This allows you to define different doc layouts for flat and broken scenarios. When placed inside a group, these respect the decision of the group itself, allowing more precise control of layouts. This is needed to replicate how elm-format works.

  • 13-Dec-2025 - Published as version 3.2.0

    Added new "ribbon width" feature and prettyWithRibbon functions. This allows you to keep code compact and more uniform looking, whether near the start of the line or the end.

  • 13-Dec-2025 - Published as version 3.1.3

    3.1.0 Added Pretty.Renderer and tagging for syntax highlighing.

    3.1.x Fixed a few small bugs particularly softline blowing up the stack.

    3.1.3 Added lots of tests and improved the documentation with examples.

  • 06-Oct-2020 - Published as version 3.0.0

A type parameter has been added to Doc allowing Strings in the document to be tagged. Tagged strings can then be rendered with the new Pretty.Renderer module, for syntax highlighting.

The new Pretty.Renderer module, also makes it possible to generate non-String output formats, for example HTML.

elm-pretty-printer

A pretty printing library based on 'A Prettier Printer' by Philip Wadler.

The theory of this code is described in the THEORY.md file, which also describes the features that extends Wadlers work.

This version follows Wadler's paper closely, but is actually ported from a Haskell implementation that is referred to as Wadler/Leijen. Leijen added Column and Nesting constructors in the document type, which make for easier and more flexible indentation.

I have added the ability to have different ways of joining documents when placing them on the same line, or breaking them into multiple lines. When placed within a group , the usual line function will render as a line break or a space; the tightline will render as a line break or "". The separators function allows a string to be given that is placed between docs on the same line, or after the start of the line when placing on multiple lines - useful when rendering commas in a list at the start of the line.

This implementation is usually sufficiently lazy and tail-recursive to perform well under Elm. Occassionally an exponential blow-up can happen if the softline function is not used carefully. Plase raise a GitHub issue on this if it is not performing well enough for you.

Syntax Highlighting and rendering to HTML

The Pretty.Renderer module allows for finer control over how the output is produced.

This requires a Renderer specification to be set up that provides call-back functions that will be used when tagged strings in the document are encountered, and also at line ends.

This is left folded over the output using whatever accumulator type you need in order to transform the output.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7

Languages