* Writing a filter to add current date to document's metadata
@ 2015-03-16 1:16 Jason White
[not found] ` <20150316011604.GB21279-4VuKTzg51y8@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Jason White @ 2015-03-16 1:16 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
I'm interested in writing a filter to add the current date to the document's
metadata before writing the output. I suspect it can be accomplished in
several well constructed lines of Haskell, but I'm having difficulty working
out what to specify as the pattern matching expression in writing a JSON
filter.
Any hints? I'm still very much a Haskell beginner.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Writing a filter to add current date to document's metadata
[not found] ` <20150316011604.GB21279-4VuKTzg51y8@public.gmane.org>
@ 2015-03-16 15:47 ` John MacFarlane
[not found] ` <20150316154722.GA44818-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2015-03-16 15:47 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Try something like this:
import Text.Pandoc.JSON
import Text.Pandoc.Builder (setMeta, text)
main = toJSONFilter addDate
addDate :: Pandoc -> IO Pandoc
addDate doc = do
today <- return "TODAYS DATE" -- something from time
return $ setMeta "date" (text today) doc
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Writing a filter to add current date to document's metadata
[not found] ` <20150316154722.GA44818-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
@ 2015-03-17 1:54 ` Jason White
2015-03-22 14:35 ` Jason White
1 sibling, 0 replies; 5+ messages in thread
From: Jason White @ 2015-03-17 1:54 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
> Try something like this:
[...]
Thank you. This is much appreciated.
As an aside, someone should conduct a survey of philosophers' programming
language preferences. It would be interesting to know whether there's a
stronger than average inclination toward logic and functional programming.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Writing a filter to add current date to document's metadata
[not found] ` <20150316154722.GA44818-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
2015-03-17 1:54 ` Jason White
@ 2015-03-22 14:35 ` Jason White
[not found] ` <20150322143513.GA8374-4VuKTzg51y8@public.gmane.org>
1 sibling, 1 reply; 5+ messages in thread
From: Jason White @ 2015-03-22 14:35 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
> Try something like this:
>
> import Text.Pandoc.JSON
> import Text.Pandoc.Builder (setMeta, text)
>
> main = toJSONFilter addDate
>
> addDate :: Pandoc -> IO Pandoc
> addDate doc = do
> today <- return "TODAYS DATE" -- something from time
> return $ setMeta "date" (text today) doc
I completed your above outline as follows. May I distribute this as part of a
project, under liberal licensing terms?
Anyone else is free to use, modify or redistribute this for any purpose so
far as I'm concerned.
#!/usr/bin/env runhaskell
-- Insert today's date into a document's metadata.
-- Portions copyright (C) 2015 by John MacFarlane.
import Text.Pandoc.JSON (Pandoc, toJSONFilter)
import Text.Pandoc.Builder (setMeta, text)
import Data.Time.LocalTime (getZonedTime)
import Data.Time.Format (formatTime)
import System.Locale (defaultTimeLocale)
main = toJSONFilter addDate where
addDate :: Pandoc -> IO Pandoc
addDate doc = do
localTime <- getZonedTime
let today = formatTime defaultTimeLocale "%-d %B %Y" localTime in
return $ setMeta "date" (text today) doc
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Writing a filter to add current date to document's metadata
[not found] ` <20150322143513.GA8374-4VuKTzg51y8@public.gmane.org>
@ 2015-03-27 4:22 ` John MacFarlane
0 siblings, 0 replies; 5+ messages in thread
From: John MacFarlane @ 2015-03-27 4:22 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
+++ Jason White [Mar 22 15 10:35 ]:
>John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>> Try something like this:
>>
>> import Text.Pandoc.JSON
>> import Text.Pandoc.Builder (setMeta, text)
>>
>> main = toJSONFilter addDate
>>
>> addDate :: Pandoc -> IO Pandoc
>> addDate doc = do
>> today <- return "TODAYS DATE" -- something from time
>> return $ setMeta "date" (text today) doc
>
>I completed your above outline as follows. May I distribute this as part of a
>project, under liberal licensing terms?
Sure.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-27 4:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 1:16 Writing a filter to add current date to document's metadata Jason White
[not found] ` <20150316011604.GB21279-4VuKTzg51y8@public.gmane.org>
2015-03-16 15:47 ` John MacFarlane
[not found] ` <20150316154722.GA44818-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
2015-03-17 1:54 ` Jason White
2015-03-22 14:35 ` Jason White
[not found] ` <20150322143513.GA8374-4VuKTzg51y8@public.gmane.org>
2015-03-27 4:22 ` John MacFarlane
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).