public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Making a simple script to send coloured output to a terminal.
@ 2012-10-21  9:15 Qubyte
       [not found] ` <c64868b9-ee1b-4b9d-bc30-dbe430d5d432-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Qubyte @ 2012-10-21  9:15 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]

Hi all,

Someone recently asked me if it was possible to pretty print markdown in a 
terminal, for example to preview git commit messages and such. I'm playing 
around with the idea as basically stripping some formatting (I don't need # 
or === but I want to keep bullets or numbers for lists) and injecting in 
colours, bold, underlines etc. So far I have:

import Text.Pandoc

colour :: Block -> Block
colour (Header n xs) = Para $ map modHeader xs
--colour (BulletList xs) = BulletList $ map modBullet xs
colour x = x

modHeader :: Inline -> Inline
modHeader (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m"
modHeader x = x

--modBullets :: Block -> Block
--modBullets (Plain xs) = Plain $ map modBullet xs

--modBullet :: Inline -> Inline
--modBullet (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m"

main :: IO ()
main = toJsonFilter $ colour

Which just makes all headers green (I'll add in cases for different depths 
later). I'm having trouble with bullet lists though. I'd like to mutate 
them either into a single paragraph with injected newlines and dashes for 
bullets (and characters for colour encoding) or modify the content of each 
point with inline colour encoding. To execute what I have so far, I compile 
as toTerminal and run files through pandoc like:

pandoc -t json something.markdown | ./toTerminal | pandoc -f json -t plain

And hints or tips would be very much appreciated! If I can get the bullet 
lists working, I'm pretty sure I can figure the rest out. :)

Thanks,

Mark

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msg/pandoc-discuss/-/7NiJS5t6WnAJ.
For more options, visit https://groups.google.com/groups/opt_out.



[-- Attachment #2: Type: text/html, Size: 3692 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Making a simple script to send coloured output to a terminal.
       [not found] ` <c64868b9-ee1b-4b9d-bc30-dbe430d5d432-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2012-10-21 15:18   ` John MacFarlane
       [not found]     ` <20121021151831.GB30752-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: John MacFarlane @ 2012-10-21 15:18 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

You won't be able to change the color of the bullets with
this method.  Given what you want to do, your best bet might
be to add a new writer (a variant of the markdown writer)
or perhaps add a "writerAnsiColors" option to WriterOptions
and use it in the markdown writer.

+++ Qubyte [Oct 21 12 02:15 ]:
>    Hi all,
> 
>    Someone recently asked me if it was possible to pretty print markdown
>    in a terminal, for example to preview git commit messages and such. I'm
>    playing around with the idea as basically stripping some formatting (I
>    don't need # or === but I want to keep bullets or numbers for lists)
>    and injecting in colours, bold, underlines etc. So far I have:
> 
>    import Text.Pandoc
>    colour :: Block -> Block
>    colour (Header n xs) = Para $ map modHeader xs
>    --colour (BulletList xs) = BulletList $ map modBullet xs
>    colour x = x
>    modHeader :: Inline -> Inline
>    modHeader (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m"
>    modHeader x = x
>    --modBullets :: Block -> Block
>    --modBullets (Plain xs) = Plain $ map modBullet xs
>    --modBullet :: Inline -> Inline
>    --modBullet (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m"
>    main :: IO ()
>    main = toJsonFilter $ colour
> 
>    Which just makes all headers green (I'll add in cases for different
>    depths later). I'm having trouble with bullet lists though. I'd like to
>    mutate them either into a single paragraph with injected newlines and
>    dashes for bullets (and characters for colour encoding) or modify the
>    content of each point with inline colour encoding. To execute what I
>    have so far, I compile as toTerminal and run files through pandoc like:
> 
>    pandoc -t json something.markdown | ./toTerminal | pandoc -f json -t
>    plain
> 
>    And hints or tips would be very much appreciated! If I can get the
>    bullet lists working, I'm pretty sure I can figure the rest out. :)
> 
>    Thanks,
> 
>    Mark
> 
>    --
>    You received this message because you are subscribed to the Google
>    Groups "pandoc-discuss" group.
>    To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>    To unsubscribe from this group, send email to
>    pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>    To view this discussion on the web visit
>    [1]https://groups.google.com/d/msg/pandoc-discuss/-/7NiJS5t6WnAJ.
>    For more options, visit [2]https://groups.google.com/groups/opt_out.
> 
> References
> 
>    1. https://groups.google.com/d/msg/pandoc-discuss/-/7NiJS5t6WnAJ
>    2. https://groups.google.com/groups/opt_out


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Making a simple script to send coloured output to a terminal.
       [not found]     ` <20121021151831.GB30752-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
@ 2012-10-22 14:39       ` Qubyte
  0 siblings, 0 replies; 3+ messages in thread
From: Qubyte @ 2012-10-22 14:39 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3493 bytes --]

Thanks, I'll give that a try and post something here when I have some 
progress.

On Monday, 22 October 2012 00:18:29 UTC+9, fiddlosopher wrote:
>
> You won't be able to change the color of the bullets with 
> this method.  Given what you want to do, your best bet might 
> be to add a new writer (a variant of the markdown writer) 
> or perhaps add a "writerAnsiColors" option to WriterOptions 
> and use it in the markdown writer. 
>
> +++ Qubyte [Oct 21 12 02:15 ]: 
> >    Hi all, 
> > 
> >    Someone recently asked me if it was possible to pretty print markdown 
> >    in a terminal, for example to preview git commit messages and such. 
> I'm 
> >    playing around with the idea as basically stripping some formatting 
> (I 
> >    don't need # or === but I want to keep bullets or numbers for lists) 
> >    and injecting in colours, bold, underlines etc. So far I have: 
> > 
> >    import Text.Pandoc 
> >    colour :: Block -> Block 
> >    colour (Header n xs) = Para $ map modHeader xs 
> >    --colour (BulletList xs) = BulletList $ map modBullet xs 
> >    colour x = x 
> >    modHeader :: Inline -> Inline 
> >    modHeader (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m" 
> >    modHeader x = x 
> >    --modBullets :: Block -> Block 
> >    --modBullets (Plain xs) = Plain $ map modBullet xs 
> >    --modBullet :: Inline -> Inline 
> >    --modBullet (Str xs) = Str $ "\x1b[1m\x1b[32m" ++ xs ++ "\x1b[0m" 
> >    main :: IO () 
> >    main = toJsonFilter $ colour 
> > 
> >    Which just makes all headers green (I'll add in cases for different 
> >    depths later). I'm having trouble with bullet lists though. I'd like 
> to 
> >    mutate them either into a single paragraph with injected newlines and 
> >    dashes for bullets (and characters for colour encoding) or modify the 
> >    content of each point with inline colour encoding. To execute what I 
> >    have so far, I compile as toTerminal and run files through pandoc 
> like: 
> > 
> >    pandoc -t json something.markdown | ./toTerminal | pandoc -f json -t 
> >    plain 
> > 
> >    And hints or tips would be very much appreciated! If I can get the 
> >    bullet lists working, I'm pretty sure I can figure the rest out. :) 
> > 
> >    Thanks, 
> > 
> >    Mark 
> > 
> >    -- 
> >    You received this message because you are subscribed to the Google 
> >    Groups "pandoc-discuss" group. 
> >    To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:>. 
>
> >    To unsubscribe from this group, send email to 
> >    pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> >    To view this discussion on the web visit 
> >    [1]https://groups.google.com/d/msg/pandoc-discuss/-/7NiJS5t6WnAJ. 
> >    For more options, visit [2]https://groups.google.com/groups/opt_out. 
> > 
> > References 
> > 
> >    1. https://groups.google.com/d/msg/pandoc-discuss/-/7NiJS5t6WnAJ 
> >    2. https://groups.google.com/groups/opt_out 
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msg/pandoc-discuss/-/NrNg9r8LZu4J.
For more options, visit https://groups.google.com/groups/opt_out.



[-- Attachment #2: Type: text/html, Size: 4994 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-22 14:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-21  9:15 Making a simple script to send coloured output to a terminal Qubyte
     [not found] ` <c64868b9-ee1b-4b9d-bc30-dbe430d5d432-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2012-10-21 15:18   ` John MacFarlane
     [not found]     ` <20121021151831.GB30752-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
2012-10-22 14:39       ` Qubyte

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).