hledger-lib
Safe HaskellNone
LanguageGHC2021

Hledger.Write.Journal

Description

Rendering a journal's items back to journal format, reproducing the original journal file(s). Used by print --export.

Synopsis

Documentation

data ItemRenderer Source #

How to render each kind of journal item in some output format.

Constructors

ItemRenderer 

Fields

  • irTransaction :: Transaction -> Text

    render a transaction, without a trailing blank line

  • irDirective :: Text -> Maybe Text

    render a directive given as source text, or drop it (Nothing)

  • irComment :: Text -> Text

    render a top-level comment line

  • irCommentBlock :: Text -> Text

    render a comment ... end comment block

journalItemRenderer :: (Transaction -> Text) -> ItemRenderer Source #

An item renderer for hledger's journal format, reproducing directives and comments as written, and rendering transactions with the given showTransaction-like function (whose trailing blank line is removed).

journalItemsAsText :: ItemRenderer -> [JournalItem] -> [Transaction] -> Text Source #

Render journal items as journal text, reproducing the journal file(s) they were parsed from, with transactions rendered from the given (possibly filtered and processed) transactions.

Directive, comment line and comment block items are rendered as the item renderer specifies (verbatim, for hledger's journal format). Non-exported directives are dropped. Include lines are dropped too, and the included file's items follow inline, beginning a new block (so eg there is a blank line between the entries of adjacent included files). Each transaction placeholder is replaced by the rendering of the next given transaction with that source position, or by nothing if there is none (eg it was filtered out). Any transactions not matching a placeholder (eg from non-journal files) are added at the end, in source position order.

Blank lines are normalised: each transaction, and each group of adjacent directive/comment items (as delimited by blank lines in the source), is a block, and blocks are separated by exactly one blank line. A final transaction is also followed by a blank line, as in ordinary print output.