From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/4937 Path: news.gmane.org!not-for-mail From: Qubyte Newsgroups: gmane.text.pandoc Subject: Making a simple script to send coloured output to a terminal. Date: Sun, 21 Oct 2012 02:15:43 -0700 (PDT) Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2175_14339539.1350810943240" X-Trace: ger.gmane.org 1350810944 31498 80.91.229.3 (21 Oct 2012 09:15:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Oct 2012 09:15:44 +0000 (UTC) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDUL7FOJRUARBP72R2CAKGQE3YFXYZA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun Oct 21 11:15:52 2012 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-qc0-f186.google.com ([209.85.216.186]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TPrdQ-0000to-2y for gtp-pandoc-discuss@m.gmane.org; Sun, 21 Oct 2012 11:15:52 +0200 Original-Received: by mail-qc0-f186.google.com with SMTP id y9sf1702429qcp.3 for ; Sun, 21 Oct 2012 02:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=xV+TQYHk6KM/FxGvojOP+PgUmF2G3kTCzwFMyYRu1Rg=; b=FaBm5GiFKGwpVF1uaov2N0CoBP41hYQZb0Jb+RLMzgzRwEYtAul2HSN08CkECfXl6x RjjIEKClQalYz10zOIOBSJFuQXUQpE1bFFk75nXtPohPx3J05fTWpUVl1wVy21NXRUnY T75yyNYMo3vWBdEKPsL68QwjD67/OXm3R+TteBEkO403Xgnm8Ds/JPXDiJBhJC7KFfoz U/V1kLmwyskiTd1EvodJPYSmD0TXi8BwuNDQ3NDo4FbBJzl6gAOQTfzxQp8fPhBNqDoS GqT7cAlo92yWZQYRCVgBWFyorx4Fb9pIYqt4CF3OPwd101+VbC+CFMWwP0ovnTBD5DgM 3L9Q== Original-Received: by 10.68.212.72 with SMTP id ni8mr1765795pbc.14.1350810944170; Sun, 21 Oct 2012 02:15:44 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.68.141.79 with SMTP id rm15ls10453903pbb.1.gmail; Sun, 21 Oct 2012 02:15:43 -0700 (PDT) Original-Received: by 10.68.130.231 with SMTP id oh7mr1793826pbb.5.1350810943642; Sun, 21 Oct 2012 02:15:43 -0700 (PDT) X-Original-Sender: mark.s.everitt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Subscribe: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:4937 Archived-At: ------=_Part_2175_14339539.1350810943240 Content-Type: text/plain; charset=ISO-8859-1 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. ------=_Part_2175_14339539.1350810943240 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi all,

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

impo= rt Text.Pandoc

<= /font>
colour :: Block ->= ; Block
colour (Head= er n xs) =3D Para $ map modHeader xs
--colour (BulletList xs) =3D BulletList $ map modBullet xs=
colour x =3D x

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

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

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

main :: IO ()

W= hich just makes all headers green (I'll add in cases for different depths l= ater). 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 bulle= ts (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 <= /font>toTerminal and run files through pandoc like:

pandoc -t json something.markdown | ./toTerminal | pand= oc -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 o= ut. :)

Thanks,

Mark

--
You received this message because you are subscribed to the Google Groups &= quot;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@go= oglegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/pan= doc-discuss/-/7NiJS5t6WnAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
------=_Part_2175_14339539.1350810943240--