metadata parse and show for transaction
This commit is contained in:
parent
c010448935
commit
ce83876700
@ -93,7 +93,7 @@ showTransactionUnelided = showTransaction' False
|
||||
|
||||
showTransaction' :: Bool -> Transaction -> String
|
||||
showTransaction' elide t =
|
||||
unlines $ [description] ++ showpostings (tpostings t) ++ [""]
|
||||
unlines $ [description] ++ metadata ++ showpostings (tpostings t) ++ [""]
|
||||
where
|
||||
description = concat [date, status, code, desc, comment]
|
||||
date = showdate (tdate t) ++ maybe "" showedate (teffectivedate t)
|
||||
@ -103,6 +103,8 @@ showTransaction' elide t =
|
||||
code = if length (tcode t) > 0 then printf " (%s)" $ tcode t else ""
|
||||
desc = if null d then "" else " " ++ d where d = tdescription t
|
||||
comment = if null c then "" else " ; " ++ c where c = tcomment t
|
||||
metadata = if null md then [] else showmetadata md where md = tmetadata t
|
||||
showmetadata md = map (\(k,v) -> " ; " ++ k++":"++v) md
|
||||
showpostings ps
|
||||
| elide && length ps > 1 && isTransactionBalanced Nothing t -- imprecise balanced check
|
||||
= map showposting (init ps) ++ [showpostingnoamt (last ps)]
|
||||
|
||||
@ -415,7 +415,7 @@ ledgercode :: GenParser Char JournalContext String
|
||||
ledgercode = try (do { many1 spacenonewline; char '(' <?> "code"; code <- anyChar `manyTill` char ')'; return code } ) <|> return ""
|
||||
|
||||
ledgermetadata :: GenParser Char JournalContext [(String,String)]
|
||||
ledgermetadata = many ledgermetadataline
|
||||
ledgermetadata = many $ try ledgermetadataline
|
||||
|
||||
-- a comment line containing a metadata declaration, eg:
|
||||
-- ; name: value
|
||||
|
||||
@ -13,6 +13,8 @@ bin/hledger -f - print
|
||||
; non-metadata:
|
||||
>>>
|
||||
2010/01/01
|
||||
; txndata1:txn val 1
|
||||
; txndata2:txn val 2
|
||||
a 1
|
||||
b -1
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user